From 3ec4b6c7ec523b4a5b4e35c7226e0e6d6f6d275e Mon Sep 17 00:00:00 2001 From: Alexey Date: Fri, 19 Jul 2019 20:34:51 +0300 Subject: [PATCH] fee check --- .env.example | 4 +++- config.js | 3 ++- index.js | 15 ++++++++------- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/.env.example b/.env.example index 2bab477..3d1bbd9 100644 --- a/.env.example +++ b/.env.example @@ -1,4 +1,6 @@ NET_ID=42 RPC_URL=https://kovan.infura.io/v3/a3f4d001c1fc4a359ea70dd27fd9cb51 PRIVATE_KEY= -MIXER_ADDRESS=0x30AF2e92263C5387A8A689322BbfE60b6B0855C4 \ No newline at end of file +MIXER_ADDRESS=0x30AF2e92263C5387A8A689322BbfE60b6B0855C4 +# in wei +DESIRED_FEE=10000000000000000 \ No newline at end of file diff --git a/config.js b/config.js index cdb9405..88f2130 100644 --- a/config.js +++ b/config.js @@ -4,7 +4,8 @@ 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', + mixerAddress: process.env.MIXER_ADDRESS, + desiredFee: process.env.DESIRED_FEE || 10000000000000000, // 0.01 ETH defaultGasPrice: 1, gasOracleUrls: ['https://www.etherchain.org/api/gasPriceOracle', 'https://gasprice.poa.network/'] } \ No newline at end of file diff --git a/index.js b/index.js index f948c70..8efa9a0 100644 --- a/index.js +++ b/index.js @@ -1,16 +1,16 @@ -const { numberToHex, toWei, toHex } = require('web3-utils') +const { numberToHex, toWei, toHex, toBN } = require('web3-utils') const Web3 = require('web3') const express = require('express') const app = express() app.use(express.json()) app.use(function(req, res, next) { - res.header('Access-Control-Allow-Origin', '*') // update to match the domain you will make the request from + res.header('Access-Control-Allow-Origin', '*') res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept') next() }) -const { netId, rpcUrl, privateKey, mixerAddress, defaultGasPrice } = require('./config') +const { netId, rpcUrl, privateKey, mixerAddress, defaultGasPrice, desiredFee } = require('./config') const { fetchGasPrice, isValidProof } = require('./utils') const web3 = new Web3(rpcUrl, null, { transactionConfirmationBlocks: 1 }) @@ -36,10 +36,11 @@ app.post('/relay', async (req, resp) => { let { pi_a, pi_b, pi_c, publicSignals } = req.body - // TODO - // if (bigInt(proof.publicSignals[3]) < getMinimumFee()) { - // resp.status(403).send('Fee is too low') - // } + const fee = toBN(publicSignals[3]) + if (fee.lt(toBN(desiredFee))) { + console.log('Fee is too low') + return resp.status(400).send('Fee is too low') + } try { const nullifier = publicSignals[1]