Get the current Merkle root
Returns the current root hash of the Merkle tree.
env - The Soroban environmentThe current Merkle root as U256
Panics if the contract has not been initialized
fn get_root(env: soroban_sdk::Env) -> Result
Hash two U256 values using Poseidon2 compression
Computes the Poseidon2 hash of two field elements in compression mode. This is the core hashing function used for Merkle tree operations.
env - The Soroban environmentleft - Left input valueright - Right input valueThe Poseidon2 hash result as U256
fn hash_pair(
env: soroban_sdk::Env,
left: soroban_sdk::U256,
right: soroban_sdk::U256,
) -> soroban_sdk::U256
Insert a new leaf into the Merkle tree
Adds a new member to the Merkle tree and updates the root. The leaf is inserted at the next available index and the tree is updated efficiently by only recomputing the hashes along the path to the root. Only the admin can insert leaves.
env - The Soroban environmentleaf - The leaf value to insert (typically a commitment or hash)Returns Ok(()) on success, or MerkleTreeFull if the tree is at
capacity
fn insert_leaf(
env: soroban_sdk::Env,
leaf: soroban_sdk::U256,
) -> Result<(), soroban_sdk::Error>
Update the contract administrator
Changes the admin address to a new address. Only the current admin can call this function.
env - The Soroban environmentnew_admin - Address of the new administratorfn update_admin(
env: soroban_sdk::Env,
new_admin: soroban_sdk::Address,
) -> Result<(), soroban_sdk::Error>
Constructor: initialize the ASP Membership contract
Creates a new Merkle tree with the specified number of levels and sets the admin address. The tree is initialized with zero hashes at each level.
env - The Soroban environmentadmin - Address of the contract administratorlevels - Number of levels in the Merkle tree (must be in range
[1..32])Returns Ok(()) on success, or an error if already initialized
Panics if levels is 0 or greater than 32
fn __constructor(
env: soroban_sdk::Env,
admin: soroban_sdk::Address,
levels: u32,
) -> Result<(), soroban_sdk::Error>
fn approve(
env: soroban_sdk::Env,
from: soroban_sdk::Address,
spender: soroban_sdk::Address,
amount: i128,
)
fn balance(env: soroban_sdk::Env, id: soroban_sdk::Address) -> i128
fn transfer(
env: soroban_sdk::Env,
from: soroban_sdk::Address,
to: soroban_sdk::Address,
amount: i128,
)
fn allowance(
env: soroban_sdk::Env,
from: soroban_sdk::Address,
spender: soroban_sdk::Address,
) -> i128
fn transfer_from(
env: soroban_sdk::Env,
from: soroban_sdk::Address,
to: soroban_sdk::Address,
amount: i128,
)