@@ -157,7 +157,7 @@ impl ConstructedTransaction {
157
157
weight. checked_add ( estimate_input_weight ( input. prev_output ( ) ) ) . unwrap_or ( Weight :: MAX )
158
158
} ) ;
159
159
let outputs_weight = self . outputs . iter ( ) . fold ( Weight :: from_wu ( 0 ) , |weight, output| {
160
- weight. checked_add ( get_output_weight ( & output. script_pubkey ( ) ) ) . unwrap_or ( Weight :: MAX )
160
+ weight. checked_add ( get_output_weight ( output. script_pubkey ( ) ) ) . unwrap_or ( Weight :: MAX )
161
161
} ) ;
162
162
Weight :: from_wu ( TX_COMMON_FIELDS_WEIGHT )
163
163
. checked_add ( inputs_weight)
@@ -297,7 +297,7 @@ impl NegotiationContext {
297
297
. iter ( )
298
298
. filter ( |( serial_id, _) | self . is_serial_id_valid_for_counterparty ( serial_id) )
299
299
. fold ( 0u64 , |weight, ( _, output) | {
300
- weight. saturating_add ( get_output_weight ( & output. script_pubkey ( ) ) . to_wu ( ) )
300
+ weight. saturating_add ( get_output_weight ( output. script_pubkey ( ) ) . to_wu ( ) )
301
301
} ) ,
302
302
)
303
303
}
@@ -508,7 +508,7 @@ impl NegotiationContext {
508
508
sequence : Sequence ( msg. sequence ) ,
509
509
..Default :: default ( )
510
510
} ;
511
- if !self . prevtx_outpoints . insert ( txin. previous_output . clone ( ) ) {
511
+ if !self . prevtx_outpoints . insert ( txin. previous_output ) {
512
512
// We have added an input that already exists
513
513
return Err ( AbortReason :: PrevTxOutInvalid ) ;
514
514
}
@@ -878,7 +878,7 @@ impl StateMachine {
878
878
}
879
879
880
880
#[ derive( Clone , Copy , Debug , Eq , PartialEq ) ]
881
- pub enum AddingRole {
881
+ enum AddingRole {
882
882
Local ,
883
883
Remote ,
884
884
}
@@ -892,7 +892,7 @@ pub struct LocalOrRemoteInput {
892
892
}
893
893
894
894
#[ derive( Clone , Debug , Eq , PartialEq ) ]
895
- pub enum InteractiveTxInput {
895
+ enum InteractiveTxInput {
896
896
Local ( LocalOrRemoteInput ) ,
897
897
Remote ( LocalOrRemoteInput ) ,
898
898
// TODO(splicing) SharedInput should be added
@@ -925,7 +925,7 @@ impl SharedOwnedOutput {
925
925
/// its ownership -- value fully owned by the adder or jointly
926
926
#[ derive( Clone , Debug , Eq , PartialEq ) ]
927
927
pub enum OutputOwned {
928
- /// Belongs to local node -- controlled exclusively and fully belonging to local node
928
+ /// Belongs to a single party -- controlled exclusively and fully belonging to a single party
929
929
Single ( TxOut ) ,
930
930
/// Output with shared control, but fully belonging to local node
931
931
SharedControlFullyOwned ( TxOut ) ,
@@ -979,7 +979,7 @@ impl OutputOwned {
979
979
}
980
980
981
981
#[ derive( Clone , Debug , Eq , PartialEq ) ]
982
- pub struct InteractiveTxOutput {
982
+ struct InteractiveTxOutput {
983
983
serial_id : SerialId ,
984
984
added_by : AddingRole ,
985
985
output : OutputOwned ,
@@ -1055,6 +1055,7 @@ pub(crate) struct InteractiveTxConstructor {
1055
1055
outputs_to_contribute : Vec < ( SerialId , OutputOwned ) > ,
1056
1056
}
1057
1057
1058
+ #[ allow( clippy:: enum_variant_names) ] // Clippy doesn't like the repeated `Tx` prefix here
1058
1059
pub ( crate ) enum InteractiveTxMessageSend {
1059
1060
TxAddInput ( msgs:: TxAddInput ) ,
1060
1061
TxAddOutput ( msgs:: TxAddOutput ) ,
@@ -1126,7 +1127,7 @@ impl InteractiveTxConstructor {
1126
1127
} ,
1127
1128
OutputOwned :: Shared ( output) => {
1128
1129
// Sanity check
1129
- if output. local_owned > output. tx_out . value . to_sat ( ) {
1130
+ if output. local_owned >= output. tx_out . value . to_sat ( ) {
1130
1131
return Err ( AbortReason :: InvalidLowFundingOutputValue ) ;
1131
1132
}
1132
1133
Some ( ( output. tx_out . script_pubkey . clone ( ) , output. local_owned ) )
@@ -1328,12 +1329,12 @@ mod tests {
1328
1329
fn get_secure_random_bytes ( & self ) -> [ u8 ; 32 ] {
1329
1330
let mut res = [ 0u8 ; 32 ] ;
1330
1331
let increment = self . 0 . get_increment ( ) ;
1331
- for i in 0 .. 32 {
1332
+ for ( i , byte ) in res . iter_mut ( ) . enumerate ( ) {
1332
1333
// Rotate the increment value by 'i' bits to the right, to avoid clashes
1333
1334
// when `generate_local_serial_id` does a parity flip on consecutive calls for the
1334
1335
// same party.
1335
1336
let rotated_increment = increment. rotate_right ( i as u32 ) ;
1336
- res [ i ] = ( rotated_increment & 0xff ) as u8 ;
1337
+ * byte = ( rotated_increment & 0xff ) as u8 ;
1337
1338
}
1338
1339
res
1339
1340
}
@@ -1402,7 +1403,7 @@ mod tests {
1402
1403
if shared_outputs_by_a. len ( ) > 1 {
1403
1404
println ! ( "Test warning: Expected at most one shared output. NodeA" ) ;
1404
1405
}
1405
- let shared_output_by_a = if shared_outputs_by_a. len ( ) >= 1 {
1406
+ let shared_output_by_a = if ! shared_outputs_by_a. is_empty ( ) {
1406
1407
Some ( shared_outputs_by_a[ 0 ] . value ( ) )
1407
1408
} else {
1408
1409
None
@@ -1412,7 +1413,7 @@ mod tests {
1412
1413
if shared_outputs_by_b. len ( ) > 1 {
1413
1414
println ! ( "Test warning: Expected at most one shared output. NodeB" ) ;
1414
1415
}
1415
- let shared_output_by_b = if shared_outputs_by_b. len ( ) >= 1 {
1416
+ let shared_output_by_b = if ! shared_outputs_by_b. is_empty ( ) {
1416
1417
Some ( shared_outputs_by_b[ 0 ] . value ( ) )
1417
1418
} else {
1418
1419
None
@@ -1424,23 +1425,19 @@ mod tests {
1424
1425
& session. a_expected_remote_shared_output
1425
1426
{
1426
1427
a_expected_remote_shared_output. 1
1428
+ } else if !shared_outputs_by_a. is_empty ( ) {
1429
+ shared_outputs_by_a[ 0 ] . local_value ( AddingRole :: Local )
1427
1430
} else {
1428
- if shared_outputs_by_a. len ( ) >= 1 {
1429
- shared_outputs_by_a[ 0 ] . local_value ( AddingRole :: Local )
1430
- } else {
1431
- 0
1432
- }
1431
+ 0
1433
1432
} ;
1434
1433
let expected_by_b = if let Some ( b_expected_remote_shared_output) =
1435
1434
& session. b_expected_remote_shared_output
1436
1435
{
1437
1436
b_expected_remote_shared_output. 1
1437
+ } else if !shared_outputs_by_b. is_empty ( ) {
1438
+ shared_outputs_by_b[ 0 ] . local_value ( AddingRole :: Local )
1438
1439
} else {
1439
- if shared_outputs_by_b. len ( ) >= 1 {
1440
- shared_outputs_by_b[ 0 ] . local_value ( AddingRole :: Local )
1441
- } else {
1442
- 0
1443
- }
1440
+ 0
1444
1441
} ;
1445
1442
1446
1443
let expected_sum = expected_by_a + expected_by_b;
@@ -1458,7 +1455,7 @@ mod tests {
1458
1455
true ,
1459
1456
tx_locktime,
1460
1457
session. inputs_a ,
1461
- session. outputs_a . iter ( ) . map ( |o| o . clone ( ) ) . collect ( ) ,
1458
+ session. outputs_a . to_vec ( ) ,
1462
1459
session. a_expected_remote_shared_output ,
1463
1460
) {
1464
1461
Ok ( r) => r,
@@ -1479,7 +1476,7 @@ mod tests {
1479
1476
false ,
1480
1477
tx_locktime,
1481
1478
session. inputs_b ,
1482
- session. outputs_b . iter ( ) . map ( |o| o . clone ( ) ) . collect ( ) ,
1479
+ session. outputs_b . to_vec ( ) ,
1483
1480
session. b_expected_remote_shared_output ,
1484
1481
) {
1485
1482
Ok ( r) => r,
@@ -1665,7 +1662,7 @@ mod tests {
1665
1662
}
1666
1663
1667
1664
fn generate_outputs ( outputs : & [ TestOutput ] ) -> Vec < OutputOwned > {
1668
- outputs. iter ( ) . map ( |o| generate_output_nonfunding_one ( o ) ) . collect ( )
1665
+ outputs. iter ( ) . map ( generate_output_nonfunding_one) . collect ( )
1669
1666
}
1670
1667
1671
1668
/// Generate a single output that is the funding output
0 commit comments