mirror of
https://github.com/tornadocash/tornado-core.git
synced 2024-10-01 01:06:17 -04:00
Merge pull request #32 from tornadocash/migrationScript
Migration script
This commit is contained in:
commit
51c3d6b28c
@ -1,4 +1,4 @@
|
||||
MERKLE_TREE_HEIGHT=16
|
||||
MERKLE_TREE_HEIGHT=20
|
||||
# in wei
|
||||
ETH_AMOUNT=100000000000000000
|
||||
TOKEN_AMOUNT=100000000000000000
|
||||
|
@ -52,4 +52,4 @@ template Withdraw(levels) {
|
||||
}
|
||||
}
|
||||
|
||||
component main = Withdraw(16);
|
||||
component main = Withdraw(20);
|
||||
|
6
cli.js
6
cli.js
@ -56,7 +56,7 @@ async function deposit() {
|
||||
const deposit = createDeposit(rbigint(31), rbigint(31))
|
||||
|
||||
console.log('Submitting deposit transaction')
|
||||
await tornado.methods.deposit(toHex(deposit.commitment)).send({ value: ETH_AMOUNT, from: senderAccount, gas:1e6 })
|
||||
await tornado.methods.deposit(toHex(deposit.commitment)).send({ value: ETH_AMOUNT, from: senderAccount, gas:2e6 })
|
||||
|
||||
const note = toHex(deposit.preimage, 62)
|
||||
console.log('Your note:', note)
|
||||
@ -71,14 +71,14 @@ async function depositErc20() {
|
||||
|
||||
if(ERC20_TOKEN === '') {
|
||||
console.log('Minting some test tokens to deposit')
|
||||
await erc20.methods.mint(senderAccount, TOKEN_AMOUNT).send({ from: senderAccount, gas: 1e6 })
|
||||
await erc20.methods.mint(senderAccount, TOKEN_AMOUNT).send({ from: senderAccount, gas: 2e6 })
|
||||
}
|
||||
|
||||
console.log('Approving tokens for deposit')
|
||||
await erc20.methods.approve(erc20tornado._address, TOKEN_AMOUNT).send({ from: senderAccount, gas:1e6 })
|
||||
|
||||
console.log('Submitting deposit transaction')
|
||||
await erc20tornado.methods.deposit(toHex(deposit.commitment)).send({ from: senderAccount, gas:1e6 })
|
||||
await erc20tornado.methods.deposit(toHex(deposit.commitment)).send({ from: senderAccount, gas:2e6 })
|
||||
|
||||
const note = toHex(deposit.preimage, 62)
|
||||
console.log('Your note:', note)
|
||||
|
@ -38,4 +38,34 @@ contract ETHTornado is Tornado {
|
||||
require(success, "payment to _relayer did not go thru");
|
||||
}
|
||||
}
|
||||
/**
|
||||
@dev Migrate state from old mixer to this one.
|
||||
@param _commitments deposited commitments from previous contract
|
||||
@param _nullifierHashes spent nullifiers from previous contract
|
||||
*/
|
||||
bool public isMigrated = false;
|
||||
function migrateState(bytes32[] calldata _commitments, bytes32[] calldata _nullifierHashes) external onlyOperator {
|
||||
require(!isMigrated, "Migration is disabled");
|
||||
for (uint32 i = 0; i < _commitments.length; i++) {
|
||||
commitments[_commitments[i]] = true;
|
||||
emit Deposit(_commitments[i], nextIndex + i, block.timestamp);
|
||||
}
|
||||
|
||||
nextIndex += uint32(_commitments.length);
|
||||
|
||||
for (uint256 i = 0; i < _nullifierHashes.length; i++) {
|
||||
nullifierHashes[_nullifierHashes[i]] = true;
|
||||
emit Withdrawal(address(0), _nullifierHashes[i], address(0), 0);
|
||||
}
|
||||
}
|
||||
|
||||
function initializeTreeForMigration(bytes32[] calldata _filledSubtrees, bytes32 _root) external onlyOperator {
|
||||
require(!isMigrated, "already migrated");
|
||||
filledSubtrees = _filledSubtrees;
|
||||
roots[0] = _root;
|
||||
}
|
||||
|
||||
function finishMigration() external payable onlyOperator {
|
||||
isMigrated = true;
|
||||
}
|
||||
}
|
||||
|
145
migrationDeposits.js
Normal file
145
migrationDeposits.js
Normal file
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user