diff --git a/taptrade-cli-demo/coordinator/src/wallet/wallet_utils.rs b/taptrade-cli-demo/coordinator/src/wallet/wallet_utils.rs index 0993247..b332390 100644 --- a/taptrade-cli-demo/coordinator/src/wallet/wallet_utils.rs +++ b/taptrade-cli-demo/coordinator/src/wallet/wallet_utils.rs @@ -1,3 +1,4 @@ +/// This module provides utility functions for working with wallets. use super::*; #[derive(Serialize, Deserialize, Debug)] pub struct PsbtInput { @@ -13,6 +14,16 @@ pub trait BondTx { } impl BondTx for Transaction { + /// Calculates the sum of input values for the transaction. + /// + /// # Arguments + /// + /// * `blockchain` - A reference to the blockchain. + /// * `db` - A reference to the database. + /// + /// # Returns + /// + /// The sum of input values as a `Result`. fn input_sum(&self, blockchain: &B, db: &D) -> Result { let mut input_sum = 0; @@ -39,7 +50,15 @@ impl BondTx for Transaction { } Ok(input_sum) } - + /// Calculates the sum of output values for the bond address. + /// + /// # Arguments + /// + /// * `bond_address` - The bond address as a string. + /// + /// # Returns + /// + /// The sum of output values as a `Result`. fn bond_output_sum(&self, bond_address: &str) -> Result { let bond_script = Address::from_str(bond_address)? .require_network(Network::Regtest)? @@ -52,13 +71,24 @@ impl BondTx for Transaction { } Err(anyhow!("No output to bond address in transaction")) } - + /// Calculates the sum of all output values for the transaction. + /// + /// # Returns + /// + /// The sum of all output values as a `u64`. fn all_output_sum(&self) -> u64 { self.output.iter().map(|output| output.value).sum() } } /// converts a csv string of bincode binary serialized, hex encoded bdk psbt inputs to a vector of PsbtInput +/// # Arguments +/// +/// * `inputs_csv_hex` - The CSV string of inputs as hex encoded strings. +/// +/// # Returns +/// +/// A vector of `PsbtInput` as a `Result>`. pub fn csv_hex_to_bdk_input(inputs_csv_hex: &str) -> Result> { let mut inputs: Vec = Vec::new(); for input_hex in inputs_csv_hex.split(',') {