-
Notifications
You must be signed in to change notification settings - Fork 102
Expand file tree
/
Copy pathview.rs
More file actions
43 lines (35 loc) · 1.24 KB
/
view.rs
File metadata and controls
43 lines (35 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// ============================================================
// View Functions - Read-only queries
// ============================================================
use soroban_sdk::{BytesN, Env};
use crate::crypto::merkle;
use crate::storage::{config, nullifier};
use crate::types::errors::Error;
use crate::types::state::PoolConfig;
/// Returns the current Merkle root (most recent).
pub fn get_root(env: Env) -> Result<BytesN<32>, Error> {
merkle::current_root(&env).ok_or(Error::NotInitialized)
}
/// Returns the total number of deposits (= next leaf index).
pub fn deposit_count(env: Env) -> u32 {
merkle::get_tree_state(&env).next_index
}
/// Check if a root is in the historical root buffer.
pub fn is_known_root(env: Env, root: BytesN<32>) -> bool {
merkle::is_known_root(&env, &root)
}
/// Check if a nullifier has been spent.
pub fn is_spent(env: Env, nullifier_hash: BytesN<32>) -> bool {
nullifier::is_spent(&env, &nullifier_hash)
}
/// Check if the pool is currently paused.
pub fn is_paused(env: Env) -> bool {
match config::load(&env) {
Ok(cfg) => cfg.paused,
Err(_) => false,
}
}
/// Returns the pool configuration.
pub fn get_config(env: Env) -> Result<PoolConfig, Error> {
config::load(&env)
}