]> Untitled Git - bdk/commitdiff
refactor(chain)!: use Amount for DescriptorExt::dust_value()
authorSteve Myers <steve@notmandatory.org>
Sun, 8 Dec 2024 02:24:35 +0000 (20:24 -0600)
committerSteve Myers <steve@notmandatory.org>
Wed, 11 Dec 2024 21:02:46 +0000 (15:02 -0600)
crates/chain/src/descriptor_ext.rs
example-crates/example_cli/src/lib.rs

index eac01a684d4d29135378248aadd590846575a472..9cf147582dec5598370710ebe943e6c4671e36ca 100644 (file)
@@ -1,5 +1,6 @@
 use crate::miniscript::{Descriptor, DescriptorPublicKey};
 use bitcoin::hashes::{hash_newtype, sha256, Hash};
+use bitcoin::Amount;
 
 hash_newtype! {
     /// Represents the unique ID of a descriptor.
@@ -13,9 +14,9 @@ hash_newtype! {
 
 /// A trait to extend the functionality of a miniscript descriptor.
 pub trait DescriptorExt {
-    /// Returns the minimum value (in satoshis) at which an output is broadcastable.
+    /// Returns the minimum [`Amount`] at which an output is broadcast-able.
     /// Panics if the descriptor wildcard is hardened.
-    fn dust_value(&self) -> u64;
+    fn dust_value(&self) -> Amount;
 
     /// Returns the descriptor ID, calculated as the sha256 hash of the spk derived from the
     /// descriptor at index 0.
@@ -23,12 +24,11 @@ pub trait DescriptorExt {
 }
 
 impl DescriptorExt for Descriptor<DescriptorPublicKey> {
-    fn dust_value(&self) -> u64 {
+    fn dust_value(&self) -> Amount {
         self.at_derivation_index(0)
             .expect("descriptor can't have hardened derivation")
             .script_pubkey()
             .minimal_non_dust()
-            .to_sat()
     }
 
     fn descriptor_id(&self) -> DescriptorId {
index 8c17348b39277f254cddcb9d05766cdb74540194..3a700db3a120a8e46f542778d1618027b86cbc1e 100644 (file)
@@ -324,7 +324,7 @@ where
         .expect("must exist")
         .1;
 
-    let min_drain_value = change_desc.dust_value();
+    let min_drain_value = change_desc.dust_value().to_sat();
 
     let target = Target {
         outputs: TargetOutputs::fund_outputs(