Skip to content

Commit 49d6477

Browse files
committed
Merge #1763: Change coin_selection and DescriptorExt::dust_value to use Amount type
2a9eeed ci: pin msrv dep version for rustls (Steve Myers) 20789ec refactor(chain)!: use Amount for DescriptorExt::dust_value() (Steve Myers) 58a8435 refactor(coin_selection)!: use Amount and SignedAmount for API and internally (Steve Myers) Pull request description: ### Description refactor(coin_selection)!: use Amount and SignedAmount for API and internally refactor(chain)!: use Amount for DescriptorExt::dust_value() Using named types make the API and internal code easier to read and reason about since it makes it clear that the values are bitcoin amounts. Also to create these types the units (ie .from_sat()) must be specified. ### Notes to the reviewers For coin_selection using Amount and SignedAmount makes internal code safer against overflow errors. In particular because these types will panic if an amount overflow occurs. Using u64/i64 on the other hand can silently rollover. See: https://doc.rust-lang.org/book/ch03-02-data-types.html#integer-overflow This is a continuation of the work done in #1595. Since this is an API breaking change I would like to include it in the 1.0.0-beta milestone if possible. ### Changelog notice - Change coin_selection to use Amount instead of u64 for all bitcoin amounts. - Change DescriptorExt::dust_value() to return an Amount instead of u64. ### Checklists #### All Submissions: * [x] I've signed all my commits * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md) * [x] I ran `cargo fmt` and `cargo clippy` before committing #### Bugfixes: * [x] This pull request breaks the existing API * [ ] I've added tests to reproduce the issue which are now passing * [ ] I'm linking the issue being fixed by this PR ACKs for top commit: ValuedMammal: ACK 2a9eeed Tree-SHA512: 9dd1b31d0f8d3d8c383c7aae7ec0fffb55bfcfe49c804e273faa740d30efde7efb7c9504e87cceb56798ea14a3e34fc8a7b65a8ad5e52ea38b8523150c9b6bc2
2 parents 955593c + 2a9eeed commit 49d6477

File tree

7 files changed

+227
-192
lines changed

7 files changed

+227
-192
lines changed

.github/workflows/cont_integration.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ jobs:
5353
cargo update -p security-framework-sys --precise "2.11.1"
5454
cargo update -p csv --precise "1.3.0"
5555
cargo update -p unicode-width --precise "0.1.13"
56+
cargo update -p [email protected] --precise "0.23.19"
5657
- name: Build
5758
run: cargo build --workspace --exclude 'example_*' ${{ matrix.features }}
5859
- name: Test

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ cargo update -p indexmap --precise "2.5.0"
8080
cargo update -p security-framework-sys --precise "2.11.1"
8181
cargo update -p csv --precise "1.3.0"
8282
cargo update -p unicode-width --precise "0.1.13"
83+
cargo update -p [email protected] --precise "0.23.19"
8384
```
8485

8586
## License

crates/chain/src/descriptor_ext.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::miniscript::{Descriptor, DescriptorPublicKey};
22
use bitcoin::hashes::{hash_newtype, sha256, Hash};
3+
use bitcoin::Amount;
34

45
hash_newtype! {
56
/// Represents the unique ID of a descriptor.
@@ -13,22 +14,21 @@ hash_newtype! {
1314

1415
/// A trait to extend the functionality of a miniscript descriptor.
1516
pub trait DescriptorExt {
16-
/// Returns the minimum value (in satoshis) at which an output is broadcastable.
17+
/// Returns the minimum [`Amount`] at which an output is broadcast-able.
1718
/// Panics if the descriptor wildcard is hardened.
18-
fn dust_value(&self) -> u64;
19+
fn dust_value(&self) -> Amount;
1920

2021
/// Returns the descriptor ID, calculated as the sha256 hash of the spk derived from the
2122
/// descriptor at index 0.
2223
fn descriptor_id(&self) -> DescriptorId;
2324
}
2425

2526
impl DescriptorExt for Descriptor<DescriptorPublicKey> {
26-
fn dust_value(&self) -> u64 {
27+
fn dust_value(&self) -> Amount {
2728
self.at_derivation_index(0)
2829
.expect("descriptor can't have hardened derivation")
2930
.script_pubkey()
3031
.minimal_non_dust()
31-
.to_sat()
3232
}
3333

3434
fn descriptor_id(&self) -> DescriptorId {

0 commit comments

Comments
 (0)