@@ -45,7 +45,7 @@ pub(crate) fn maybe_add_change_output(tx: &mut Transaction, input_value: Amount,
45
45
if output_value >= input_value { return Err ( ( ) ) ; }
46
46
}
47
47
48
- let dust_value = change_destination_script. dust_value ( ) ;
48
+ let dust_value = change_destination_script. minimal_non_dust ( ) ;
49
49
let mut change_output = TxOut {
50
50
script_pubkey : change_destination_script,
51
51
value : Amount :: ZERO ,
@@ -227,27 +227,27 @@ mod tests {
227
227
fn test_tx_change_edge ( ) {
228
228
// Check that we never add dust outputs
229
229
let mut tx = Transaction { version : Version :: TWO , lock_time : LockTime :: ZERO , input : Vec :: new ( ) , output : Vec :: new ( ) } ;
230
- let orig_wtxid = tx. wtxid ( ) ;
230
+ let orig_wtxid = tx. compute_wtxid ( ) ;
231
231
let output_spk = ScriptBuf :: new_p2pkh ( & PubkeyHash :: hash ( & [ 0 ; 0 ] ) ) ;
232
- assert_eq ! ( output_spk. dust_value ( ) . to_sat( ) , 546 ) ;
232
+ assert_eq ! ( output_spk. minimal_non_dust ( ) . to_sat( ) , 546 ) ;
233
233
// base size = version size + varint[input count] + input size + varint[output count] + output size + lock time size
234
234
// total size = version size + marker + flag + varint[input count] + input size + varint[output count] + output size + lock time size
235
235
// weight = 3 * base size + total size = 3 * (4 + 1 + 0 + 1 + 0 + 4) + (4 + 1 + 1 + 1 + 0 + 1 + 0 + 4) = 3 * 10 + 12 = 42
236
236
assert_eq ! ( tx. weight( ) . to_wu( ) , 42 ) ;
237
237
// 10 sats isn't enough to pay fee on a dummy transaction...
238
238
assert ! ( maybe_add_change_output( & mut tx, Amount :: from_sat( 10 ) , 0 , 250 , output_spk. clone( ) ) . is_err( ) ) ;
239
- assert_eq ! ( tx. wtxid ( ) , orig_wtxid) ; // Failure doesn't change the transaction
239
+ assert_eq ! ( tx. compute_wtxid ( ) , orig_wtxid) ; // Failure doesn't change the transaction
240
240
// but 11 (= ceil(42 * 250 / 1000)) is, just not enough to add a change output...
241
241
assert ! ( maybe_add_change_output( & mut tx, Amount :: from_sat( 11 ) , 0 , 250 , output_spk. clone( ) ) . is_ok( ) ) ;
242
242
assert_eq ! ( tx. output. len( ) , 0 ) ;
243
- assert_eq ! ( tx. wtxid ( ) , orig_wtxid) ; // If we don't add an output, we don't change the transaction
243
+ assert_eq ! ( tx. compute_wtxid ( ) , orig_wtxid) ; // If we don't add an output, we don't change the transaction
244
244
assert ! ( maybe_add_change_output( & mut tx, Amount :: from_sat( 549 ) , 0 , 250 , output_spk. clone( ) ) . is_ok( ) ) ;
245
245
assert_eq ! ( tx. output. len( ) , 0 ) ;
246
- assert_eq ! ( tx. wtxid ( ) , orig_wtxid) ; // If we don't add an output, we don't change the transaction
246
+ assert_eq ! ( tx. compute_wtxid ( ) , orig_wtxid) ; // If we don't add an output, we don't change the transaction
247
247
// 590 is also not enough
248
248
assert ! ( maybe_add_change_output( & mut tx, Amount :: from_sat( 590 ) , 0 , 250 , output_spk. clone( ) ) . is_ok( ) ) ;
249
249
assert_eq ! ( tx. output. len( ) , 0 ) ;
250
- assert_eq ! ( tx. wtxid ( ) , orig_wtxid) ; // If we don't add an output, we don't change the transaction
250
+ assert_eq ! ( tx. compute_wtxid ( ) , orig_wtxid) ; // If we don't add an output, we don't change the transaction
251
251
// at 591 we can afford the change output at the dust limit (546)
252
252
assert ! ( maybe_add_change_output( & mut tx, Amount :: from_sat( 591 ) , 0 , 250 , output_spk. clone( ) ) . is_ok( ) ) ;
253
253
assert_eq ! ( tx. output. len( ) , 1 ) ;
@@ -256,7 +256,7 @@ mod tests {
256
256
assert_eq ! ( tx. weight( ) . to_wu( ) / 4 , 590 -546 ) ; // New weight is exactly the fee we wanted.
257
257
258
258
tx. output . pop ( ) ;
259
- assert_eq ! ( tx. wtxid ( ) , orig_wtxid) ; // The only change is the addition of one output.
259
+ assert_eq ! ( tx. compute_wtxid ( ) , orig_wtxid) ; // The only change is the addition of one output.
260
260
}
261
261
262
262
#[ test]
@@ -267,28 +267,28 @@ mod tests {
267
267
} ] , output : vec ! [ TxOut {
268
268
script_pubkey: Builder :: new( ) . push_int( 1 ) . into_script( ) , value: Amount :: from_sat( 1000 )
269
269
} ] } ;
270
- let orig_wtxid = tx. wtxid ( ) ;
270
+ let orig_wtxid = tx. compute_wtxid ( ) ;
271
271
let orig_weight = tx. weight ( ) . to_wu ( ) ;
272
272
assert_eq ! ( orig_weight / 4 , 61 ) ;
273
273
274
- assert_eq ! ( Builder :: new( ) . push_int( 2 ) . into_script( ) . dust_value ( ) . to_sat( ) , 474 ) ;
274
+ assert_eq ! ( Builder :: new( ) . push_int( 2 ) . into_script( ) . minimal_non_dust ( ) . to_sat( ) , 474 ) ;
275
275
276
276
// Input value of the output value + fee - 1 should fail:
277
277
assert ! ( maybe_add_change_output( & mut tx, Amount :: from_sat( 1000 + 61 + 100 - 1 ) , 400 , 250 , Builder :: new( ) . push_int( 2 ) . into_script( ) ) . is_err( ) ) ;
278
- assert_eq ! ( tx. wtxid ( ) , orig_wtxid) ; // Failure doesn't change the transaction
278
+ assert_eq ! ( tx. compute_wtxid ( ) , orig_wtxid) ; // Failure doesn't change the transaction
279
279
// but one more input sat should succeed, without changing the transaction
280
280
assert ! ( maybe_add_change_output( & mut tx, Amount :: from_sat( 1000 + 61 + 100 ) , 400 , 250 , Builder :: new( ) . push_int( 2 ) . into_script( ) ) . is_ok( ) ) ;
281
- assert_eq ! ( tx. wtxid ( ) , orig_wtxid) ; // If we don't add an output, we don't change the transaction
281
+ assert_eq ! ( tx. compute_wtxid ( ) , orig_wtxid) ; // If we don't add an output, we don't change the transaction
282
282
// In order to get a change output, we need to add 474 plus the output's weight / 4 (10)...
283
283
assert ! ( maybe_add_change_output( & mut tx, Amount :: from_sat( 1000 + 61 + 100 + 474 + 9 ) , 400 , 250 , Builder :: new( ) . push_int( 2 ) . into_script( ) ) . is_ok( ) ) ;
284
- assert_eq ! ( tx. wtxid ( ) , orig_wtxid) ; // If we don't add an output, we don't change the transaction
284
+ assert_eq ! ( tx. compute_wtxid ( ) , orig_wtxid) ; // If we don't add an output, we don't change the transaction
285
285
286
286
assert ! ( maybe_add_change_output( & mut tx, Amount :: from_sat( 1000 + 61 + 100 + 474 + 10 ) , 400 , 250 , Builder :: new( ) . push_int( 2 ) . into_script( ) ) . is_ok( ) ) ;
287
287
assert_eq ! ( tx. output. len( ) , 2 ) ;
288
288
assert_eq ! ( tx. output[ 1 ] . value. to_sat( ) , 474 ) ;
289
289
assert_eq ! ( tx. output[ 1 ] . script_pubkey, Builder :: new( ) . push_int( 2 ) . into_script( ) ) ;
290
290
assert_eq ! ( tx. weight( ) . to_wu( ) - orig_weight, 40 ) ; // Weight difference matches what we had to add above
291
291
tx. output . pop ( ) ;
292
- assert_eq ! ( tx. wtxid ( ) , orig_wtxid) ; // The only change is the addition of one output.
292
+ assert_eq ! ( tx. compute_wtxid ( ) , orig_wtxid) ; // The only change is the addition of one output.
293
293
}
294
294
}
0 commit comments