mirror of
https://github.com/tornadocash/tornado-core.git
synced 2024-11-22 09:47:13 +01:00
fix PRIVATE_KEY dependency
This commit is contained in:
parent
03175a2277
commit
f90a898001
20
cli.js
20
cli.js
@ -125,7 +125,8 @@ async function generateMerkleProof(deposit) {
|
|||||||
const leafIndex = depositEvent ? depositEvent.returnValues.leafIndex : -1
|
const leafIndex = depositEvent ? depositEvent.returnValues.leafIndex : -1
|
||||||
|
|
||||||
// Validate that our data is correct
|
// Validate that our data is correct
|
||||||
const isValidRoot = await tornado.methods.isKnownRoot(toHex(await tree.root())).call()
|
const root = await tree.root()
|
||||||
|
const isValidRoot = await tornado.methods.isKnownRoot(toHex(root)).call()
|
||||||
const isSpent = await tornado.methods.isSpent(toHex(deposit.nullifierHash)).call()
|
const isSpent = await tornado.methods.isSpent(toHex(deposit.nullifierHash)).call()
|
||||||
assert(isValidRoot === true, 'Merkle tree is corrupted')
|
assert(isValidRoot === true, 'Merkle tree is corrupted')
|
||||||
assert(isSpent === false, 'The note is already spent')
|
assert(isSpent === false, 'The note is already spent')
|
||||||
@ -193,6 +194,9 @@ async function withdraw({ deposit, currency, amount, recipient, relayerURL, refu
|
|||||||
}
|
}
|
||||||
refund = toWei(refund)
|
refund = toWei(refund)
|
||||||
if (relayerURL) {
|
if (relayerURL) {
|
||||||
|
if(relayerURL.endsWith('.eth')) {
|
||||||
|
throw new Error('ENS name resolving is not supported. Please provide DNS name of the relayer. See instuctions in README.md')
|
||||||
|
}
|
||||||
const relayerStatus = await axios.get(relayerURL + '/status')
|
const relayerStatus = await axios.get(relayerURL + '/status')
|
||||||
const { relayerAddress, netId, gasPrices, ethPrices, relayerServiceFee } = relayerStatus.data
|
const { relayerAddress, netId, gasPrices, ethPrices, relayerServiceFee } = relayerStatus.data
|
||||||
assert(netId === await web3.eth.net.getId() || netId === '*', 'This relay is for different network')
|
assert(netId === await web3.eth.net.getId() || netId === '*', 'This relay is for different network')
|
||||||
@ -382,16 +386,20 @@ async function init({ rpc, noteNetId, currency = 'dai', amount = '100' }) {
|
|||||||
contractJson = require('./build/contracts/ETHTornado.json')
|
contractJson = require('./build/contracts/ETHTornado.json')
|
||||||
circuit = require('./build/circuits/withdraw.json')
|
circuit = require('./build/circuits/withdraw.json')
|
||||||
proving_key = fs.readFileSync('build/circuits/withdraw_proving_key.bin').buffer
|
proving_key = fs.readFileSync('build/circuits/withdraw_proving_key.bin').buffer
|
||||||
MERKLE_TREE_HEIGHT = process.env.MERKLE_TREE_HEIGHT
|
MERKLE_TREE_HEIGHT = process.env.MERKLE_TREE_HEIGHT || 20
|
||||||
ETH_AMOUNT = process.env.ETH_AMOUNT
|
ETH_AMOUNT = process.env.ETH_AMOUNT
|
||||||
TOKEN_AMOUNT = process.env.TOKEN_AMOUNT
|
TOKEN_AMOUNT = process.env.TOKEN_AMOUNT
|
||||||
PRIVATE_KEY = process.env.PRIVATE_KEY
|
PRIVATE_KEY = process.env.PRIVATE_KEY
|
||||||
|
if (PRIVATE_KEY) {
|
||||||
|
const account = web3.eth.accounts.privateKeyToAccount('0x' + PRIVATE_KEY)
|
||||||
|
web3.eth.accounts.wallet.add('0x' + PRIVATE_KEY)
|
||||||
|
web3.eth.defaultAccount = account.address
|
||||||
|
senderAccount = account.address
|
||||||
|
} else {
|
||||||
|
console.log('Warning! PRIVATE_KEY not found. Please provide PRIVATE_KEY in .env file if you deposit')
|
||||||
|
}
|
||||||
erc20ContractJson = require('./build/contracts/ERC20Mock.json')
|
erc20ContractJson = require('./build/contracts/ERC20Mock.json')
|
||||||
erc20tornadoJson = require('./build/contracts/ERC20Tornado.json')
|
erc20tornadoJson = require('./build/contracts/ERC20Tornado.json')
|
||||||
const account = web3.eth.accounts.privateKeyToAccount('0x' + PRIVATE_KEY)
|
|
||||||
web3.eth.accounts.wallet.add('0x' + PRIVATE_KEY)
|
|
||||||
web3.eth.defaultAccount = account.address
|
|
||||||
senderAccount = account.address
|
|
||||||
}
|
}
|
||||||
// groth16 initialises a lot of Promises that will never be resolved, that's why we need to use process.exit to terminate the CLI
|
// groth16 initialises a lot of Promises that will never be resolved, that's why we need to use process.exit to terminate the CLI
|
||||||
groth16 = await buildGroth16()
|
groth16 = await buildGroth16()
|
||||||
|
Loading…
Reference in New Issue
Block a user