@@ -411,11 +411,11 @@ impl Script {
411
411
412
412
/// Gets the minimum value an output with this script should have in order to be
413
413
/// broadcastable on today's bitcoin network.
414
- pub fn dust_value ( & self ) -> u64 {
414
+ pub fn dust_value ( & self ) -> :: Amount {
415
415
// This must never be lower than Bitcoin Core's GetDustThreshold() (as of v0.21) as it may
416
416
// otherwise allow users to create transactions which likely can never be
417
417
// broadcasted/confirmed.
418
- DUST_RELAY_TX_FEE as u64 / 1000 * // The default dust relay fee is 3000 satoshi/kB (ie 3 sat/vByte)
418
+ let sats = DUST_RELAY_TX_FEE as u64 / 1000 * // The default dust relay fee is 3000 satoshi/kB (ie 3 sat/vByte)
419
419
if self . is_op_return ( ) {
420
420
0
421
421
} else if self . is_witness_program ( ) {
@@ -426,7 +426,9 @@ impl Script {
426
426
32 + 4 + 1 + 107 + 4 + // The spend cost copied from Core
427
427
8 + // The serialized size of the TxOut's amount field
428
428
self . consensus_encode ( & mut :: std:: io:: sink ( ) ) . unwrap ( ) as u64 // The serialized size of this script_pubkey
429
- }
429
+ } ;
430
+
431
+ :: Amount :: from_sat ( sats)
430
432
}
431
433
432
434
/// Iterate over the script in the form of `Instruction`s, which are an enum covering
@@ -1262,7 +1264,7 @@ mod test {
1262
1264
// well-known scriptPubKey types.
1263
1265
let script_p2wpkh = Builder :: new ( ) . push_int ( 0 ) . push_slice ( & [ 42 ; 20 ] ) . into_script ( ) ;
1264
1266
assert ! ( script_p2wpkh. is_v0_p2wpkh( ) ) ;
1265
- assert_eq ! ( script_p2wpkh. dust_value( ) , 294 ) ;
1267
+ assert_eq ! ( script_p2wpkh. dust_value( ) , :: Amount :: from_sat ( 294 ) ) ;
1266
1268
1267
1269
let script_p2pkh = Builder :: new ( )
1268
1270
. push_opcode ( opcodes:: all:: OP_DUP )
@@ -1272,7 +1274,7 @@ mod test {
1272
1274
. push_opcode ( opcodes:: all:: OP_CHECKSIG )
1273
1275
. into_script ( ) ;
1274
1276
assert ! ( script_p2pkh. is_p2pkh( ) ) ;
1275
- assert_eq ! ( script_p2pkh. dust_value( ) , 546 ) ;
1277
+ assert_eq ! ( script_p2pkh. dust_value( ) , :: Amount :: from_sat ( 546 ) ) ;
1276
1278
}
1277
1279
}
1278
1280
0 commit comments