Skip to content

Commit

Permalink
Add Script:dust_value() to get minimum output value for a spk
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBlueMatt committed Feb 5, 2021
1 parent cf45a61 commit ad0d82d
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/blockdata/script.rs
Expand Up @@ -325,6 +325,26 @@ impl Script {
opcodes::All::from(self.0[0]).classify() == opcodes::Class::IllegalOp)
}

/// The minimum value an output to a witness script must have in order to be
/// broadcastable on today's bitcoin network.
pub const WITNESS_OUTPUT_DUST_THRESHOLD: u64 = 294;

/// The minimum value an output to a non-witness script must have in order to be
/// broadcastable on today's bitcoin network.
pub const LEGACY_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 {
if self.is_op_return() {
0
} else if self.is_witness_program() {
WITNESS_OUTPUT_DUST_THRESHOLD
} else {
LEGACY_OUTPUT_DUST_THRESHOLD
}
}

/// Iterate over the script in the form of `Instruction`s, which are an enum covering
/// opcodes, datapushes and errors. At most one error will be returned and then the
/// iterator will end. To instead iterate over the script as sequence of bytes, treat
Expand Down

0 comments on commit ad0d82d

Please sign in to comment.