fix contract address validation
This commit is contained in:
parent
a7fc9c4b24
commit
16d8e0fc28
@ -19,7 +19,7 @@ ajv.addKeyword('isAddress', {
|
|||||||
ajv.addKeyword('isKnownContract', {
|
ajv.addKeyword('isKnownContract', {
|
||||||
validate: (schema, data) => {
|
validate: (schema, data) => {
|
||||||
try {
|
try {
|
||||||
return getInstance(data) !== null
|
return !!getInstance(data)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
30
src/utils.js
30
src/utils.js
@ -10,20 +10,34 @@ 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))
|
const sleep = ms => new Promise(res => setTimeout(res, ms))
|
||||||
|
|
||||||
function getInstance(address) {
|
function getInstance(address) {
|
||||||
address = toChecksumAddress(address)
|
address = toChecksumAddress(address)
|
||||||
const inst = instances[`netId${netId}`]
|
if (addressMap.has({ netId, address })) {
|
||||||
for (const currency of Object.keys(inst)) {
|
return addressMap.get({ netId, address })
|
||||||
for (const amount of Object.keys(inst[currency].instanceAddress)) {
|
} else {
|
||||||
if (inst[currency].instanceAddress[amount] === address) {
|
throw new Error('Unknown contact address')
|
||||||
return { currency, amount }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
const poseidonHash = items => toBN(poseidon(items).toString())
|
const poseidonHash = items => toBN(poseidon(items).toString())
|
||||||
const poseidonHash2 = (a, b) => poseidonHash([a, b])
|
const poseidonHash2 = (a, b) => poseidonHash([a, b])
|
||||||
|
@ -25,7 +25,6 @@ const {
|
|||||||
torn,
|
torn,
|
||||||
netId,
|
netId,
|
||||||
gasLimits,
|
gasLimits,
|
||||||
instances,
|
|
||||||
privateKey,
|
privateKey,
|
||||||
httpRpcUrl,
|
httpRpcUrl,
|
||||||
oracleRpcUrl,
|
oracleRpcUrl,
|
||||||
@ -131,8 +130,7 @@ async function getGasPrice() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function checkTornadoFee({ args, contract }) {
|
async function checkTornadoFee({ args, contract }) {
|
||||||
const { currency, amount } = getInstance(contract)
|
const { currency, amount, decimals } = getInstance(contract)
|
||||||
const { decimals } = instances[`netId${netId}`][currency]
|
|
||||||
const [fee, refund] = [args[4], args[5]].map(toBN)
|
const [fee, refund] = [args[4], args[5]].map(toBN)
|
||||||
const gasPrice = await getGasPrice()
|
const gasPrice = await getGasPrice()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user