From 4e97f3ce8d19f9f6cd7f21ce876768e468884e2e Mon Sep 17 00:00:00 2001 From: yancy Date: Mon, 18 Mar 2024 11:30:00 +0100 Subject: [PATCH] wip --- src/lib.rs | 25 +++++++++++++++++-------- src/single_random_draw.rs | 8 ++++---- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 9e4afd79..ea101a87 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -16,7 +16,7 @@ #[cfg(bench)] extern crate test; -mod branch_and_bound; +//mod branch_and_bound; mod single_random_draw; use bitcoin::Amount; @@ -40,6 +40,16 @@ pub trait Utxo: Clone { // https://github.com/bitcoin/bitcoin/blob/f722a9bd132222d9d5cd503b5af25c905b205cdb/src/wallet/coinselection.h#L20 const CHANGE_LOWER: Amount = Amount::from_sat(50_000); +/// TODO +pub struct Coin { + /// TODO + pub utxo: TxOut, + /// TODO + pub effective_value: Amount, + /// TODO + pub waste: SignedAmount +} + /// This struct contains the weight of all params needed to satisfy the UTXO. /// /// The idea of using a WeightUtxo type was inspired by the BDK implementation: @@ -86,13 +96,12 @@ pub fn select_coins( weighted_utxos: &[WeightedUtxo], ) -> Option> { { - let bnb = - select_coins_bnb(target, cost_of_change, fee_rate, long_term_fee_rate, weighted_utxos); + select_coins_bnb(target, cost_of_change, fee_rate, long_term_fee_rate, weighted_utxos) - if bnb.is_some() { - bnb - } else { - select_coins_srd(target, fee_rate, weighted_utxos, &mut thread_rng()) - } + //if bnb.is_some() { + //bnb + //} else { + //select_coins_srd(target, fee_rate, weighted_utxos, &mut thread_rng()) + //} } } diff --git a/src/single_random_draw.rs b/src/single_random_draw.rs index b7f57063..2311b703 100644 --- a/src/single_random_draw.rs +++ b/src/single_random_draw.rs @@ -1,7 +1,7 @@ //! This library provides efficient algorithms to compose a set of unspent transaction outputs //! (UTXOs). -use crate::WeightedUtxo; +use crate::Coin; use crate::CHANGE_LOWER; use bitcoin::blockdata::transaction::effective_value; use bitcoin::Amount; @@ -31,10 +31,10 @@ use rand::seq::SliceRandom; pub fn select_coins_srd<'a, R: rand::Rng + ?Sized>( target: Amount, fee_rate: FeeRate, - weighted_utxos: &'a [WeightedUtxo], + coin: &'a [Coin], rng: &mut R, -) -> Option> { - let mut origin: Vec<_> = weighted_utxos.iter().collect(); +) -> Option> { + let mut origin: Vec<_> = coin.iter().collect(); origin.shuffle(rng); let threshold = target + CHANGE_LOWER;