Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
yancyribbens committed Mar 18, 2024
1 parent cbdb656 commit 4e97f3c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
25 changes: 17 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#[cfg(bench)]
extern crate test;

mod branch_and_bound;
//mod branch_and_bound;
mod single_random_draw;

use bitcoin::Amount;
Expand All @@ -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:
Expand Down Expand Up @@ -86,13 +96,12 @@ pub fn select_coins<T: Utxo>(
weighted_utxos: &[WeightedUtxo],
) -> Option<impl Iterator<Item = &WeightedUtxo>> {
{
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())
//}
}
}
8 changes: 4 additions & 4 deletions src/single_random_draw.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<std::vec::IntoIter<&'a WeightedUtxo>> {
let mut origin: Vec<_> = weighted_utxos.iter().collect();
) -> Option<std::vec::IntoIter<&'a Coin>> {
let mut origin: Vec<_> = coin.iter().collect();
origin.shuffle(rng);

let threshold = target + CHANGE_LOWER;
Expand Down

0 comments on commit 4e97f3c

Please sign in to comment.