Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce new bdk_coin_select implementation #924

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Cargo.1.48.0.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[workspace]
members = [
"nursery/coin_select"
]
16 changes: 16 additions & 0 deletions build-msrv-crates.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env sh
trap '
signal=$?;
cleanup
exit $signal;
' INT

cleanup() {
mv Cargo.tmp.toml Cargo.toml 2>/dev/null
}

cp Cargo.toml Cargo.tmp.toml
cp Cargo.1.48.0.toml Cargo.toml
cat Cargo.toml
cargo build --release
cleanup
4 changes: 2 additions & 2 deletions example-crates/keychain_tracker_example_cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use bdk_chain::{
sparse_chain::{self, ChainPosition},
DescriptorExt, FullTxOut,
};
use bdk_coin_select::{coin_select_bnb, CoinSelector, CoinSelectorOpt, WeightedValue};
use bdk_coin_select::{coin_select_bnb, CoinSelector, CoinSelectorOpt, Candidate};
use bdk_file_store::KeychainStore;
use clap::{Parser, Subcommand};
use std::{
Expand Down Expand Up @@ -352,7 +352,7 @@ pub fn create_tx<P: ChainPosition>(
let wv_candidates = candidates
.iter()
.map(|(plan, utxo)| {
WeightedValue::new(
Candidate::new(
utxo.txout.value,
plan.expected_weight() as _,
plan.witness_version().is_some(),
Expand Down
12 changes: 9 additions & 3 deletions nursery/coin_select/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
[package]
name = "bdk_coin_select"
version = "0.0.1"
authors = [ "LLFourn <[email protected]>" ]
version = "0.1.0"
edition = "2018"
license = "MIT OR Apache-2.0"

[dependencies]
bdk_chain = { path = "../../crates/chain" }
# No dependencies! Don't add any please!

[dev-dependencies]
rand = "0.8"
proptest = "1"
bitcoin = "0.30"

[features]
default = ["std"]
Expand Down
59 changes: 59 additions & 0 deletions nursery/coin_select/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# BDK Coin Selection

`bdk_coin_select` is a tool to help you select inputs for making Bitcoin (ticker: BTC) transactions. It's got zero dependencies so you can pasta it into your project without concern.


## Synopsis

```rust
use bdk_coin_select::{CoinSelector, Candidate, TXIN_BASE_WEIGHT};
use bitcoin::{ Transaction, TxIn };

// You should use miniscript to figure out the satisfaction weight for your coins!
const tr_satisfaction_weight: u32 = 66;
const tr_input_weight: u32 = txin_base_weight + tr_satisfaction_weight;


let candidates = vec![
Candidate {
// How many inputs does this candidate represent. Needed so we can figure out the weight
// of the varint that encodes the number of inputs.
input_count: 1,
// the value of the input
value: 1_000_000,
// the total weight of the input(s). This doesn't include
weight: TR_INPUT_WEIGHT,
// wether it's a segwit input. Needed so we know whether to include the segwit header
// in total weight calculations.
is_segwit: true
},
Candidate {
// A candidate can represent multiple inputs in the case where you always want some inputs
// to be spent together.
input_count: 2,
weight: 2*tr_input_weight,
value: 3_000_000,
is_segwit: true
},
Candidate {
input_count: 1,
weight: TR_INPUT_WEIGHT,
value: 5_000_000,
is_segwit: true,
}
];

let base_weight = Transaction {
input: vec![],
output: vec![],
lock_time: bitcoin::absolute::LockTime::from_height(0).unwrap(),
version: 1,
}.weight().to_wu() as u32;

panic!("{}", base_weight);

let mut coin_selector = CoinSelector::new(&candidates,base_weight);


```

Loading