Skip to content

Commit

Permalink
refactor(chain)!: use Amount for DescriptorExt::dust_value()
Browse files Browse the repository at this point in the history
  • Loading branch information
notmandatory committed Dec 11, 2024
1 parent 58a8435 commit 20789ec
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions crates/chain/src/descriptor_ext.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -13,22 +14,21 @@ 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.
fn descriptor_id(&self) -> DescriptorId;
}

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 {
Expand Down
2 changes: 1 addition & 1 deletion example-crates/example_cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 20789ec

Please sign in to comment.