fee check

This commit is contained in:
Alexey 2019-07-19 20:34:51 +03:00
parent faecc9fa87
commit 3ec4b6c7ec
3 changed files with 13 additions and 9 deletions

View File

@ -1,4 +1,6 @@
NET_ID=42
RPC_URL=https://kovan.infura.io/v3/a3f4d001c1fc4a359ea70dd27fd9cb51
PRIVATE_KEY=
MIXER_ADDRESS=0x30AF2e92263C5387A8A689322BbfE60b6B0855C4
MIXER_ADDRESS=0x30AF2e92263C5387A8A689322BbfE60b6B0855C4
# in wei
DESIRED_FEE=10000000000000000

View File

@ -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/']
}

View File

@ -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]