mirror of
https://github.com/RoboSats/taptrade-core.git
synced 2025-07-18 08:43:17 +00:00
added docs for wallet utils
This commit is contained in:
@ -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<u64>`.
|
||||
fn input_sum<D: Database, B: GetTx>(&self, blockchain: &B, db: &D) -> Result<u64> {
|
||||
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<u64>`.
|
||||
fn bond_output_sum(&self, bond_address: &str) -> Result<u64> {
|
||||
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<Vec<PsbtInput>>`.
|
||||
pub fn csv_hex_to_bdk_input(inputs_csv_hex: &str) -> Result<Vec<PsbtInput>> {
|
||||
let mut inputs: Vec<PsbtInput> = Vec::new();
|
||||
for input_hex in inputs_csv_hex.split(',') {
|
||||
|
Reference in New Issue
Block a user