Merge pull request #566 from TheBlueMatt/2021-02-dust-value

Add Script:dust_value() to get minimum output value for a spk
This commit is contained in:
Sebastian 2021-02-07 11:45:17 +01:00 committed by GitHub
commit 5bd61967b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 20 additions and 0 deletions

View File

@ -400,6 +400,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() {
Self::WITNESS_OUTPUT_DUST_THRESHOLD
} else {
Self::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