spark_sdk/wallet/internal_handlers/traits/
leaves.rs1use tonic::async_trait;
2
3use crate::{
4 error::SparkSdkError,
5 signer::traits::SparkSigner,
6 wallet::leaf_manager::{LeafNode, LeafNodeStatus, PublicLeafNode},
7};
8
9#[derive(Debug)]
10pub(crate) struct LeafSelectionResponse {
11 pub(crate) unlocking_id: Option<String>,
12 pub(crate) leaves: Vec<PublicLeafNode>,
13 pub(crate) total_value: u64,
14}
15
16#[async_trait]
17pub(crate) trait LeavesInternalHandlers<S: SparkSigner + Send + Sync> {
18 fn get_btc_value(
19 &self,
20 filter_cb: Option<Box<dyn Fn(&PublicLeafNode) -> bool>>,
21 ) -> Result<u64, SparkSdkError>;
22
23 fn query_single_node(
24 &self,
25 cb: Option<Box<dyn Fn(&LeafNode) -> bool>>,
26 new_status: Option<LeafNodeStatus>,
27 ) -> Result<PublicLeafNode, SparkSdkError>;
28
29 fn get_node_with_id(&self, leaf_id: &String) -> Result<PublicLeafNode, SparkSdkError>;
30
31 async fn prepare_leaves_for_amount(
32 &self,
33 amount: u64,
34 token_pubkey: Option<&Vec<u8>>,
35 new_status: LeafNodeStatus,
36 ) -> Result<LeafSelectionResponse, SparkSdkError>;
37
38 async fn verify_and_get_leaves(
39 &self,
40 leaf_ids: Vec<String>,
41 new_status: LeafNodeStatus,
42 ) -> Result<LeafSelectionResponse, SparkSdkError>;
43
44 async fn select_leaf_to_split(
45 &self,
46 target_value: u64,
47 ) -> Result<PublicLeafNode, SparkSdkError>;
48
49 async fn fetch_owned_leaves_from_spark(&self) -> Result<(), SparkSdkError>;
50}