-
Notifications
You must be signed in to change notification settings - Fork 322
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Introduce new coin selection implementation * Add some tooling to make bdk_coin_select work on 1.48.0 * Update `example_cli` to use new `bdk_coin_select`
1 parent
feafaac
commit 4e51d18
Showing
18 changed files
with
2,129 additions
and
1,190 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[workspace] | ||
members = [ | ||
"nursery/coin_select" | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
|
||
``` | ||
|
Oops, something went wrong.