diff --git a/contracts/transfer/src/lib.rs b/contracts/transfer/src/lib.rs index 68f7fa2019..f7017e800a 100644 --- a/contracts/transfer/src/lib.rs +++ b/contracts/transfer/src/lib.rs @@ -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] diff --git a/contracts/transfer/src/state.rs b/contracts/transfer/src/state.rs index 9405538415..2928dc3e16 100644 --- a/contracts/transfer/src/state.rs +++ b/contracts/transfer/src/state.rs @@ -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, diff --git a/contracts/transfer/src/tree.rs b/contracts/transfer/src/tree.rs index f35239af9b..6df8a2f86f 100644 --- a/contracts/transfer/src/tree.rs +++ b/contracts/transfer/src/tree.rs @@ -97,4 +97,8 @@ impl Tree { ) -> Option> { self.tree.opening(pos) } + + pub fn leaves_len(&self) -> u64 { + self.leaves.len() as u64 + } }