File tree Expand file tree Collapse file tree 15 files changed +59
-198
lines changed Expand file tree Collapse file tree 15 files changed +59
-198
lines changed Original file line number Diff line number Diff line change @@ -396,27 +396,15 @@ impl SegwitBitcoinAddress {
396
396
}
397
397
398
398
pub fn is_p2wpkh ( & self ) -> bool {
399
- if let SegwitBitcoinAddress :: P2WPKH ( ..) = self {
400
- true
401
- } else {
402
- false
403
- }
399
+ matches ! ( self , SegwitBitcoinAddress :: P2WPKH ( ..) )
404
400
}
405
401
406
402
pub fn is_p2wsh ( & self ) -> bool {
407
- if let SegwitBitcoinAddress :: P2WSH ( ..) = self {
408
- true
409
- } else {
410
- false
411
- }
403
+ matches ! ( self , SegwitBitcoinAddress :: P2WSH ( ..) )
412
404
}
413
405
414
406
pub fn is_p2tr ( & self ) -> bool {
415
- if let SegwitBitcoinAddress :: P2TR ( ..) = self {
416
- true
417
- } else {
418
- false
419
- }
407
+ matches ! ( self , SegwitBitcoinAddress :: P2TR ( ..) )
420
408
}
421
409
}
422
410
Original file line number Diff line number Diff line change @@ -150,10 +150,10 @@ impl BurnchainParameters {
150
150
}
151
151
152
152
pub fn is_testnet ( network_id : u32 ) -> bool {
153
- match network_id {
154
- BITCOIN_NETWORK_ID_TESTNET | BITCOIN_NETWORK_ID_REGTEST => true ,
155
- _ => false ,
156
- }
153
+ matches ! (
154
+ network_id ,
155
+ BITCOIN_NETWORK_ID_TESTNET | BITCOIN_NETWORK_ID_REGTEST
156
+ )
157
157
}
158
158
}
159
159
Original file line number Diff line number Diff line change @@ -457,10 +457,7 @@ mod tests {
457
457
& sender,
458
458
)
459
459
. unwrap_err ( ) ;
460
- assert ! ( match err {
461
- op_error:: ParseError => true ,
462
- _ => false ,
463
- } ) ;
460
+ assert ! ( matches!( err, op_error:: ParseError ) ) ;
464
461
465
462
// Data is length 17. The 16th byte is set to 1, which signals that until_burn_height
466
463
// is Some(u64), so the deserialize function expects another 8 bytes
@@ -496,10 +493,7 @@ mod tests {
496
493
& sender,
497
494
)
498
495
. unwrap_err ( ) ;
499
- assert ! ( match err {
500
- op_error:: ParseError => true ,
501
- _ => false ,
502
- } ) ;
496
+ assert ! ( matches!( err, op_error:: ParseError ) ) ;
503
497
}
504
498
505
499
// This test sets the op code to the op code of the StackStx
@@ -540,10 +534,7 @@ mod tests {
540
534
)
541
535
. unwrap_err ( ) ;
542
536
543
- assert ! ( match err {
544
- op_error:: InvalidInput => true ,
545
- _ => false ,
546
- } ) ;
537
+ assert ! ( matches!( err, op_error:: InvalidInput ) ) ;
547
538
}
548
539
549
540
// This test constructs a tx with zero outputs, which causes
@@ -576,10 +567,7 @@ mod tests {
576
567
)
577
568
. unwrap_err ( ) ;
578
569
579
- assert ! ( match err {
580
- op_error:: InvalidInput => true ,
581
- _ => false ,
582
- } ) ;
570
+ assert ! ( matches!( err, op_error:: InvalidInput ) ) ;
583
571
}
584
572
585
573
// Parse a normal DelegateStx op in which the reward_addr is set to output index 2.
Original file line number Diff line number Diff line change @@ -1280,11 +1280,7 @@ mod tests {
1280
1280
)
1281
1281
. unwrap_err ( ) ;
1282
1282
1283
- assert ! ( if let op_error:: BlockCommitBadOutputs = err {
1284
- true
1285
- } else {
1286
- false
1287
- } ) ;
1283
+ assert ! ( matches!( err, op_error:: BlockCommitBadOutputs ) ) ;
1288
1284
1289
1285
// should succeed in epoch 2.1 -- can be PoX in 2.1
1290
1286
let _op = LeaderBlockCommitOp :: parse_from_tx (
Original file line number Diff line number Diff line change @@ -1256,17 +1256,11 @@ impl TransactionAuth {
1256
1256
}
1257
1257
1258
1258
pub fn is_standard ( & self ) -> bool {
1259
- match * self {
1260
- TransactionAuth :: Standard ( _) => true ,
1261
- _ => false ,
1262
- }
1259
+ matches ! ( self , TransactionAuth :: Standard ( _) )
1263
1260
}
1264
1261
1265
1262
pub fn is_sponsored ( & self ) -> bool {
1266
- match * self {
1267
- TransactionAuth :: Sponsored ( _, _) => true ,
1268
- _ => false ,
1269
- }
1263
+ matches ! ( self , TransactionAuth :: Sponsored ( ..) )
1270
1264
}
1271
1265
1272
1266
/// When beginning to sign a sponsored transaction, the origin account will not commit to any
Original file line number Diff line number Diff line change @@ -1240,38 +1240,23 @@ macro_rules! with_node {
1240
1240
1241
1241
impl TrieNodeType {
1242
1242
pub fn is_leaf ( & self ) -> bool {
1243
- match self {
1244
- TrieNodeType :: Leaf ( _) => true ,
1245
- _ => false ,
1246
- }
1243
+ matches ! ( self , TrieNodeType :: Leaf ( _) )
1247
1244
}
1248
1245
1249
1246
pub fn is_node4 ( & self ) -> bool {
1250
- match self {
1251
- TrieNodeType :: Node4 ( _) => true ,
1252
- _ => false ,
1253
- }
1247
+ matches ! ( self , TrieNodeType :: Node4 ( _) )
1254
1248
}
1255
1249
1256
1250
pub fn is_node16 ( & self ) -> bool {
1257
- match self {
1258
- TrieNodeType :: Node16 ( _) => true ,
1259
- _ => false ,
1260
- }
1251
+ matches ! ( self , TrieNodeType :: Node16 ( _) )
1261
1252
}
1262
1253
1263
1254
pub fn is_node48 ( & self ) -> bool {
1264
- match self {
1265
- TrieNodeType :: Node48 ( _) => true ,
1266
- _ => false ,
1267
- }
1255
+ matches ! ( self , TrieNodeType :: Node48 ( _) )
1268
1256
}
1269
1257
1270
1258
pub fn is_node256 ( & self ) -> bool {
1271
- match self {
1272
- TrieNodeType :: Node256 ( _) => true ,
1273
- _ => false ,
1274
- }
1259
+ matches ! ( self , TrieNodeType :: Node256 ( _) )
1275
1260
}
1276
1261
1277
1262
pub fn id ( & self ) -> u8 {
Original file line number Diff line number Diff line change @@ -551,10 +551,7 @@ impl TransactionResult {
551
551
552
552
/// Returns true iff this enum is backed by `TransactionSuccess`.
553
553
pub fn is_ok ( & self ) -> bool {
554
- match & self {
555
- TransactionResult :: Success ( _) => true ,
556
- _ => false ,
557
- }
554
+ matches ! ( self , TransactionResult :: Success ( _) )
558
555
}
559
556
560
557
/// Returns a TransactionSuccess result as a pair of 1) fee and 2) receipt.
@@ -568,10 +565,7 @@ impl TransactionResult {
568
565
569
566
/// Returns true iff this enum is backed by `Error`.
570
567
pub fn is_err ( & self ) -> bool {
571
- match & self {
572
- TransactionResult :: ProcessingError ( _) => true ,
573
- _ => false ,
574
- }
568
+ matches ! ( self , TransactionResult :: ProcessingError ( _) )
575
569
}
576
570
577
571
/// Returns an Error result as an Error.
Original file line number Diff line number Diff line change @@ -461,17 +461,11 @@ pub enum TransactionAuthField {
461
461
462
462
impl TransactionAuthField {
463
463
pub fn is_public_key ( & self ) -> bool {
464
- match * self {
465
- TransactionAuthField :: PublicKey ( _) => true ,
466
- _ => false ,
467
- }
464
+ matches ! ( self , TransactionAuthField :: PublicKey ( _) )
468
465
}
469
466
470
467
pub fn is_signature ( & self ) -> bool {
471
- match * self {
472
- TransactionAuthField :: Signature ( _, _) => true ,
473
- _ => false ,
474
- }
468
+ matches ! ( self , TransactionAuthField :: Signature ( ..) )
475
469
}
476
470
477
471
pub fn as_public_key ( & self ) -> Option < StacksPublicKey > {
Original file line number Diff line number Diff line change @@ -1277,20 +1277,14 @@ fn test_build_anchored_blocks_incrementing_nonces() {
1277
1277
// because the tx fee for each transaction increases with the nonce
1278
1278
for ( i, tx) in stacks_block. txs . iter ( ) . enumerate ( ) {
1279
1279
if i == 0 {
1280
- let okay = if let TransactionPayload :: Coinbase ( ..) = tx. payload {
1281
- true
1282
- } else {
1283
- false
1284
- } ;
1280
+ let okay = matches ! ( tx. payload, TransactionPayload :: Coinbase ( ..) ) ;
1285
1281
assert ! ( okay, "Coinbase should be first tx" ) ;
1286
1282
} else {
1287
1283
let expected_nonce = ( i - 1 ) % 25 ;
1288
1284
assert_eq ! (
1289
1285
tx. get_origin_nonce( ) ,
1290
1286
expected_nonce as u64 ,
1291
- "{}th transaction should have nonce = {}" ,
1292
- i,
1293
- expected_nonce
1287
+ "{i}th transaction should have nonce = {expected_nonce}" ,
1294
1288
) ;
1295
1289
}
1296
1290
}
Original file line number Diff line number Diff line change @@ -1030,10 +1030,7 @@ impl StacksTransaction {
1030
1030
1031
1031
/// Is this a mainnet transaction? false means 'testnet'
1032
1032
pub fn is_mainnet ( & self ) -> bool {
1033
- match self . version {
1034
- TransactionVersion :: Mainnet => true ,
1035
- _ => false ,
1036
- }
1033
+ self . version == TransactionVersion :: Mainnet
1037
1034
}
1038
1035
1039
1036
/// Is this a phantom transaction?
@@ -3993,10 +3990,10 @@ mod test {
3993
3990
TransactionAuth :: Standard ( origin) => origin,
3994
3991
TransactionAuth :: Sponsored ( _, sponsor) => sponsor,
3995
3992
} ;
3996
- match spending_condition {
3997
- TransactionSpendingCondition :: OrderIndependentMultisig ( .. ) => true ,
3998
- _ => false ,
3999
- }
3993
+ matches ! (
3994
+ spending_condition ,
3995
+ TransactionSpendingCondition :: OrderIndependentMultisig ( .. )
3996
+ )
4000
3997
}
4001
3998
4002
3999
fn check_oversign_origin_multisig ( signed_tx : & StacksTransaction ) {
You can’t perform that action at this time.
0 commit comments