spark_rust/wallet/internal_handlers/traits/
leaves.rs

1use tonic::async_trait;
2
3use crate::{
4    error::SparkSdkError,
5    signer::traits::SparkSigner,
6    wallet::leaf_manager::SparkLeaf,
7    // wallet::leaf_manager::{LeafNode, LeafNodeStatus, PublicLeafNode},
8};
9
10#[derive(Debug)]
11pub(crate) struct LeafSelectionResponse {
12    pub(crate) unlocking_id: Option<String>,
13    pub(crate) leaves: Vec<SparkLeaf>,
14    #[allow(dead_code)]
15    pub(crate) total_value: u64,
16    pub(crate) exact_amount: bool,
17}
18
19#[async_trait]
20pub(crate) trait LeavesInternalHandlers<S: SparkSigner + Send + Sync> {
21    // get_leaves in JS SDK
22    async fn sync_leaves(&self) -> Result<(), SparkSdkError>;
23
24    async fn prepare_leaves_for_amount(
25        &self,
26        target_amount: u64,
27    ) -> Result<LeafSelectionResponse, SparkSdkError>;
28
29    // optimize leaves
30    async fn optimize_leaves(&self) -> Result<(), SparkSdkError>;
31
32    // check if leaves are inefficient
33    fn are_leaves_inefficient(&self) -> Result<bool, SparkSdkError>;
34}