return inserted index from merkle tree

This commit is contained in:
poma 2019-11-01 04:07:11 +03:00
parent b8d22464e3
commit 54e2c5f890
2 changed files with 4 additions and 3 deletions

View File

@ -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) {

View File

@ -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 */