77const config = require ( '../config' )
88const { redisClient, redisOpts } = require ( './redis' )
99
10- const { web3, fetcher, sender } = require ( './instances' )
10+ const { web3, fetcher, sender, gasPriceOracle } = require ( './instances' )
1111const withdrawQueue = new Queue ( 'withdraw' , redisOpts )
1212
1313const reponseCbs = { }
@@ -22,26 +22,26 @@ async function relayController(req, resp) {
2222 let requestJob
2323
2424 const { proof, args, contract } = req . body
25- let { valid , reason } = isValidProof ( proof )
25+ let { valid, reason } = isValidProof ( proof )
2626 if ( ! valid ) {
2727 console . log ( 'Proof is invalid:' , reason )
2828 return resp . status ( 400 ) . json ( { error : 'Proof format is invalid' } )
2929 }
3030
31- ( { valid , reason } = isValidArgs ( args ) )
31+ ( { valid, reason } = isValidArgs ( args ) )
3232 if ( ! valid ) {
3333 console . log ( 'Args are invalid:' , reason )
3434 return resp . status ( 400 ) . json ( { error : 'Withdraw arguments are invalid' } )
3535 }
3636
3737 let currency , amount
38- ( { valid, currency, amount } = isKnownContract ( contract ) )
38+ ( { valid, currency, amount } = isKnownContract ( contract ) )
3939 if ( ! valid ) {
4040 console . log ( 'Contract does not exist:' , contract )
4141 return resp . status ( 400 ) . json ( { error : 'This relayer does not support the token' } )
4242 }
4343
44- const [ root , nullifierHash , recipient , relayer , fee , refund ] = [
44+ const [ root , nullifierHash , recipient , relayer , fee , refund ] = [
4545 args [ 0 ] ,
4646 args [ 1 ] ,
4747 toChecksumAddress ( args [ 2 ] ) ,
@@ -65,9 +65,9 @@ async function relayController(req, resp) {
6565 reponseCbs [ requestJob . id ] = resp
6666}
6767
68- withdrawQueue . process ( async function ( job , done ) {
68+ withdrawQueue . process ( async function ( job , done ) {
6969 console . log ( Date . now ( ) , ' withdraw started' , job . id )
70- const gasPrices = fetcher . gasPrices
70+ const gasPrices = await gasPriceOracle . gasPrices ( )
7171 const { contract, nullifierHash, root, proof, args, refund, currency, amount, fee } = job . data
7272 console . log ( JSON . stringify ( job . data ) )
7373 // job.data contains the custom data passed when the job was created
@@ -128,7 +128,7 @@ withdrawQueue.process(async function(job, done){
128128 nonce
129129 }
130130 tx . date = Date . now ( )
131- await redisClient . set ( 'tx:' + nonce , JSON . stringify ( tx ) )
131+ await redisClient . set ( 'tx:' + nonce , JSON . stringify ( tx ) )
132132 nonce += 1
133133 await redisClient . set ( 'nonce' , nonce )
134134 sender . sendTx ( tx , done )
0 commit comments