Skip to content

Commit

Permalink
transfer-contract: add last_pos contract call
Browse files Browse the repository at this point in the history
  • Loading branch information
herr-seppia committed Jan 12, 2024
1 parent 57752f2 commit ecdc2bb
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
5 changes: 5 additions & 0 deletions contracts/transfer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ unsafe fn existing_nullifiers(arg_len: u32) -> u32 {
})
}

#[no_mangle]
unsafe fn last_pos(arg_len: u32) -> u32 {
rusk_abi::wrap_call(arg_len, |_: ()| STATE.last_pos())
}

// "Feeder" queries

#[no_mangle]
Expand Down
5 changes: 5 additions & 0 deletions contracts/transfer/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,11 @@ impl TransferState {
self.tree.root()
}

/// Get the position of the last note in the tree.
pub fn last_pos(&self) -> u64 {
self.tree.leaves_len()
}

/// Get the opening
pub fn opening(
&self,
Expand Down
4 changes: 4 additions & 0 deletions contracts/transfer/src/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,8 @@ impl Tree {
) -> Option<PoseidonOpening<(), TRANSFER_TREE_DEPTH, A>> {
self.tree.opening(pos)
}

pub fn leaves_len(&self) -> u64 {
self.leaves.len() as u64
}
}

0 comments on commit ecdc2bb

Please sign in to comment.