mirror of
https://github.com/tornadocash/tornado-relayer
synced 2024-02-02 15:04:06 +01:00
fix contract address validation
This commit is contained in:
parent
a7fc9c4b24
commit
16d8e0fc28
@ -19,7 +19,7 @@ ajv.addKeyword('isAddress', {
|
||||
ajv.addKeyword('isKnownContract', {
|
||||
validate: (schema, data) => {
|
||||
try {
|
||||
return getInstance(data) !== null
|
||||
return !!getInstance(data)
|
||||
} catch (e) {
|
||||
return false
|
||||
}
|
||||
|
30
src/utils.js
30
src/utils.js
@ -10,19 +10,33 @@ const TOKENS = {
|
||||
},
|
||||
}
|
||||
|
||||
const addressMap = new Map()
|
||||
for (const [key, value] of Object.entries(instances)) {
|
||||
const netId = Number(key.substring(5))
|
||||
for (const [currency, { instanceAddress, symbol, decimals }] of Object.entries(value)) {
|
||||
Object.entries(instanceAddress).forEach(([amount, address]) =>
|
||||
addressMap.set(
|
||||
{ netId, address },
|
||||
{
|
||||
currency,
|
||||
amount,
|
||||
symbol,
|
||||
decimals,
|
||||
},
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
const sleep = ms => new Promise(res => setTimeout(res, ms))
|
||||
|
||||
function getInstance(address) {
|
||||
address = toChecksumAddress(address)
|
||||
const inst = instances[`netId${netId}`]
|
||||
for (const currency of Object.keys(inst)) {
|
||||
for (const amount of Object.keys(inst[currency].instanceAddress)) {
|
||||
if (inst[currency].instanceAddress[amount] === address) {
|
||||
return { currency, amount }
|
||||
if (addressMap.has({ netId, address })) {
|
||||
return addressMap.get({ netId, address })
|
||||
} else {
|
||||
throw new Error('Unknown contact address')
|
||||
}
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
const poseidonHash = items => toBN(poseidon(items).toString())
|
||||
|
@ -25,7 +25,6 @@ const {
|
||||
torn,
|
||||
netId,
|
||||
gasLimits,
|
||||
instances,
|
||||
privateKey,
|
||||
httpRpcUrl,
|
||||
oracleRpcUrl,
|
||||
@ -131,8 +130,7 @@ async function getGasPrice() {
|
||||
}
|
||||
|
||||
async function checkTornadoFee({ args, contract }) {
|
||||
const { currency, amount } = getInstance(contract)
|
||||
const { decimals } = instances[`netId${netId}`][currency]
|
||||
const { currency, amount, decimals } = getInstance(contract)
|
||||
const [fee, refund] = [args[4], args[5]].map(toBN)
|
||||
const gasPrice = await getGasPrice()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user