Skip to content

Commit 41cda57

Browse files
committed
clippy: fix map_unwrap_or lint
There is a `map_or` method that encapsulates the `.map().unwrap_or()` pattern. Use it to reduce the number of function calls the reader has to read.
1 parent b339010 commit 41cda57

2 files changed

Lines changed: 12 additions & 8 deletions

File tree

src/pset/map/input.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -479,8 +479,10 @@ impl Input {
479479
/// If the `sighash_type` field is set to a non-standard ECDSA sighash value.
480480
pub fn ecdsa_hash_ty(&self) -> Option<EcdsaSighashType> {
481481
self.sighash_type
482-
.map(|sighash_type| sighash_type.ecdsa_hash_ty())
483-
.unwrap_or(Some(EcdsaSighashType::All))
482+
.map_or(
483+
Some(EcdsaSighashType::All),
484+
|sighash_type| sighash_type.ecdsa_hash_ty(),
485+
)
484486
}
485487

486488
/// Obtains the [`SchnorrSighashType`] for this input if one is specified. If no sighash type is
@@ -491,8 +493,10 @@ impl Input {
491493
/// If the `sighash_type` field is set to a invalid Schnorr sighash value.
492494
pub fn schnorr_hash_ty(&self) -> Option<SchnorrSighashType> {
493495
self.sighash_type
494-
.map(|sighash_type| sighash_type.schnorr_hash_ty())
495-
.unwrap_or(Some(SchnorrSighashType::Default))
496+
.map_or(
497+
Some(SchnorrSighashType::Default),
498+
|sighash_type| sighash_type.schnorr_hash_ty(),
499+
)
496500
}
497501

498502
/// Create a psbt input from prevout

src/transaction.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -668,12 +668,12 @@ impl TxOutWitness {
668668

669669
/// The rangeproof len if is present, otherwise 0
670670
pub fn rangeproof_len(&self) -> usize {
671-
self.rangeproof.as_ref().map(|prf| prf.len()).unwrap_or(0)
671+
self.rangeproof.as_ref().map_or(0, |prf| prf.len())
672672
}
673673

674674
/// The surjection proof len if is present, otherwise 0
675675
pub fn surjectionproof_len(&self) -> usize {
676-
self.surjection_proof.as_ref().map(|prf| prf.len()).unwrap_or(0)
676+
self.surjection_proof.as_ref().map_or(0, |prf| prf.len())
677677
}
678678
}
679679

@@ -974,9 +974,9 @@ impl Transaction {
974974
}
975975
) + if witness_flag {
976976
let amt_prf_len = input.witness.amount_rangeproof.as_ref()
977-
.map(|x| x.len()).unwrap_or(0);
977+
.map_or(0, |x| x.len());
978978
let keys_prf_len = input.witness.inflation_keys_rangeproof.as_ref()
979-
.map(|x| x.len()).unwrap_or(0);
979+
.map_or(0, |x| x.len());
980980

981981
VarInt(amt_prf_len as u64).size() +
982982
amt_prf_len +

0 commit comments

Comments
 (0)