mirror of
https://github.com/tornadocash/tornado-relayer.git
synced 2025-08-15 09:35:59 -04:00
update
This commit is contained in:
parent
b22311e2c6
commit
6367bad194
3 changed files with 45 additions and 18 deletions
22
src/utils.js
22
src/utils.js
|
@ -2,7 +2,7 @@ const { instances, netId } = require('../config')
|
|||
const { poseidon } = require('circomlib')
|
||||
const { toBN } = require('web3-utils')
|
||||
|
||||
const sleep = (ms) => new Promise(res => setTimeout(res, ms))
|
||||
const sleep = (ms) => new Promise((res) => setTimeout(res, ms))
|
||||
|
||||
function getInstance(address) {
|
||||
const inst = instances[`netId${netId}`]
|
||||
|
@ -30,19 +30,25 @@ const poseidonHash = (items) => toBN(poseidon(items).toString())
|
|||
const poseidonHash2 = (a, b) => poseidonHash([a, b])
|
||||
|
||||
function setSafeInterval(func, interval) {
|
||||
func().catch(console.error).finally(() => {
|
||||
setTimeout(() => setSafeInterval(func, interval), interval)
|
||||
})
|
||||
func()
|
||||
.catch(console.error)
|
||||
.finally(() => {
|
||||
setTimeout(() => setSafeInterval(func, interval), interval)
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* A promise that resolves when the source emits specified event
|
||||
*/
|
||||
function when(source, event) {
|
||||
return new Promise(resolve => {
|
||||
source.once(event, payload => {
|
||||
resolve(payload)
|
||||
})
|
||||
return new Promise((resolve, reject) => {
|
||||
source
|
||||
.once(event, (payload) => {
|
||||
resolve(payload)
|
||||
})
|
||||
.on('error', (error) => {
|
||||
reject(error)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue