gas oracle fix; entry point update; docker-compose removing

This commit is contained in:
Alexey 2019-12-05 15:51:01 +03:00
parent 46e3a1bcce
commit b833ed8a5e
8 changed files with 28 additions and 57 deletions

View File

@ -1,22 +1,23 @@
# Relayer for Tornado mixer [![Build Status](https://travis-ci.org/tornadocash/relayer.svg?branch=master)](https://travis-ci.org/tornadocash/relayer) [![Docker Cloud Build Status](https://img.shields.io/docker/cloud/build/tornadocash/relayer.svg)](https://hub.docker.com/r/tornadocash/relayer/builds)
## Setup
## Run locally
1. `npm i`
2. `cp .env.example .env`
3. Modify `.env` as needed
4. If you want to change contracts' addresses go to [config.js](./config.js) file.
## Deploy Kovan
1. `cp .env.example deploy/kovan/.env`
2. `cd deploy/kovan`
2. Modify `.env` as needed
3. `docker-compose -p kovan up -d`
## Run locally
1. `npm run start`
2. `curl -X POST -H 'content-type:application/json' --data '<input data>' http://127.0.0.1:8000/relay`
4. `npm run start`
5. Go to `http://127.0.0.1:8000`
6. In order to execute withdraw request, you can run following command
```bash
curl -X POST -H 'content-type:application/json' --data '<input data>' http://127.0.0.1:8000/relay
```
Relayer should return a transaction hash.
*Note.* If you want to change contracts' addresses go to [config.js](./config.js) file.
## Deploy as a Docker container
1. `cp .env.example .env`
2. Modify `.env` as needed
3. `docker run -d --env-file .env -p 80:8000 tornadocash/relayer:v2`
## Input data example
```json

1
app.js Normal file
View File

@ -0,0 +1 @@
module.exports = require('./src/index')

View File

@ -50,7 +50,7 @@ module.exports = {
}
},
defaultGasPrice: 2,
gasOracleUrls: ['https://www.etherchain.org/api/gasPriceOracle', 'https://gasprice.poa.network/'],
gasOracleUrls: ['https://ethgasstation.info/json/ethgasAPI.json', 'https://gasprice.poa.network/'],
port: process.env.APP_PORT,
relayerServiceFee: Number(process.env.RELAYER_FEE)
}

View File

@ -1,18 +0,0 @@
version: '2.2'
services:
relayer:
build: ../../
restart: always
environment:
NODE_ENV: production
VIRTUAL_HOST: kovan.tornado.cash
LETSENCRYPT_HOST: kovan.tornado.cash
env_file: ./.env
healthcheck:
test: curl -sS http://127.0.0.1:8000 || exit 1
networks:
default:
external:
name: frontend_default

View File

@ -1,18 +0,0 @@
version: '2.2'
services:
relayer:
build: ../../
restart: always
environment:
NODE_ENV: production
VIRTUAL_HOST: mainnet.tornado.cash
LETSENCRYPT_HOST: mainnet.tornado.cash
env_file: ./.env
healthcheck:
test: curl -sS http://127.0.0.1:8000 || exit 1
networks:
default:
external:
name: frontend_default

View File

@ -2,9 +2,9 @@
"name": "relay",
"version": "1.0.0",
"description": "Relayer for Tornado mixer. https://tornado.cash",
"main": "src/index.js",
"main": "app.js",
"scripts": {
"start": "node src/index.js",
"start": "node app.js",
"eslint": "npx eslint --ignore-path .gitignore .",
"test": "echo \"Error: no test specified\" && exit 1"
},

View File

@ -38,22 +38,27 @@ class Fetcher {
}
async fetchGasPrice({ oracleIndex = 0 } = {}) {
oracleIndex = (oracleIndex + 1) % gasOracleUrls.length
const url = gasOracleUrls[oracleIndex]
const delimiter = url === 'https://ethgasstation.info/json/ethgasAPI.json' ? 10 : 1
try {
const response = await fetch(gasOracleUrls[oracleIndex])
const response = await fetch(url)
if (response.status === 200) {
const json = await response.json()
if (Number(json.fast) === 0) {
throw new Error('Fetch gasPrice failed')
}
if (json.slow) {
this.gasPrices.low = Number(json.slow)
this.gasPrices.low = Number(json.slow) / delimiter
}
if (json.safeLow) {
this.gasPrices.low = Number(json.safeLow)
this.gasPrices.low = Number(json.safeLow) / delimiter
}
if (json.standard) {
this.gasPrices.standard = Number(json.standard)
this.gasPrices.standard = Number(json.standard) / delimiter
}
if (json.fast) {
this.gasPrices.fast = Number(json.fast)
this.gasPrices.fast = Number(json.fast) / delimiter
}
} else {
throw Error('Fetch gasPrice failed')

View File

@ -25,7 +25,7 @@ app.use(function(req, res, next) {
app.get('/', function (req, res) {
// just for testing purposes
res.send('This is <a href=https://tornado.cash>tornado.cash</a> Relayer service. Check the /status for settings')
res.send('This is <a href=https://tornado.cash>tornado.cash</a> Relayer service. Check the <a href=/status>/status</a> for settings')
})
app.get('/status', function (req, res) {