mirror of
https://github.com/tornadocash/tornado-core.git
synced 2024-11-22 01:37:07 +01:00
return inserted index from merkle tree
This commit is contained in:
parent
b8d22464e3
commit
54e2c5f890
@ -56,7 +56,7 @@ contract MerkleTreeWithHistory {
|
||||
hash = R;
|
||||
}
|
||||
|
||||
function _insert(uint256 leaf) internal {
|
||||
function _insert(uint256 leaf) internal returns(uint256 index) {
|
||||
uint32 current_index = next_index;
|
||||
require(current_index != 2**levels, "Merkle tree is full. No more leafs can be added");
|
||||
next_index += 1;
|
||||
@ -82,6 +82,7 @@ contract MerkleTreeWithHistory {
|
||||
|
||||
current_root = (current_root + 1) % ROOT_HISTORY_SIZE;
|
||||
_roots[current_root] = current_level_hash;
|
||||
return next_index - 1;
|
||||
}
|
||||
|
||||
function isKnownRoot(uint256 root) public view returns(bool) {
|
||||
|
@ -65,11 +65,11 @@ contract Mixer is MerkleTreeWithHistory {
|
||||
function deposit(uint256 commitment) public payable {
|
||||
require(isDepositsEnabled, "deposits are disabled");
|
||||
require(!commitments[commitment], "The commitment has been submitted");
|
||||
_insert(commitment);
|
||||
uint256 insertedIndex = _insert(commitment);
|
||||
commitments[commitment] = true;
|
||||
_processDeposit();
|
||||
|
||||
emit Deposit(commitment, next_index - 1, block.timestamp);
|
||||
emit Deposit(commitment, insertedIndex, block.timestamp);
|
||||
}
|
||||
|
||||
/** @dev this function is defined in a child contract */
|
||||
|
Loading…
Reference in New Issue
Block a user