Skip to content

Commit

Permalink
Drop not-very-useful output dust threshold constants
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
TheBlueMatt committed May 5, 2021
1 parent 15981c9 commit fc6f23f
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions src/blockdata/script.rs
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand All @@ -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);
}
}

0 comments on commit fc6f23f

Please sign in to comment.