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