From fc6f23fb9bc19ba0ea4bb2c285467e62ed54285b Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Wed, 5 May 2021 14:53:26 +0000 Subject: [PATCH] Drop not-very-useful output dust threshold constants It doesn't really make sense to have a constant for every common script type's dust limit, instead we should just use the `Script::dust_value()` function to have users calculate it. --- src/blockdata/script.rs | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/blockdata/script.rs b/src/blockdata/script.rs index 40e38ba0..36d2b321 100644 --- a/src/blockdata/script.rs +++ b/src/blockdata/script.rs @@ -400,14 +400,6 @@ impl Script { opcodes::All::from(self.0[0]).classify() == opcodes::Class::IllegalOp) } - /// The minimum value an output with a P2WPKH script_pubkey must have in order to be - /// broadcastable on today's bitcoin network. - pub const P2WPKH_OUTPUT_DUST_THRESHOLD: u64 = 294; - - /// The minimum value an output with a P2PKH script_pubkey must have in order to be - /// broadcastable on today's bitcoin network. - pub const P2PKH_OUTPUT_DUST_THRESHOLD: u64 = 546; - /// Gets the minimum value an output with this script should have in order to be /// broadcastable on today's bitcoin network. pub fn dust_value(&self) -> u64 { @@ -1240,9 +1232,12 @@ mod test { #[test] fn defult_dust_value_tests() { + // Check that our dust_value() calculator correctly calculates the dust limit on common + // well-known scriptPubKey types. let script_p2wpkh = Builder::new().push_int(0).push_slice(&[42; 20]).into_script(); assert!(script_p2wpkh.is_v0_p2wpkh()); - assert_eq!(script_p2wpkh.dust_value(), Script::P2WPKH_OUTPUT_DUST_THRESHOLD); + assert_eq!(script_p2wpkh.dust_value(), 294); + let script_p2pkh = Builder::new() .push_opcode(opcodes::all::OP_DUP) .push_opcode(opcodes::all::OP_HASH160) @@ -1251,7 +1246,7 @@ mod test { .push_opcode(opcodes::all::OP_CHECKSIG) .into_script(); assert!(script_p2pkh.is_p2pkh()); - assert_eq!(script_p2pkh.dust_value(), Script::P2PKH_OUTPUT_DUST_THRESHOLD); + assert_eq!(script_p2pkh.dust_value(), 546); } }