Switch config to .env

This commit is contained in:
poma 2019-07-18 17:05:09 +03:00
parent f7bca08480
commit 28ba4bad50
9 changed files with 28 additions and 18 deletions

6
.env.example Normal file

@ -0,0 +1,6 @@
NET_ID=42
RPC_URL=https://kovan.infura.io/v3/a3f4d001c1fc4a359ea70dd27fd9cb51
PRIVATE_KEY=
MIXER_ADDRESS=0x30AF2e92263C5387A8A689322BbfE60b6B0855C4
DEFAULT_GAS_PRICE=1
GAS_ORACLE_URLS=https://www.etherchain.org/api/gasPriceOracle https://gasprice.poa.network/

3
.gitignore vendored

@ -1,4 +1,3 @@
.vscode .vscode
node_modules/ node_modules/
env.json .env

@ -1,11 +1,11 @@
# Relayer for Tornado mixer # Relayer for Tornado mixer
## Setup ## Setup
1. `npm i` 1. `npm i`
2. `cp env.json.example env.json` 2. `cp .env.example .env`
3. Modify `env.json` as needed 3. Modify `.env` as needed
## Run ## Run
1. `node index.js` 1. `npm run start`
2. `curl -X POST -H 'content-type:application/json' --data '<PROOF>' http://127.0.0.1:8000/relay` 2. `curl -X POST -H 'content-type:application/json' --data '<PROOF>' http://127.0.0.1:8000/relay`
Relayer should return a transaction hash. Relayer should return a transaction hash.

10
config.js Normal file

@ -0,0 +1,10 @@
require('dotenv').config()
module.exports = {
netId: process.env.NET_ID || 42,
rpcUrl: process.env.RPC_URL || 'https://kovan.infura.io/v3/a3f4d001c1fc4a359ea70dd27fd9cb51',
privateKey: process.env.PRIVATE_KEY,
mixerAddress: process.env.MIXER_ADDRESS || '0x30AF2e92263C5387A8A689322BbfE60b6B0855C4',
defaultGasPrice: process.env.DEFAULT_GAS_PRICE || 1,
gasOracleUrls: process.env.GAS_ORACLE_URLS ? process.env.GAS_ORACLE_URLS.split(' ') : ['https://www.etherchain.org/api/gasPriceOracle', 'https://gasprice.poa.network/']
}

@ -1,11 +0,0 @@
{
"netId": 42,
"rpcUrl": "https://kovan.infura.io/v3/a3f4d001c1fc4a359ea70dd27fd9cb51",
"privateKey": "",
"mixerAddress": "0x30AF2e92263C5387A8A689322BbfE60b6B0855C4",
"defaultGasPrice": 1,
"gasOracleUrls": [
"https://www.etherchain.org/api/gasPriceOracle",
"https://gasprice.poa.network/"
]
}

@ -5,7 +5,7 @@ const express = require('express')
const app = express() const app = express()
app.use(express.json()) app.use(express.json())
const { netId, rpcUrl, privateKey, mixerAddress, defaultGasPrice } = require('./env.json') const { netId, rpcUrl, privateKey, mixerAddress, defaultGasPrice } = require('./config')
const Web3 = require('web3') const Web3 = require('web3')
const web3 = new Web3(rpcUrl, null, { transactionConfirmationBlocks: 1 }) const web3 = new Web3(rpcUrl, null, { transactionConfirmationBlocks: 1 })

5
package-lock.json generated

@ -960,6 +960,11 @@
"resolved": "https://registry.npmjs.org/dom-walk/-/dom-walk-0.1.1.tgz", "resolved": "https://registry.npmjs.org/dom-walk/-/dom-walk-0.1.1.tgz",
"integrity": "sha1-ZyIm3HTI95mtNTB9+TaroRrNYBg=" "integrity": "sha1-ZyIm3HTI95mtNTB9+TaroRrNYBg="
}, },
"dotenv": {
"version": "8.0.0",
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-8.0.0.tgz",
"integrity": "sha512-30xVGqjLjiUOArT4+M5q9sYdvuR4riM6yK9wMcas9Vbp6zZa+ocC9dp6QoftuhTPhFAiLK/0C5Ni2nou/Bk8lg=="
},
"drbg.js": { "drbg.js": {
"version": "1.0.1", "version": "1.0.1",
"resolved": "https://registry.npmjs.org/drbg.js/-/drbg.js-1.0.1.tgz", "resolved": "https://registry.npmjs.org/drbg.js/-/drbg.js-1.0.1.tgz",

@ -11,6 +11,7 @@
"author": "Alexey Pertsev <alexey@peppersec.com> (https://peppersec.com)", "author": "Alexey Pertsev <alexey@peppersec.com> (https://peppersec.com)",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"dotenv": "^8.0.0",
"express": "^4.17.1", "express": "^4.17.1",
"node-fetch": "^2.6.0", "node-fetch": "^2.6.0",
"web3": "^1.0.0-beta.55", "web3": "^1.0.0-beta.55",

@ -1,6 +1,6 @@
const fetch = require('node-fetch') const fetch = require('node-fetch')
const { isHexStrict } = require('web3-utils') const { isHexStrict } = require('web3-utils')
const { gasOracleUrls } = require('./env.json') const { gasOracleUrls } = require('./config')
async function fetchGasPrice({ gasPrices, oracleIndex = 0 }) { async function fetchGasPrice({ gasPrices, oracleIndex = 0 }) {
oracleIndex = (oracleIndex + 1) % gasOracleUrls.length oracleIndex = (oracleIndex + 1) % gasOracleUrls.length