Skip to content

Commit b136a4d

Browse files
committed
Merge rust-bitcoin/rust-bitcoin#794: Refactor use map_err
9f84847 Refactor use map_err (wim-web) Pull request description: issue: rust-bitcoin/rust-bitcoin#793 change to using map_err ACKs for top commit: Kixunil: ACK 9f84847 apoelstra: ACK 9f84847 Tree-SHA512: 93dac16463bf84825f764f3ef81833c27722a52f56737d30f14160d070959ad13bbfdf5f3c4871b961ce05fa9f75ed36acbacaa40ff6ba3bbf449b9c9173c0c7
2 parents aed84ce + f54bd60 commit b136a4d

File tree

1 file changed

+27
-20
lines changed

1 file changed

+27
-20
lines changed

src/util/psbt/serialize.rs

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -109,16 +109,21 @@ impl Deserialize for EcdsaSig {
109109
// also has a field sighash_u32 (See BIP141). For example, when signing with non-standard
110110
// 0x05, the sighash message would have the last field as 0x05u32 while, the verification
111111
// would use check the signature assuming sighash_u32 as `0x01`.
112-
match EcdsaSig::from_slice(&bytes) {
113-
Ok(sig) => Ok(sig),
114-
Err(EcdsaSigError::EmptySignature) =>
115-
Err(encode::Error::ParseFailed("Empty partial signature data")),
116-
Err(EcdsaSigError::NonStandardSigHashType(flag)) =>
117-
Err(encode::Error::from(psbt::Error::NonStandardSigHashType(flag))),
118-
Err(EcdsaSigError::Secp256k1(..)) =>
119-
Err(encode::Error::ParseFailed("Invalid Ecdsa signature")),
120-
Err(EcdsaSigError::HexEncoding(..)) => unreachable!("Decoding from slice, not hex")
121-
}
112+
EcdsaSig::from_slice(&bytes)
113+
.map_err(|e| match e {
114+
EcdsaSigError::EmptySignature => {
115+
encode::Error::ParseFailed("Empty partial signature data")
116+
}
117+
EcdsaSigError::NonStandardSigHashType(flag) => {
118+
encode::Error::from(psbt::Error::NonStandardSigHashType(flag))
119+
}
120+
EcdsaSigError::Secp256k1(..) => {
121+
encode::Error::ParseFailed("Invalid Ecdsa signature")
122+
}
123+
EcdsaSigError::HexEncoding(..) => {
124+
unreachable!("Decoding from slice, not hex")
125+
}
126+
})
122127
}
123128
}
124129

@@ -205,16 +210,18 @@ impl Serialize for schnorr::SchnorrSig {
205210

206211
impl Deserialize for schnorr::SchnorrSig {
207212
fn deserialize(bytes: &[u8]) -> Result<Self, encode::Error> {
208-
match schnorr::SchnorrSig::from_slice(&bytes) {
209-
Ok(sig) => Ok(sig),
210-
Err(schnorr::SchnorrSigError::InvalidSighashType(flag)) => {
211-
Err(encode::Error::from(psbt::Error::NonStandardSigHashType(flag as u32)))
212-
}
213-
Err(schnorr::SchnorrSigError::InvalidSchnorrSigSize(_)) =>
214-
Err(encode::Error::ParseFailed("Invalid Schnorr signature length")),
215-
Err(schnorr::SchnorrSigError::Secp256k1(..)) =>
216-
Err(encode::Error::ParseFailed("Invalid Schnorr signature")),
217-
}
213+
schnorr::SchnorrSig::from_slice(&bytes)
214+
.map_err(|e| match e {
215+
schnorr::SchnorrSigError::InvalidSighashType(flag) => {
216+
encode::Error::from(psbt::Error::NonStandardSigHashType(flag as u32))
217+
}
218+
schnorr::SchnorrSigError::InvalidSchnorrSigSize(_) => {
219+
encode::Error::ParseFailed("Invalid Schnorr signature length")
220+
}
221+
schnorr::SchnorrSigError::Secp256k1(..) => {
222+
encode::Error::ParseFailed("Invalid Schnorr signature")
223+
}
224+
})
218225
}
219226
}
220227

0 commit comments

Comments
 (0)