From f8fc455d0882c1bd9191fd4ad5d1d9d978dc44a8 Mon Sep 17 00:00:00 2001 From: Aaryamann Challani <43716372+rymnc@users.noreply.github.com> Date: Tue, 12 Sep 2023 14:44:33 +0530 Subject: [PATCH] chore(rln): expose leaves_set api (#213) --- rln/src/ffi.rs | 6 ++++++ rln/tests/ffi.rs | 3 +++ 2 files changed, 9 insertions(+) diff --git a/rln/src/ffi.rs b/rln/src/ffi.rs index 8c652f2..5ed5c02 100644 --- a/rln/src/ffi.rs +++ b/rln/src/ffi.rs @@ -261,6 +261,12 @@ pub extern "C" fn get_leaf(ctx: *mut RLN, index: usize, output_buffer: *mut Buff call_with_output_arg!(ctx, get_leaf, output_buffer, index) } +#[allow(clippy::not_unsafe_ptr_arg_deref)] +#[no_mangle] +pub extern "C" fn leaves_set(ctx: *mut RLN) -> usize { + ctx.process().leaves_set() +} + #[allow(clippy::not_unsafe_ptr_arg_deref)] #[no_mangle] pub extern "C" fn set_next_leaf(ctx: *mut RLN, input_buffer: *const Buffer) -> bool { diff --git a/rln/tests/ffi.rs b/rln/tests/ffi.rs index 469f938..8b72c2e 100644 --- a/rln/tests/ffi.rs +++ b/rln/tests/ffi.rs @@ -143,6 +143,8 @@ mod test { assert!(success, "RLN object creation failed"); let rln_pointer = unsafe { &mut *rln_pointer.assume_init() }; + assert_eq!(rln_pointer.leaves_set(), 0); + // We generate a vector of random leaves let mut leaves: Vec = Vec::new(); let mut rng = thread_rng(); @@ -159,6 +161,7 @@ mod test { let input_buffer = &Buffer::from(leaves_ser.as_ref()); let success = init_tree_with_leaves(rln_pointer, input_buffer); assert!(success, "init tree with leaves call failed"); + assert_eq!(rln_pointer.leaves_set(), no_of_leaves); // We get the root of the tree obtained adding leaves in batch let mut output_buffer = MaybeUninit::::uninit();