Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 11 additions & 106 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ benchmark-pallet:
cargo build --release --features=runtime-benchmarks
./target/release/orbinum-node benchmark pallet --chain=dev --pallet=$(PALLET) --extrinsic='*' --steps=50 --repeat=20 --output=./frame/$(PALLET)/src/weights.rs --template=./scripts/frame-weight-template.hbs

.PHONY: run-dev
# Run node in development mode with temporary storage
run-dev:
./target/release/orbinum-node --dev --tmp

.PHONY: audit
# Run security audit (ignoring known Polkadot SDK transitive dependencies via deny.toml)
audit:
Expand Down
1 change: 1 addition & 0 deletions client/rpc-v2/src/orbinum/ORBINUM_RPC_API.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Method names use the `privacy_` prefix.
- `merkle_root`: `string`
- `commitment_count`: `u32`
- `total_balance`: `u128` (minimum units)
- `asset_balances`: `Array<{ asset_id: u32, balance: u128 }>` (solo balances no-cero)
- `tree_depth`: `u32`

## Usage Notes
Expand Down
2 changes: 1 addition & 1 deletion client/rpc-v2/src/orbinum/application/dto/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ mod pool_stats_response;

pub use merkle_proof_response::MerkleProofResponse;
pub use nullifier_status_response::NullifierStatusResponse;
pub use pool_stats_response::PoolStatsResponse;
pub use pool_stats_response::{AssetBalanceResponse, PoolStatsResponse};
40 changes: 39 additions & 1 deletion client/rpc-v2/src/orbinum/application/dto/pool_stats_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ use serde::{Deserialize, Serialize};
/// Response DTO for pool statistics.
///
/// Maps from `domain::PoolStatistics` into JSON-friendly fields.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct AssetBalanceResponse {
/// Asset identifier.
pub asset_id: u32,
/// Asset balance in minimum units.
pub balance: u128,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct PoolStatsResponse {
/// Merkle tree root (hex string).
Expand All @@ -13,22 +21,33 @@ pub struct PoolStatsResponse {
pub commitment_count: u32,
/// Total pool balance (in minimum units).
pub total_balance: u128,
/// Non-zero balances grouped by asset.
pub asset_balances: Vec<AssetBalanceResponse>,
/// Tree depth.
pub tree_depth: u32,
}

impl AssetBalanceResponse {
/// Creates a new `AssetBalanceResponse`.
pub fn new(asset_id: u32, balance: u128) -> Self {
Self { asset_id, balance }
}
}

impl PoolStatsResponse {
/// Creates a new `PoolStatsResponse`.
pub fn new(
merkle_root: String,
commitment_count: u32,
total_balance: u128,
asset_balances: Vec<AssetBalanceResponse>,
tree_depth: u32,
) -> Self {
Self {
merkle_root,
commitment_count,
total_balance,
asset_balances,
tree_depth,
}
}
Expand All @@ -40,11 +59,25 @@ mod tests {

#[test]
fn should_create_pool_stats_response() {
let response = PoolStatsResponse::new("0x1234".to_string(), 42, 1_000_000u128, 32);
let response = PoolStatsResponse::new(
"0x1234".to_string(),
42,
1_000_000u128,
vec![
AssetBalanceResponse::new(0, 900_000),
AssetBalanceResponse::new(1, 100_000),
],
32,
);

assert_eq!(response.merkle_root, "0x1234");
assert_eq!(response.commitment_count, 42);
assert_eq!(response.total_balance, 1_000_000u128);
assert_eq!(response.asset_balances.len(), 2);
assert_eq!(
response.asset_balances[0],
AssetBalanceResponse::new(0, 900_000)
);
assert_eq!(response.tree_depth, 32);
}

Expand All @@ -56,6 +89,11 @@ mod tests {
fn assert_debug<T: core::fmt::Debug>() {}
fn assert_eq_trait<T: Eq>() {}

assert_serialize::<AssetBalanceResponse>();
assert_deserialize::<AssetBalanceResponse>();
assert_clone::<AssetBalanceResponse>();
assert_debug::<AssetBalanceResponse>();
assert_eq_trait::<AssetBalanceResponse>();
assert_serialize::<PoolStatsResponse>();
assert_deserialize::<PoolStatsResponse>();
assert_clone::<PoolStatsResponse>();
Expand Down
4 changes: 3 additions & 1 deletion client/rpc-v2/src/orbinum/application/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ pub mod services;
pub use services::{MerkleProofService, NullifierService, PoolQueryService};

// DTO re-exports
pub use dto::{MerkleProofResponse, NullifierStatusResponse, PoolStatsResponse};
pub use dto::{
AssetBalanceResponse, MerkleProofResponse, NullifierStatusResponse, PoolStatsResponse,
};

/// Application layer error type.
#[derive(Debug, Clone, PartialEq, Eq)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::orbinum::{
};

// Import zero-hash function from the pallet
use pallet_shielded_pool::infrastructure::merkle_tree::get_zero_hash_cached;
use pallet_shielded_pool::{infrastructure::merkle_tree::get_zero_hash_cached, DEFAULT_TREE_DEPTH};

// Logging
extern crate log;
Expand Down Expand Up @@ -162,7 +162,7 @@ where
let block_hash = self.query.best_hash()?;
let root = self.query.get_merkle_root(block_hash)?;
let size = self.query.get_tree_size(block_hash)?;
let depth = TreeDepth::from_tree_size(size.value());
let depth = TreeDepth::new(DEFAULT_TREE_DEPTH as u32);

Ok((root, size, depth))
}
Expand Down Expand Up @@ -282,6 +282,6 @@ mod tests {

assert_eq!(root, Commitment::new([3u8; 32]));
assert_eq!(size.value(), 5);
assert_eq!(depth.value(), TreeDepth::from_tree_size(5).value());
assert_eq!(depth.value(), DEFAULT_TREE_DEPTH as u32);
}
}
Loading
Loading