From 38e4f74afbc58bc57eaeeecd3a109a6365d1df05 Mon Sep 17 00:00:00 2001 From: Alexey Date: Thu, 18 Jul 2019 17:45:33 +0300 Subject: [PATCH] docker-compose --- .env.example | 4 +--- README.md | 5 ++++- config.js | 4 ++-- docker-compose.yml | 12 ++++++++++++ index.js | 8 ++++---- 5 files changed, 23 insertions(+), 10 deletions(-) create mode 100644 docker-compose.yml diff --git a/.env.example b/.env.example index be6bb37..2bab477 100644 --- a/.env.example +++ b/.env.example @@ -1,6 +1,4 @@ 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/ \ No newline at end of file +MIXER_ADDRESS=0x30AF2e92263C5387A8A689322BbfE60b6B0855C4 \ No newline at end of file diff --git a/README.md b/README.md index dbe81be..d510b85 100644 --- a/README.md +++ b/README.md @@ -4,11 +4,14 @@ 2. `cp .env.example .env` 3. Modify `.env` as needed -## Run +## Run localy 1. `npm run start` 2. `curl -X POST -H 'content-type:application/json' --data '' http://127.0.0.1:8000/relay` Relayer should return a transaction hash. +## Run in Docker +1. `docker-compose up -d` + ## Proof example ```json { diff --git a/config.js b/config.js index 2421eea..cdb9405 100644 --- a/config.js +++ b/config.js @@ -5,6 +5,6 @@ module.exports = { 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/'] + defaultGasPrice: 1, + gasOracleUrls: ['https://www.etherchain.org/api/gasPriceOracle', 'https://gasprice.poa.network/'] } \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..41b3e90 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,12 @@ +version: '2' + +services: + relayer: + image: relayer + build: ./ + restart: always + ports: + - 8000:8000 + environment: + - NODE_ENV=production + env_file: ./.env \ No newline at end of file diff --git a/index.js b/index.js index e8c5b30..5b3d2b0 100644 --- a/index.js +++ b/index.js @@ -1,19 +1,19 @@ -const { fetchGasPrice, isValidProof } = require('./utils') const { numberToHex, toWei, toHex } = require('web3-utils') - +const Web3 = require('web3') const express = require('express') + const app = express() app.use(express.json()) const { netId, rpcUrl, privateKey, mixerAddress, defaultGasPrice } = require('./config') +const { fetchGasPrice, isValidProof } = require('./utils') -const Web3 = require('web3') const web3 = new Web3(rpcUrl, null, { transactionConfirmationBlocks: 1 }) const account = web3.eth.accounts.privateKeyToAccount('0x' + privateKey) web3.eth.accounts.wallet.add('0x' + privateKey) web3.eth.defaultAccount = account.address -const mixerABI = require('./mixerABI.json') +const mixerABI = require('./mixerABI.json') const mixer = new web3.eth.Contract(mixerABI, mixerAddress) const gasPrices = { fast: defaultGasPrice }