mirror of
https://github.com/tornadocash/tornado-nova
synced 2024-02-02 14:53:56 +01:00
fix deposit
This commit is contained in:
parent
709bde4705
commit
a772d76829
30
src/index.js
30
src/index.js
@ -24,7 +24,7 @@ const toHex = (number, length = 32) => '0x' + (number instanceof Buffer ? number
|
|||||||
|
|
||||||
function merklePathIndicesToBigint(indexArray) {
|
function merklePathIndicesToBigint(indexArray) {
|
||||||
let result = 0
|
let result = 0
|
||||||
for(let item of indexArray) {
|
for(let item of indexArray.slice().reverse()) {
|
||||||
result = (result << 1) + item
|
result = (result << 1) + item
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
@ -86,8 +86,8 @@ async function buildMerkleTree() {
|
|||||||
console.log('Getting contract state...')
|
console.log('Getting contract state...')
|
||||||
const events = await contract.getPastEvents('NewCommitment', { fromBlock: 0, toBlock: 'latest' })
|
const events = await contract.getPastEvents('NewCommitment', { fromBlock: 0, toBlock: 'latest' })
|
||||||
const leaves = events
|
const leaves = events
|
||||||
.sort((a, b) => a.returnValues.index - b.returnValues.index) // todo sort by event date
|
.sort((a, b) => a.returnValues.index - b.returnValues.index) // todo sort by event date
|
||||||
.map(e => e.returnValues.commitment)
|
.map(e => e.returnValues.commitment)
|
||||||
return new MerkleTree(MERKLE_TREE_HEIGHT, leaves)
|
return new MerkleTree(MERKLE_TREE_HEIGHT, leaves)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,16 +98,7 @@ async function insertOutput(tree, output) {
|
|||||||
output.merklePathElements = path_elements
|
output.merklePathElements = path_elements
|
||||||
}
|
}
|
||||||
|
|
||||||
async function main() {
|
async function deposit() {
|
||||||
web3 = new Web3(new Web3.providers.HttpProvider(RPC_URL, { timeout: 5 * 60 * 1000 }), null, { transactionConfirmationBlocks: 1 })
|
|
||||||
circuit = require('../build/circuits/transaction.json')
|
|
||||||
proving_key = fs.readFileSync('../build/circuits/transaction_proving_key.bin').buffer
|
|
||||||
groth16 = await buildGroth16()
|
|
||||||
netId = await web3.eth.net.getId()
|
|
||||||
const contractData = require('../build/contracts/TornadoPool.json')
|
|
||||||
contract = new web3.eth.Contract(contractData.abi, contractData.networks[netId].address)
|
|
||||||
web3.eth.defaultAccount = (await web3.eth.getAccounts())[0]
|
|
||||||
|
|
||||||
const amount = 1e6;
|
const amount = 1e6;
|
||||||
const tree = await buildMerkleTree()
|
const tree = await buildMerkleTree()
|
||||||
const oldRoot = await tree.root()
|
const oldRoot = await tree.root()
|
||||||
@ -164,6 +155,19 @@ async function main() {
|
|||||||
console.log('Sending deposit transaction...')
|
console.log('Sending deposit transaction...')
|
||||||
const receipt = await contract.methods.transaction(proof, ...args).send({ value: amount, from: web3.eth.defaultAccount, gas: 1e6 })
|
const receipt = await contract.methods.transaction(proof, ...args).send({ value: amount, from: web3.eth.defaultAccount, gas: 1e6 })
|
||||||
console.log(`Receipt ${receipt.transactionHash}`)
|
console.log(`Receipt ${receipt.transactionHash}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
async function main() {
|
||||||
|
web3 = new Web3(new Web3.providers.HttpProvider(RPC_URL, { timeout: 5 * 60 * 1000 }), null, { transactionConfirmationBlocks: 1 })
|
||||||
|
circuit = require('../build/circuits/transaction.json')
|
||||||
|
proving_key = fs.readFileSync('../build/circuits/transaction_proving_key.bin').buffer
|
||||||
|
groth16 = await buildGroth16()
|
||||||
|
netId = await web3.eth.net.getId()
|
||||||
|
const contractData = require('../build/contracts/TornadoPool.json')
|
||||||
|
contract = new web3.eth.Contract(contractData.abi, contractData.networks[netId].address)
|
||||||
|
web3.eth.defaultAccount = (await web3.eth.getAccounts())[0]
|
||||||
|
|
||||||
|
await deposit()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user