What changed, and why it matters
This commit is a large but purely cosmetic code cleanup in the Rust Bitcoin library. It removes wildcard imports of error types (like `use Error::*`) and replaces them with explicit `Self::Variant` or fully-qualified names. The behavior of the code does not change; it only makes the source code easier to read and maintain.
No security action required. Treat as a normal maintainability refactor. Reviewers can verify the diff contains only import/match-style changes and no behavioral modifications.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit refactors error-handling code across 21 files to eliminate wildcard imports of enum variants. Pattern matches in fmt::Display, std::error::Error::source, and constructor calls now use Self::Variant or EnumName::Variant instead of imported bare names. There are no functional changes, no new logic, no added bounds checks, and no changes to public APIs or serialization formats. The diff is entirely stylistic.
Changed components
bitcoin/src/address/error.rsbitcoin/src/bip152.rsbitcoin/src/bip158.rsbitcoin/src/bip32.rsbitcoin/src/blockdata/block.rsbitcoin/src/blockdata/script/mod.rsbitcoin/src/blockdata/script/witness_program.rsbitcoin/src/blockdata/script/witness_version.rsbitcoin/src/consensus/error.rsbitcoin/src/consensus_validation.rsbitcoin/src/crypto/ecdsa.rsbitcoin/src/crypto/key.rsbitcoin/src/crypto/sighash.rsbitcoin/src/crypto/taproot.rsbitcoin/src/merkle_tree/block.rsbitcoin/src/psbt/error.rsbitcoin/src/psbt/mod.rsbitcoin/src/psbt/serialize.rsbitcoin/src/sign_message.rsbitcoin/src/taproot/mod.rsunits/src/amount/tests.rsInspect captured patch +487 / −623
diff --git a/bitcoin/src/address/error.rs b/bitcoin/src/address/error.rs
index a0d5fd46..55620769 100644
--- a/bitcoin/src/address/error.rs
+++ b/bitcoin/src/address/error.rs
@@ -28,12 +28,12 @@ impl From<Infallible> for FromScriptError {
impl fmt::Display for FromScriptError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- use FromScriptError::*;
-
- match *self {
- WitnessVersion(ref e) => write_err!(f, "witness version construction error"; e),
- WitnessProgram(ref e) => write_err!(f, "witness program error"; e),
- UnrecognizedScript => write!(f, "script is not a p2pkh, p2sh or witness program"),
+ match self {
+ Self::WitnessVersion(ref e) =>
+ write_err!(f, "witness version construction error"; e),
+ Self::WitnessProgram(ref e) => write_err!(f, "witness program error"; e),
+ Self::UnrecognizedScript =>
+ write!(f, "script is not a p2pkh, p2sh or witness program"),
}
}
}
@@ -41,12 +41,10 @@ impl fmt::Display for FromScriptError {
#[cfg(feature = "std")]
impl std::error::Error for FromScriptError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
- use FromScriptError::*;
-
- match *self {
- UnrecognizedScript => None,
- WitnessVersion(ref e) => Some(e),
- WitnessProgram(ref e) => Some(e),
+ match self {
+ Self::UnrecognizedScript => None,
+ Self::WitnessVersion(ref e) => Some(e),
+ Self::WitnessProgram(ref e) => Some(e),
}
}
}
@@ -93,12 +91,10 @@ impl From<Infallible> for ParseError {
impl fmt::Display for ParseError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- use ParseError::*;
-
- match *self {
- Base58(ref e) => write_err!(f, "base58 error"; e),
- Bech32(ref e) => write_err!(f, "bech32 error"; e),
- NetworkValidation(ref e) => write_err!(f, "validation error"; e),
+ match self {
+ Self::Base58(ref e) => write_err!(f, "base58 error"; e),
+ Self::Bech32(ref e) => write_err!(f, "bech32 error"; e),
+ Self::NetworkValidation(ref e) => write_err!(f, "validation error"; e),
}
}
}
@@ -106,12 +102,10 @@ impl fmt::Display for ParseError {
#[cfg(feature = "std")]
impl std::error::Error for ParseError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
- use ParseError::*;
-
- match *self {
- Base58(ref e) => Some(e),
- Bech32(ref e) => Some(e),
- NetworkValidation(ref e) => Some(e),
+ match self {
+ Self::Base58(ref e) => Some(e),
+ Self::Bech32(ref e) => Some(e),
+ Self::NetworkValidation(ref e) => Some(e),
}
}
}
@@ -186,13 +180,12 @@ impl From<Infallible> for Bech32Error {
impl fmt::Display for Bech32Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- use Bech32Error::*;
-
- match *self {
- ParseBech32(ref e) => write_err!(f, "SegWit parsing error"; e),
- WitnessVersion(ref e) => write_err!(f, "witness version conversion/parsing error"; e),
- WitnessProgram(ref e) => write_err!(f, "witness program error"; e),
- UnknownHrp(ref e) => write_err!(f, "unknown hrp error"; e),
+ match self {
+ Self::ParseBech32(ref e) => write_err!(f, "SegWit parsing error"; e),
+ Self::WitnessVersion(ref e) =>
+ write_err!(f, "witness version conversion/parsing error"; e),
+ Self::WitnessProgram(ref e) => write_err!(f, "witness program error"; e),
+ Self::UnknownHrp(ref e) => write_err!(f, "unknown hrp error"; e),
}
}
}
@@ -200,13 +193,11 @@ impl fmt::Display for Bech32Error {
#[cfg(feature = "std")]
impl std::error::Error for Bech32Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
- use Bech32Error::*;
-
- match *self {
- ParseBech32(ref e) => Some(e),
- WitnessVersion(ref e) => Some(e),
- WitnessProgram(ref e) => Some(e),
- UnknownHrp(ref e) => Some(e),
+ match self {
+ Self::ParseBech32(ref e) => Some(e),
+ Self::WitnessVersion(ref e) => Some(e),
+ Self::WitnessProgram(ref e) => Some(e),
+ Self::UnknownHrp(ref e) => Some(e),
}
}
}
@@ -263,13 +254,13 @@ impl From<Infallible> for Base58Error {
impl fmt::Display for Base58Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- use Base58Error::*;
-
- match *self {
- ParseBase58(ref e) => write_err!(f, "legacy parsing error"; e),
- LegacyAddressTooLong(ref e) => write_err!(f, "legacy address length error"; e),
- InvalidBase58PayloadLength(ref e) => write_err!(f, "legacy payload length error"; e),
- InvalidLegacyPrefix(ref e) => write_err!(f, "legacy prefix error"; e),
+ match self {
+ Self::ParseBase58(ref e) => write_err!(f, "legacy parsing error"; e),
+ Self::LegacyAddressTooLong(ref e) =>
+ write_err!(f, "legacy address length error"; e),
+ Self::InvalidBase58PayloadLength(ref e) =>
+ write_err!(f, "legacy payload length error"; e),
+ Self::InvalidLegacyPrefix(ref e) => write_err!(f, "legacy prefix error"; e),
}
}
}
@@ -277,13 +268,11 @@ impl fmt::Display for Base58Error {
#[cfg(feature = "std")]
impl std::error::Error for Base58Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
- use Base58Error::*;
-
- match *self {
- ParseBase58(ref e) => Some(e),
- LegacyAddressTooLong(ref e) => Some(e),
- InvalidBase58PayloadLength(ref e) => Some(e),
- InvalidLegacyPrefix(ref e) => Some(e),
+ match self {
+ Self::ParseBase58(ref e) => Some(e),
+ Self::LegacyAddressTooLong(ref e) => Some(e),
+ Self::InvalidBase58PayloadLength(ref e) => Some(e),
+ Self::InvalidLegacyPrefix(ref e) => Some(e),
}
}
}
diff --git a/bitcoin/src/bip152.rs b/bitcoin/src/bip152.rs
index 7095e3aa..38b4be42 100644
--- a/bitcoin/src/bip152.rs
+++ b/bitcoin/src/bip152.rs
@@ -48,10 +48,8 @@ impl fmt::Display for Error {
#[cfg(feature = "std")]
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
- use self::Error::*;
-
- match *self {
- UnknownVersion | InvalidPrefill => None,
+ match self {
+ Self::UnknownVersion | Self::InvalidPrefill => None,
}
}
}
diff --git a/bitcoin/src/bip158.rs b/bitcoin/src/bip158.rs
index 928c3d0d..1ac7d3bb 100644
--- a/bitcoin/src/bip158.rs
+++ b/bitcoin/src/bip158.rs
@@ -89,11 +89,9 @@ impl From<Infallible> for Error {
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
- use Error::*;
-
- match *self {
- UtxoMissing(ref coin) => write!(f, "unresolved UTXO {}", coin),
- Io(ref e) => write_err!(f, "I/O error"; e),
+ match self {
+ Self::UtxoMissing(ref coin) => write!(f, "unresolved UTXO {}", coin),
+ Self::Io(ref e) => write_err!(f, "I/O error"; e),
}
}
}
@@ -101,11 +99,9 @@ impl fmt::Display for Error {
#[cfg(feature = "std")]
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
- use Error::*;
-
- match *self {
- UtxoMissing(_) => None,
- Io(ref e) => Some(e),
+ match self {
+ Self::UtxoMissing(_) => None,
+ Self::Io(ref e) => Some(e),
}
}
}
diff --git a/bitcoin/src/bip32.rs b/bitcoin/src/bip32.rs
index c8ec0d17..8f0926ee 100644
--- a/bitcoin/src/bip32.rs
+++ b/bitcoin/src/bip32.rs
@@ -575,20 +575,20 @@ impl From<Infallible> for ParseError {
impl fmt::Display for ParseError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- use ParseError::*;
-
- match *self {
- Secp256k1(ref e) => write_err!(f, "secp256k1 error"; e),
- UnknownVersion(ref bytes) => write!(f, "unknown version magic bytes: {:?}", bytes),
- WrongExtendedKeyLength(ref len) =>
+ match self {
+ Self::Secp256k1(ref e) => write_err!(f, "secp256k1 error"; e),
+ Self::UnknownVersion(ref bytes) =>
+ write!(f, "unknown version magic bytes: {:?}", bytes),
+ Self::WrongExtendedKeyLength(ref len) =>
write!(f, "encoded extended key data has wrong length {}", len),
- Base58(ref e) => write_err!(f, "base58 encoding error"; e),
- InvalidBase58PayloadLength(ref e) => write_err!(f, "base58 payload"; e),
- InvalidPrivateKeyPrefix =>
+ Self::Base58(ref e) => write_err!(f, "base58 encoding error"; e),
+ Self::InvalidBase58PayloadLength(ref e) => write_err!(f, "base58 payload"; e),
+ Self::InvalidPrivateKeyPrefix =>
f.write_str("invalid private key prefix, byte 45 must be 0 as required by BIP-0032"),
- NonZeroParentFingerprintForMasterKey =>
+ Self::NonZeroParentFingerprintForMasterKey =>
f.write_str("non-zero parent fingerprint in master key"),
- NonZeroChildNumberForMasterKey => f.write_str("non-zero child number in master key"),
+ Self::NonZeroChildNumberForMasterKey =>
+ f.write_str("non-zero child number in master key"),
}
}
}
@@ -596,16 +596,14 @@ impl fmt::Display for ParseError {
#[cfg(feature = "std")]
impl std::error::Error for ParseError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
- use ParseError::*;
-
- match *self {
- Secp256k1(ref e) => Some(e),
- Base58(ref e) => Some(e),
- InvalidBase58PayloadLength(ref e) => Some(e),
- UnknownVersion(_) | WrongExtendedKeyLength(_) => None,
- InvalidPrivateKeyPrefix => None,
- NonZeroParentFingerprintForMasterKey => None,
- NonZeroChildNumberForMasterKey => None,
+ match self {
+ Self::Secp256k1(ref e) => Some(e),
+ Self::Base58(ref e) => Some(e),
+ Self::InvalidBase58PayloadLength(ref e) => Some(e),
+ Self::UnknownVersion(_) | Self::WrongExtendedKeyLength(_) => None,
+ Self::InvalidPrivateKeyPrefix => None,
+ Self::NonZeroParentFingerprintForMasterKey => None,
+ Self::NonZeroChildNumberForMasterKey => None,
}
}
}
diff --git a/bitcoin/src/blockdata/block.rs b/bitcoin/src/blockdata/block.rs
index a5e574f5..2eb7890d 100644
--- a/bitcoin/src/blockdata/block.rs
+++ b/bitcoin/src/blockdata/block.rs
@@ -453,13 +453,13 @@ impl From<Infallible> for InvalidBlockError {
impl fmt::Display for InvalidBlockError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- use InvalidBlockError::*;
-
- match *self {
- InvalidMerkleRoot => write!(f, "header Merkle root does not match the calculated Merkle root"),
- InvalidWitnessCommitment => write!(f, "the witness commitment in coinbase transaction does not match the calculated witness_root"),
- NoTransactions => write!(f, "block has no transactions (missing coinbase)"),
- InvalidCoinbase => write!(f, "the first transaction is not a valid coinbase transaction"),
+ match self {
+ Self::InvalidMerkleRoot =>
+ write!(f, "header Merkle root does not match the calculated Merkle root"),
+ Self::InvalidWitnessCommitment => write!(f, "the witness commitment in coinbase transaction does not match the calculated witness_root"),
+ Self::NoTransactions => write!(f, "block has no transactions (missing coinbase)"),
+ Self::InvalidCoinbase =>
+ write!(f, "the first transaction is not a valid coinbase transaction"),
}
}
}
@@ -487,13 +487,11 @@ impl From<Infallible> for Bip34Error {
impl fmt::Display for Bip34Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- use Bip34Error::*;
-
- match *self {
- Unsupported => write!(f, "block doesn't support BIP-0034"),
- NotPresent => write!(f, "BIP-0034 push not present in block's coinbase"),
- NonMinimalPush => write!(f, "byte push not minimally encoded"),
- NegativeHeight => write!(f, "negative BIP-0034 height"),
+ match self {
+ Self::Unsupported => write!(f, "block doesn't support BIP-0034"),
+ Self::NotPresent => write!(f, "BIP-0034 push not present in block's coinbase"),
+ Self::NonMinimalPush => write!(f, "byte push not minimally encoded"),
+ Self::NegativeHeight => write!(f, "negative BIP-0034 height"),
}
}
}
@@ -501,10 +499,9 @@ impl fmt::Display for Bip34Error {
#[cfg(feature = "std")]
impl std::error::Error for Bip34Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
- use Bip34Error::*;
-
- match *self {
- Unsupported | NotPresent | NonMinimalPush | NegativeHeight => None,
+ match self {
+ Self::Unsupported | Self::NotPresent | Self::NonMinimalPush | Self::NegativeHeight =>
+ None,
}
}
}
@@ -543,11 +540,9 @@ impl From<Infallible> for ValidationError {
impl fmt::Display for ValidationError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- use ValidationError::*;
-
- match *self {
- BadProofOfWork => f.write_str("block target correct but not attained"),
- BadTarget => f.write_str("block target incorrect"),
+ match self {
+ Self::BadProofOfWork => f.write_str("block target correct but not attained"),
+ Self::BadTarget => f.write_str("block target incorrect"),
}
}
}
@@ -555,10 +550,8 @@ impl fmt::Display for ValidationError {
#[cfg(feature = "std")]
impl std::error::Error for ValidationError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
- use self::ValidationError::*;
-
- match *self {
- BadProofOfWork | BadTarget => None,
+ match self {
+ Self::BadProofOfWork | Self::BadTarget => None,
}
}
}
diff --git a/bitcoin/src/blockdata/script/mod.rs b/bitcoin/src/blockdata/script/mod.rs
index 348e39cc..06643769 100644
--- a/bitcoin/src/blockdata/script/mod.rs
+++ b/bitcoin/src/blockdata/script/mod.rs
@@ -263,15 +263,13 @@ impl From<Infallible> for Error {
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- use Error::*;
-
- match *self {
- NonMinimalPush => f.write_str("non-minimal datapush"),
- EarlyEndOfScript => f.write_str("unexpected end of script"),
- NumericOverflow =>
+ match self {
+ Self::NonMinimalPush => f.write_str("non-minimal datapush"),
+ Self::EarlyEndOfScript => f.write_str("unexpected end of script"),
+ Self::NumericOverflow =>
f.write_str("numeric overflow (number on stack larger than 4 bytes)"),
- UnknownSpentOutput(ref point) => write!(f, "unknown spent output: {}", point),
- Serialization =>
+ Self::UnknownSpentOutput(ref point) => write!(f, "unknown spent output: {}", point),
+ Self::Serialization =>
f.write_str("can not serialize the spending transaction in Transaction::verify()"),
}
}
@@ -280,14 +278,12 @@ impl fmt::Display for Error {
#[cfg(feature = "std")]
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
- use Error::*;
-
- match *self {
- NonMinimalPush
- | EarlyEndOfScript
- | NumericOverflow
- | UnknownSpentOutput(_)
- | Serialization => None,
+ match self {
+ Self::NonMinimalPush
+ | Self::EarlyEndOfScript
+ | Self::NumericOverflow
+ | Self::UnknownSpentOutput(_)
+ | Self::Serialization => None,
}
}
}
diff --git a/bitcoin/src/blockdata/script/witness_program.rs b/bitcoin/src/blockdata/script/witness_program.rs
index d6ac0319..7ecb923d 100644
--- a/bitcoin/src/blockdata/script/witness_program.rs
+++ b/bitcoin/src/blockdata/script/witness_program.rs
@@ -43,16 +43,14 @@ pub struct WitnessProgram {
impl WitnessProgram {
/// Constructs a new witness program, copying the content from the given byte slice.
pub fn new(version: WitnessVersion, bytes: &[u8]) -> Result<Self, Error> {
- use Error::*;
-
let program_len = bytes.len();
if program_len < MIN_SIZE || program_len > MAX_SIZE {
- return Err(InvalidLength(program_len));
+ return Err(Error::InvalidLength(program_len));
}
// Specific SegWit v0 check. These addresses can never spend funds sent to them.
if version == WitnessVersion::V0 && (program_len != 20 && program_len != 32) {
- return Err(InvalidSegwitV0Length(program_len));
+ return Err(Error::InvalidSegwitV0Length(program_len));
}
let program = ArrayVec::from_slice(bytes);
@@ -161,12 +159,10 @@ impl From<Infallible> for Error {
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- use Error::*;
-
- match *self {
- InvalidLength(len) =>
+ match self {
+ Self::InvalidLength(len) =>
write!(f, "witness program must be between 2 and 40 bytes: length={}", len),
- InvalidSegwitV0Length(len) =>
+ Self::InvalidSegwitV0Length(len) =>
write!(f, "a v0 witness program must be either 20 or 32 bytes: length={}", len),
}
}
@@ -175,10 +171,8 @@ impl fmt::Display for Error {
#[cfg(feature = "std")]
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
- use Error::*;
-
- match *self {
- InvalidLength(_) | InvalidSegwitV0Length(_) => None,
+ match self {
+ Self::InvalidLength(_) | Self::InvalidSegwitV0Length(_) => None,
}
}
}
diff --git a/bitcoin/src/blockdata/script/witness_version.rs b/bitcoin/src/blockdata/script/witness_version.rs
index dd7c2cd0..5d271f3e 100644
--- a/bitcoin/src/blockdata/script/witness_version.rs
+++ b/bitcoin/src/blockdata/script/witness_version.rs
@@ -166,11 +166,9 @@ impl From<Infallible> for FromStrError {
impl fmt::Display for FromStrError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- use FromStrError::*;
-
- match *self {
- Unparsable(ref e) => write_err!(f, "integer parse error"; e),
- Invalid(ref e) => write_err!(f, "invalid version number"; e),
+ match self {
+ Self::Unparsable(ref e) => write_err!(f, "integer parse error"; e),
+ Self::Invalid(ref e) => write_err!(f, "invalid version number"; e),
}
}
}
@@ -178,11 +176,9 @@ impl fmt::Display for FromStrError {
#[cfg(feature = "std")]
impl std::error::Error for FromStrError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
- use FromStrError::*;
-
- match *self {
- Unparsable(ref e) => Some(e),
- Invalid(ref e) => Some(e),
+ match self {
+ Self::Unparsable(ref e) => Some(e),
+ Self::Invalid(ref e) => Some(e),
}
}
}
@@ -211,11 +207,10 @@ impl From<Infallible> for TryFromInstructionError {
impl fmt::Display for TryFromInstructionError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- use TryFromInstructionError::*;
-
- match *self {
- TryFrom(ref e) => write_err!(f, "opcode is not a valid witness version"; e),
- DataPush => write!(f, "non-zero data push opcode is not a valid witness version"),
+ match self {
+ Self::TryFrom(ref e) => write_err!(f, "opcode is not a valid witness version"; e),
+ Self::DataPush =>
+ write!(f, "non-zero data push opcode is not a valid witness version"),
}
}
}
@@ -223,11 +218,9 @@ impl fmt::Display for TryFromInstructionError {
#[cfg(feature = "std")]
impl std::error::Error for TryFromInstructionError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
- use TryFromInstructionError::*;
-
- match *self {
- TryFrom(ref e) => Some(e),
- DataPush => None,
+ match self {
+ Self::TryFrom(ref e) => Some(e),
+ Self::DataPush => None,
}
}
}
diff --git a/bitcoin/src/consensus/error.rs b/bitcoin/src/consensus/error.rs
index 4fe207f5..60a053a4 100644
--- a/bitcoin/src/consensus/error.rs
+++ b/bitcoin/src/consensus/error.rs
@@ -27,11 +27,9 @@ impl From<Infallible> for DeserializeError {
impl fmt::Display for DeserializeError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- use DeserializeError::*;
-
- match *self {
- Parse(ref e) => write_err!(f, "error parsing encoded object"; e),
- Unconsumed => write!(f, "data not consumed entirely when deserializing"),
+ match self {
+ Self::Parse(ref e) => write_err!(f, "error parsing encoded object"; e),
+ Self::Unconsumed => write!(f, "data not consumed entirely when deserializing"),
}
}
}
@@ -39,11 +37,9 @@ impl fmt::Display for DeserializeError {
#[cfg(feature = "std")]
impl std::error::Error for DeserializeError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
- use DeserializeError::*;
-
- match *self {
- Parse(ref e) => Some(e),
- Unconsumed => None,
+ match self {
+ Self::Parse(ref e) => Some(e),
+ Self::Unconsumed => None,
}
}
}
@@ -72,12 +68,10 @@ impl<E> From<Infallible> for DecodeError<E> {
impl<E: fmt::Debug> fmt::Display for DecodeError<E> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- use DecodeError::*;
-
- match *self {
- Parse(ref e) => write_err!(f, "error parsing encoded object"; e),
- Unconsumed => write!(f, "data not consumed entirely when deserializing"),
- Other(ref other) => write!(f, "other decoding error: {:?}", other),
+ match self {
+ Self::Parse(ref e) => write_err!(f, "error parsing encoded object"; e),
+ Self::Unconsumed => write!(f, "data not consumed entirely when deserializing"),
+ Self::Other(ref other) => write!(f, "other decoding error: {:?}", other),
}
}
}
@@ -85,12 +79,10 @@ impl<E: fmt::Debug> fmt::Display for DecodeError<E> {
#[cfg(feature = "std")]
impl<E: fmt::Debug + std::error::Error + 'static> std::error::Error for DecodeError<E> {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
- use DecodeError::*;
-
- match *self {
- Parse(ref e) => Some(e),
- Unconsumed => None,
- Other(ref e) => Some(e),
+ match self {
+ Self::Parse(ref e) => Some(e),
+ Self::Unconsumed => None,
+ Self::Other(ref e) => Some(e),
}
}
}
@@ -111,11 +103,9 @@ impl From<Infallible> for Error {
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- use Error::*;
-
- match *self {
- Io(ref e) => write_err!(f, "I/O error"; e),
- Parse(ref e) => write_err!(f, "error parsing encoded object"; e),
+ match self {
+ Self::Io(ref e) => write_err!(f, "I/O error"; e),
+ Self::Parse(ref e) => write_err!(f, "error parsing encoded object"; e),
}
}
}
@@ -123,11 +113,9 @@ impl fmt::Display for Error {
#[cfg(feature = "std")]
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
- use Error::*;
-
- match *self {
- Io(ref e) => Some(e),
- Parse(ref e) => Some(e),
+ match self {
+ Self::Io(ref e) => Some(e),
+ Self::Parse(ref e) => Some(e),
}
}
}
@@ -181,20 +169,18 @@ impl From<Infallible> for ParseError {
impl fmt::Display for ParseError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- use ParseError::*;
-
- match *self {
- MissingData => write!(f, "missing data (early end of file or slice too short)"),
- OversizedVectorAllocation { requested: ref r, max: ref m } =>
+ match self {
+ Self::MissingData => write!(f, "missing data (early end of file or slice too short)"),
+ Self::OversizedVectorAllocation { requested: ref r, max: ref m } =>
write!(f, "allocation of oversized vector: requested {}, maximum {}", r, m),
- InvalidChecksum { expected: ref e, actual: ref a } => write!(
+ Self::InvalidChecksum { expected: ref e, actual: ref a } => write!(
f,
"invalid checksum: expected {:02x}{:02x}{:02x}{:02x}, actual {:02x}{:02x}{:02x}{:02x}",
e[0], e[1], e[2], e[3], a[0], a[1], a[2], a[3],
),
- NonMinimalCompactSize => write!(f, "non-minimal compact size"),
- ParseFailed(ref s) => write!(f, "parse failed: {}", s),
- UnsupportedSegwitFlag(ref swflag) =>
+ Self::NonMinimalCompactSize => write!(f, "non-minimal compact size"),
+ Self::ParseFailed(ref s) => write!(f, "parse failed: {}", s),
+ Self::UnsupportedSegwitFlag(ref swflag) =>
write!(f, "unsupported SegWit version: {}", swflag),
}
}
@@ -203,15 +189,13 @@ impl fmt::Display for ParseError {
#[cfg(feature = "std")]
impl std::error::Error for ParseError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
- use ParseError::*;
-
match self {
- MissingData
- | OversizedVectorAllocation { .. }
- | InvalidChecksum { .. }
- | NonMinimalCompactSize
- | ParseFailed(_)
- | UnsupportedSegwitFlag(_) => None,
+ Self::MissingData
+ | Self::OversizedVectorAllocation { .. }
+ | Self::InvalidChecksum { .. }
+ | Self::NonMinimalCompactSize
+ | Self::ParseFailed(_)
+ | Self::UnsupportedSegwitFlag(_) => None,
}
}
}
@@ -227,12 +211,10 @@ pub enum FromHexError {
impl fmt::Display for FromHexError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- use FromHexError::*;
-
- match *self {
- OddLengthString(ref e) =>
+ match self {
+ Self::OddLengthString(ref e) =>
write_err!(f, "odd length, failed to create bytes from hex"; e),
- Decode(ref e) => write_err!(f, "decoding error"; e),
+ Self::Decode(ref e) => write_err!(f, "decoding error"; e),
}
}
}
@@ -240,11 +222,9 @@ impl fmt::Display for FromHexError {
#[cfg(feature = "std")]
impl std::error::Error for FromHexError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
- use FromHexError::*;
-
- match *self {
- OddLengthString(ref e) => Some(e),
- Decode(ref e) => Some(e),
+ match self {
+ Self::OddLengthString(ref e) => Some(e),
+ Self::Decode(ref e) => Some(e),
}
}
}
diff --git a/bitcoin/src/consensus_validation.rs b/bitcoin/src/consensus_validation.rs
index cf5343c3..a998e602 100644
--- a/bitcoin/src/consensus_validation.rs
+++ b/bitcoin/src/consensus_validation.rs
@@ -244,11 +244,10 @@ impl From<Infallible> for TxVerifyError {
impl fmt::Display for TxVerifyError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- use TxVerifyError::*;
-
- match *self {
- ScriptVerification(ref e) => write_err!(f, "bitcoinconsensus verification failed"; e),
- UnknownSpentOutput(ref p) => write!(f, "unknown spent output: {}", p),
+ match self {
+ Self::ScriptVerification(ref e) =>
+ write_err!(f, "bitcoinconsensus verification failed"; e),
+ Self::UnknownSpentOutput(ref p) => write!(f, "unknown spent output: {}", p),
}
}
}
@@ -256,11 +255,9 @@ impl fmt::Display for TxVerifyError {
#[cfg(feature = "std")]
impl std::error::Error for TxVerifyError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
- use TxVerifyError::*;
-
- match *self {
- ScriptVerification(ref e) => Some(e),
- UnknownSpentOutput(_) => None,
+ match self {
+ Self::ScriptVerification(ref e) => Some(e),
+ Self::UnknownSpentOutput(_) => None,
}
}
}
diff --git a/bitcoin/src/crypto/ecdsa.rs b/bitcoin/src/crypto/ecdsa.rs
index 0b5a1462..ed8aeff1 100644
--- a/bitcoin/src/crypto/ecdsa.rs
+++ b/bitcoin/src/crypto/ecdsa.rs
@@ -221,12 +221,10 @@ impl From<Infallible> for DecodeError {
impl fmt::Display for DecodeError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- use DecodeError::*;
-
- match *self {
- SighashType(ref e) => write_err!(f, "non-standard signature hash type"; e),
- EmptySignature => write!(f, "empty ECDSA signature"),
- Secp256k1(ref e) => write_err!(f, "secp256k1"; e),
+ match self {
+ Self::SighashType(ref e) => write_err!(f, "non-standard signature hash type"; e),
+ Self::EmptySignature => write!(f, "empty ECDSA signature"),
+ Self::Secp256k1(ref e) => write_err!(f, "secp256k1"; e),
}
}
}
@@ -234,12 +232,10 @@ impl fmt::Display for DecodeError {
#[cfg(feature = "std")]
impl std::error::Error for DecodeError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
- use DecodeError::*;
-
- match *self {
- Secp256k1(ref e) => Some(e),
- SighashType(ref e) => Some(e),
- EmptySignature => None,
+ match self {
+ Self::Secp256k1(ref e) => Some(e),
+ Self::SighashType(ref e) => Some(e),
+ Self::EmptySignature => None,
}
}
}
@@ -268,11 +264,9 @@ impl From<Infallible> for ParseSignatureError {
impl fmt::Display for ParseSignatureError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- use ParseSignatureError::*;
-
- match *self {
- Hex(ref e) => write_err!(f, "signature hex decoding error"; e),
- Decode(ref e) => write_err!(f, "signature byte slice decoding error"; e),
+ match self {
+ Self::Hex(ref e) => write_err!(f, "signature hex decoding error"; e),
+ Self::Decode(ref e) => write_err!(f, "signature byte slice decoding error"; e),
}
}
}
@@ -280,11 +274,9 @@ impl fmt::Display for ParseSignatureError {
#[cfg(feature = "std")]
impl std::error::Error for ParseSignatureError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
- use ParseSignatureError::*;
-
- match *self {
- Hex(ref e) => Some(e),
- Decode(ref e) => Some(e),
+ match self {
+ Self::Hex(ref e) => Some(e),
+ Self::Decode(ref e) => Some(e),
}
}
}
diff --git a/bitcoin/src/crypto/key.rs b/bitcoin/src/crypto/key.rs
index e0ce609c..1bbe16de 100644
--- a/bitcoin/src/crypto/key.rs
+++ b/bitcoin/src/crypto/key.rs
@@ -349,20 +349,18 @@ impl fmt::Display for PublicKey {
impl FromStr for PublicKey {
type Err = ParsePublicKeyError;
fn from_str(s: &str) -> Result<Self, ParsePublicKeyError> {
- use HexToArrayError::*;
-
match s.len() {
66 => {
let bytes = <[u8; 33]>::from_hex(s).map_err(|e| match e {
- InvalidChar(e) => ParsePublicKeyError::InvalidChar(e),
- InvalidLength(_) => unreachable!("length checked already"),
+ HexToArrayError::InvalidChar(e) => ParsePublicKeyError::InvalidChar(e),
+ HexToArrayError::InvalidLength(_) => unreachable!("length checked already"),
})?;
Ok(Self::from_slice(&bytes)?)
}
130 => {
let bytes = <[u8; 65]>::from_hex(s).map_err(|e| match e {
- InvalidChar(e) => ParsePublicKeyError::InvalidChar(e),
- InvalidLength(_) => unreachable!("length checked already"),
+ HexToArrayError::InvalidChar(e) => ParsePublicKeyError::InvalidChar(e),
+ HexToArrayError::InvalidLength(_) => unreachable!("length checked already"),
})?;
Ok(Self::from_slice(&bytes)?)
}
@@ -1070,12 +1068,11 @@ impl From<Infallible> for FromSliceError {
impl fmt::Display for FromSliceError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- use FromSliceError::*;
-
match self {
- Secp256k1(e) => write_err!(f, "secp256k1"; e),
- InvalidKeyPrefix(b) => write!(f, "key prefix invalid: {}", b),
- InvalidLength(got) => write!(f, "slice length should be 33 or 65 bytes, got: {}", got),
+ Self::Secp256k1(e) => write_err!(f, "secp256k1"; e),
+ Self::InvalidKeyPrefix(b) => write!(f, "key prefix invalid: {}", b),
+ Self::InvalidLength(got) =>
+ write!(f, "slice length should be 33 or 65 bytes, got: {}", got),
}
}
}
@@ -1083,11 +1080,9 @@ impl fmt::Display for FromSliceError {
#[cfg(feature = "std")]
impl std::error::Error for FromSliceError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
- use FromSliceError::*;
-
- match *self {
- Secp256k1(ref e) => Some(e),
- InvalidKeyPrefix(_) | InvalidLength(_) => None,
+ match self {
+ Self::Secp256k1(ref e) => Some(e),
+ Self::InvalidKeyPrefix(_) | Self::InvalidLength(_) => None,
}
}
}
@@ -1118,16 +1113,15 @@ impl From<Infallible> for FromWifError {
impl fmt::Display for FromWifError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- use FromWifError::*;
-
- match *self {
- Base58(ref e) => write_err!(f, "invalid base58"; e),
- InvalidBase58PayloadLength(ref e) =>
+ match self {
+ Self::Base58(ref e) => write_err!(f, "invalid base58"; e),
+ Self::InvalidBase58PayloadLength(ref e) =>
write_err!(f, "decoded base58 data was an invalid length"; e),
- InvalidAddressVersion(ref e) =>
+ Self::InvalidAddressVersion(ref e) =>
write_err!(f, "decoded base58 data contained an invalid address version byte"; e),
- Secp256k1(ref e) => write_err!(f, "private key validation failed"; e),
- InvalidWifCompressionFlag(ref e) => write_err!(f, "invalid WIF compression flag"; e),
+ Self::Secp256k1(ref e) => write_err!(f, "private key validation failed"; e),
+ Self::InvalidWifCompressionFlag(ref e) =>
+ write_err!(f, "invalid WIF compression flag"; e),
}
}
}
@@ -1135,14 +1129,12 @@ impl fmt::Display for FromWifError {
#[cfg(feature = "std")]
impl std::error::Error for FromWifError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
- use FromWifError::*;
-
- match *self {
- Base58(ref e) => Some(e),
- InvalidBase58PayloadLength(ref e) => Some(e),
- InvalidAddressVersion(ref e) => Some(e),
- Secp256k1(ref e) => Some(e),
- InvalidWifCompressionFlag(ref e) => Some(e),
+ match self {
+ Self::Base58(ref e) => Some(e),
+ Self::InvalidBase58PayloadLength(ref e) => Some(e),
+ Self::InvalidAddressVersion(ref e) => Some(e),
+ Self::Secp256k1(ref e) => Some(e),
+ Self::InvalidWifCompressionFlag(ref e) => Some(e),
}
}
}
@@ -1184,11 +1176,10 @@ impl From<Infallible> for ParsePublicKeyError {
impl fmt::Display for ParsePublicKeyError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- use ParsePublicKeyError::*;
- match *self {
- Encoding(ref e) => write_err!(f, "string error"; e),
- InvalidChar(ref e) => write_err!(f, "hex decoding"; e),
- InvalidHexLength(got) =>
+ match self {
+ Self::Encoding(ref e) => write_err!(f, "string error"; e),
+ Self::InvalidChar(ref e) => write_err!(f, "hex decoding"; e),
+ Self::InvalidHexLength(got) =>
write!(f, "pubkey string should be 66 or 130 digits long, got: {}", got),
}
}
@@ -1197,12 +1188,10 @@ impl fmt::Display for ParsePublicKeyError {
#[cfg(feature = "std")]
impl std::error::Error for ParsePublicKeyError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
- use ParsePublicKeyError::*;
-
- match *self {
- Encoding(ref e) => Some(e),
- InvalidChar(ref e) => Some(e),
- InvalidHexLength(_) => None,
+ match self {
+ Self::Encoding(ref e) => Some(e),
+ Self::InvalidChar(ref e) => Some(e),
+ Self::InvalidHexLength(_) => None,
}
}
}
@@ -1226,10 +1215,9 @@ impl From<Infallible> for ParseCompressedPublicKeyError {
impl fmt::Display for ParseCompressedPublicKeyError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- use ParseCompressedPublicKeyError::*;
match self {
- Secp256k1(e) => write_err!(f, "secp256k1 error"; e),
- Hex(e) => write_err!(f, "invalid hex"; e),
+ Self::Secp256k1(e) => write_err!(f, "secp256k1 error"; e),
+ Self::Hex(e) => write_err!(f, "invalid hex"; e),
}
}
}
@@ -1237,11 +1225,9 @@ impl fmt::Display for ParseCompressedPublicKeyError {
#[cfg(feature = "std")]
impl std::error::Error for ParseCompressedPublicKeyError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
- use ParseCompressedPublicKeyError::*;
-
match self {
- Secp256k1(e) => Some(e),
- Hex(e) => Some(e),
+ Self::Secp256k1(e) => Some(e),
+ Self::Hex(e) => Some(e),
}
}
}
diff --git a/bitcoin/src/crypto/sighash.rs b/bitcoin/src/crypto/sighash.rs
index a966a4e7..b6458d25 100644
--- a/bitcoin/src/crypto/sighash.rs
+++ b/bitcoin/src/crypto/sighash.rs
@@ -310,11 +310,11 @@ impl From<Infallible> for PrevoutsIndexError {
impl fmt::Display for PrevoutsIndexError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- use PrevoutsIndexError::*;
-
- match *self {
- InvalidOneIndex => write!(f, "invalid index when accessing a Prevouts::One kind"),
- InvalidAllIndex => write!(f, "invalid index when accessing a Prevouts::All kind"),
+ match self {
+ Self::InvalidOneIndex =>
+ write!(f, "invalid index when accessing a Prevouts::One kind"),
+ Self::InvalidAllIndex =>
+ write!(f, "invalid index when accessing a Prevouts::All kind"),
}
}
}
@@ -322,10 +322,8 @@ impl fmt::Display for PrevoutsIndexError {
#[cfg(feature = "std")]
impl std::error::Error for PrevoutsIndexError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
- use PrevoutsIndexError::*;
-
- match *self {
- InvalidOneIndex | InvalidAllIndex => None,
+ match self {
+ Self::InvalidOneIndex | Self::InvalidAllIndex => None,
}
}
}
@@ -1181,12 +1179,10 @@ pub struct Annex<'a>(&'a [u8]);
impl<'a> Annex<'a> {
/// Constructs a new `Annex` struct checking the first byte is `0x50`.
pub fn new(annex_bytes: &'a [u8]) -> Result<Self, AnnexError> {
- use AnnexError::*;
-
match annex_bytes.first() {
Some(&TAPROOT_ANNEX_PREFIX) => Ok(Annex(annex_bytes)),
- Some(other) => Err(IncorrectPrefix(*other)),
- None => Err(Empty),
+ Some(other) => Err(AnnexError::IncorrectPrefix(*other)),
+ None => Err(AnnexError::Empty),
}
}
@@ -1224,15 +1220,14 @@ impl From<Infallible> for TaprootError {
impl fmt::Display for TaprootError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- use TaprootError::*;
-
- match *self {
- InputsIndex(ref e) => write_err!(f, "inputs index"; e),
- SingleMissingOutput(ref e) => write_err!(f, "sighash single"; e),
- PrevoutsSize(ref e) => write_err!(f, "prevouts size"; e),
- PrevoutsIndex(ref e) => write_err!(f, "prevouts index"; e),
- PrevoutsKind(ref e) => write_err!(f, "prevouts kind"; e),
- InvalidSighashType(hash_ty) => write!(f, "invalid Taproot sighash type : {} ", hash_ty),
+ match self {
+ Self::InputsIndex(ref e) => write_err!(f, "inputs index"; e),
+ Self::SingleMissingOutput(ref e) => write_err!(f, "sighash single"; e),
+ Self::PrevoutsSize(ref e) => write_err!(f, "prevouts size"; e),
+ Self::PrevoutsIndex(ref e) => write_err!(f, "prevouts index"; e),
+ Self::PrevoutsKind(ref e) => write_err!(f, "prevouts kind"; e),
+ Self::InvalidSighashType(hash_ty) =>
+ write!(f, "invalid Taproot sighash type : {} ", hash_ty),
}
}
}
@@ -1240,15 +1235,13 @@ impl fmt::Display for TaprootError {
#[cfg(feature = "std")]
impl std::error::Error for TaprootError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
- use TaprootError::*;
-
- match *self {
- InputsIndex(ref e) => Some(e),
- SingleMissingOutput(ref e) => Some(e),
- PrevoutsSize(ref e) => Some(e),
- PrevoutsIndex(ref e) => Some(e),
- PrevoutsKind(ref e) => Some(e),
- InvalidSighashType(_) => None,
+ match self {
+ Self::InputsIndex(ref e) => Some(e),
+ Self::SingleMissingOutput(ref e) => Some(e),
+ Self::PrevoutsSize(ref e) => Some(e),
+ Self::PrevoutsIndex(ref e) => Some(e),
+ Self::PrevoutsKind(ref e) => Some(e),
+ Self::InvalidSighashType(_) => None,
}
}
}
@@ -1289,11 +1282,10 @@ impl From<transaction::InputsIndexError> for P2wpkhError {
impl fmt::Display for P2wpkhError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- use P2wpkhError::*;
-
- match *self {
- Sighash(ref e) => write_err!(f, "error encoding SegWit v0 signing data"; e),
- NotP2wpkhScript => write!(f, "script is not a script pubkey for a p2wpkh output"),
+ match self {
+ Self::Sighash(ref e) => write_err!(f, "error encoding SegWit v0 signing data"; e),
+ Self::NotP2wpkhScript =>
+ write!(f, "script is not a script pubkey for a p2wpkh output"),
}
}
}
@@ -1301,11 +1293,9 @@ impl fmt::Display for P2wpkhError {
#[cfg(feature = "std")]
impl std::error::Error for P2wpkhError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
- use P2wpkhError::*;
-
- match *self {
- Sighash(ref e) => Some(e),
- NotP2wpkhScript => None,
+ match self {
+ Self::Sighash(ref e) => Some(e),
+ Self::NotP2wpkhScript => None,
}
}
}
@@ -1352,11 +1342,9 @@ impl From<Infallible> for AnnexError {
impl fmt::Display for AnnexError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- use AnnexError::*;
-
- match *self {
- Empty => write!(f, "the annex is empty"),
- IncorrectPrefix(byte) =>
+ match self {
+ Self::Empty => write!(f, "the annex is empty"),
+ Self::IncorrectPrefix(byte) =>
write!(f, "incorrect prefix byte in the annex {:02x}, expecting 0x50", byte),
}
}
@@ -1365,10 +1353,8 @@ impl fmt::Display for AnnexError {
#[cfg(feature = "std")]
impl std::error::Error for AnnexError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
- use AnnexError::*;
-
- match *self {
- Empty | IncorrectPrefix(_) => None,
+ match self {
+ Self::Empty | Self::IncorrectPrefix(_) => None,
}
}
}
diff --git a/bitcoin/src/crypto/taproot.rs b/bitcoin/src/crypto/taproot.rs
index db7aa4b1..b7ca5d19 100644
--- a/bitcoin/src/crypto/taproot.rs
+++ b/bitcoin/src/crypto/taproot.rs
@@ -102,12 +102,11 @@ impl From<Infallible> for SigFromSliceError {
impl fmt::Display for SigFromSliceError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- use SigFromSliceError::*;
-
- match *self {
- SighashType(ref e) => write_err!(f, "sighash"; e),
- Secp256k1(ref e) => write_err!(f, "secp256k1"; e),
- InvalidSignatureSize(sz) => write!(f, "invalid Taproot signature size: {}", sz),
+ match self {
+ Self::SighashType(ref e) => write_err!(f, "sighash"; e),
+ Self::Secp256k1(ref e) => write_err!(f, "secp256k1"; e),
+ Self::InvalidSignatureSize(sz) =>
+ write!(f, "invalid Taproot signature size: {}", sz),
}
}
}
@@ -115,12 +114,10 @@ impl fmt::Display for SigFromSliceError {
#[cfg(feature = "std")]
impl std::error::Error for SigFromSliceError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
- use SigFromSliceError::*;
-
- match *self {
- Secp256k1(ref e) => Some(e),
- SighashType(ref e) => Some(e),
- InvalidSignatureSize(_) => None,
+ match self {
+ Self::Secp256k1(ref e) => Some(e),
+ Self::SighashType(ref e) => Some(e),
+ Self::InvalidSignatureSize(_) => None,
}
}
}
diff --git a/bitcoin/src/merkle_tree/block.rs b/bitcoin/src/merkle_tree/block.rs
index 4b6edc1c..7fb7a4d2 100644
--- a/bitcoin/src/merkle_tree/block.rs
+++ b/bitcoin/src/merkle_tree/block.rs
@@ -17,7 +17,6 @@ use arbitrary::{Arbitrary, Unstructured};
use internals::ToU64 as _;
use io::{BufRead, Write};
-use self::MerkleBlockError::*;
use crate::block::{self, Block, Checked};
use crate::consensus::encode::{self, Decodable, Encodable, ReadExt, WriteExt, MAX_VEC_SIZE};
use crate::merkle_tree::{MerkleNode as _, TxMerkleNode};
@@ -115,7 +114,7 @@ impl MerkleBlock {
if merkle_root.eq(&self.header.merkle_root) {
Ok(())
} else {
- Err(MerkleRootMismatch)
+ Err(MerkleBlockError::MerkleRootMismatch)
}
}
}
@@ -247,19 +246,19 @@ impl PartialMerkleTree {
indexes.clear();
// An empty set will not work
if self.num_transactions == 0 {
- return Err(NoTransactions);
+ return Err(MerkleBlockError::NoTransactions);
};
// check for excessively high numbers of transactions
if self.num_transactions.to_u64() > Weight::MAX_BLOCK / Weight::MIN_TRANSACTION {
- return Err(TooManyTransactions);
+ return Err(MerkleBlockError::TooManyTransactions);
}
// there can never be more hashes provided than one for every txid
if self.hashes.len() as u32 > self.num_transactions {
- return Err(TooManyHashes);
+ return Err(MerkleBlockError::TooManyHashes);
};
// there must be at least one bit per node in the partial tree, and at least one node per hash
if self.bits.len() < self.hashes.len() {
- return Err(NotEnoughBits);
+ return Err(MerkleBlockError::NotEnoughBits);
};
let height = self.calc_tree_height();
@@ -272,11 +271,11 @@ impl PartialMerkleTree {
// Verify that all bits were consumed (except for the padding caused by
// serializing it as a byte sequence)
if bits_used.div_ceil(8) != self.bits.len().div_ceil(8) as u32 {
- return Err(NotAllBitsConsumed);
+ return Err(MerkleBlockError::NotAllBitsConsumed);
}
// Verify that all hashes were consumed
if hash_used != self.hashes.len() as u32 {
- return Err(NotAllHashesConsumed);
+ return Err(MerkleBlockError::NotAllHashesConsumed);
}
Ok(hash_merkle_root)
}
@@ -353,14 +352,14 @@ impl PartialMerkleTree {
indexes: &mut Vec<u32>,
) -> Result<TxMerkleNode, MerkleBlockError> {
if *bits_used as usize >= self.bits.len() {
- return Err(BitsArrayOverflow);
+ return Err(MerkleBlockError::BitsArrayOverflow);
}
let parent_of_match = self.bits[*bits_used as usize];
*bits_used += 1;
if height == 0 || !parent_of_match {
// If at height 0, or nothing interesting below, use stored hash and do not descend
if *hash_used as usize >= self.hashes.len() {
- return Err(HashesArrayOverflow);
+ return Err(MerkleBlockError::HashesArrayOverflow);
}
let hash = self.hashes[*hash_used as usize];
*hash_used += 1;
@@ -393,7 +392,7 @@ impl PartialMerkleTree {
if right == left {
// The left and right branches should never be identical, as the transaction
// hashes covered by them must each be unique.
- return Err(IdenticalHashesFound);
+ return Err(MerkleBlockError::IdenticalHashesFound);
}
} else {
right = left;
@@ -482,19 +481,17 @@ impl From<Infallible> for MerkleBlockError {
impl fmt::Display for MerkleBlockError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- use MerkleBlockError::*;
-
- match *self {
- MerkleRootMismatch => write!(f, "Merkle header root doesn't match to the root calculated from the partial Merkle tree"),
- NoTransactions => write!(f, "partial Merkle tree contains no transactions"),
- TooManyTransactions => write!(f, "too many transactions"),
- TooManyHashes => write!(f, "proof contains more hashes than transactions"),
- NotEnoughBits => write!(f, "proof contains fewer bits than hashes"),
- NotAllBitsConsumed => write!(f, "not all bits were consumed"),
- NotAllHashesConsumed => write!(f, "not all hashes were consumed"),
- BitsArrayOverflow => write!(f, "overflowed the bits array"),
- HashesArrayOverflow => write!(f, "overflowed the hashes array"),
- IdenticalHashesFound => write!(f, "found identical transaction hashes"),
+ match self {
+ Self::MerkleRootMismatch => write!(f, "Merkle header root doesn't match to the root calculated from the partial Merkle tree"),
+ Self::NoTransactions => write!(f, "partial Merkle tree contains no transactions"),
+ Self::TooManyTransactions => write!(f, "too many transactions"),
+ Self::TooManyHashes => write!(f, "proof contains more hashes than transactions"),
+ Self::NotEnoughBits => write!(f, "proof contains fewer bits than hashes"),
+ Self::NotAllBitsConsumed => write!(f, "not all bits were consumed"),
+ Self::NotAllHashesConsumed => write!(f, "not all hashes were consumed"),
+ Self::BitsArrayOverflow => write!(f, "overflowed the bits array"),
+ Self::HashesArrayOverflow => write!(f, "overflowed the hashes array"),
+ Self::IdenticalHashesFound => write!(f, "found identical transaction hashes"),
}
}
}
@@ -502,12 +499,17 @@ impl fmt::Display for MerkleBlockError {
#[cfg(feature = "std")]
impl std::error::Error for MerkleBlockError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
- use MerkleBlockError::*;
-
- match *self {
- MerkleRootMismatch | NoTransactions | TooManyTransactions | TooManyHashes
- | NotEnoughBits | NotAllBitsConsumed | NotAllHashesConsumed | BitsArrayOverflow
- | HashesArrayOverflow | IdenticalHashesFound => None,
+ match self {
+ Self::MerkleRootMismatch
+ | Self::NoTransactions
+ | Self::TooManyTransactions
+ | Self::TooManyHashes
+ | Self::NotEnoughBits
+ | Self::NotAllBitsConsumed
+ | Self::NotAllHashesConsumed
+ | Self::BitsArrayOverflow
+ | Self::HashesArrayOverflow
+ | Self::IdenticalHashesFound => None,
}
}
}
diff --git a/bitcoin/src/psbt/error.rs b/bitcoin/src/psbt/error.rs
index b84b9322..3a62df06 100644
--- a/bitcoin/src/psbt/error.rs
+++ b/bitcoin/src/psbt/error.rs
@@ -124,67 +124,68 @@ impl From<Infallible> for Error {
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- use Error::*;
-
- match *self {
- InvalidMagic => f.write_str("invalid magic"),
- MissingUtxo => f.write_str("UTXO information is not present in PSBT"),
- InvalidSeparator => f.write_str("invalid separator"),
- PsbtUtxoOutOfbounds =>
+ match self {
+ Self::InvalidMagic => f.write_str("invalid magic"),
+ Self::MissingUtxo => f.write_str("UTXO information is not present in PSBT"),
+ Self::InvalidSeparator => f.write_str("invalid separator"),
+ Self::PsbtUtxoOutOfbounds =>
f.write_str("output index is out of bounds of non witness script output array"),
- InvalidKey(ref rkey) => write!(f, "invalid key: {}", rkey),
- InvalidProprietaryKey =>
+ Self::InvalidKey(ref rkey) => write!(f, "invalid key: {}", rkey),
+ Self::InvalidProprietaryKey =>
write!(f, "non-proprietary key type found when proprietary key was expected"),
- DuplicateKey(ref rkey) => write!(f, "duplicate key: {}", rkey),
- UnsignedTxHasScriptSigs => f.write_str("the unsigned transaction has script sigs"),
- UnsignedTxHasScriptWitnesses =>
+ Self::DuplicateKey(ref rkey) => write!(f, "duplicate key: {}", rkey),
+ Self::UnsignedTxHasScriptSigs =>
+ f.write_str("the unsigned transaction has script sigs"),
+ Self::UnsignedTxHasScriptWitnesses =>
f.write_str("the unsigned transaction has script witnesses"),
- MustHaveUnsignedTx =>
+ Self::MustHaveUnsignedTx =>
f.write_str("partially signed transactions must have an unsigned transaction"),
- NoMorePairs => f.write_str("no more key-value pairs for this psbt map"),
- UnexpectedUnsignedTx { expected: ref e, actual: ref a } => write!(
+ Self::NoMorePairs => f.write_str("no more key-value pairs for this psbt map"),
+ Self::UnexpectedUnsignedTx { expected: ref e, actual: ref a } => write!(
f,
"different unsigned transaction: expected {}, actual {}",
e.compute_txid(),
a.compute_txid()
),
- NonStandardSighashType(ref sht) => write!(f, "non-standard sighash type: {}", sht),
- InvalidHash(ref e) => write_err!(f, "invalid hash when parsing slice"; e),
- InvalidPreimageHashPair { ref preimage, ref hash, ref hash_type } => {
+ Self::NonStandardSighashType(ref sht) =>
+ write!(f, "non-standard sighash type: {}", sht),
+ Self::InvalidHash(ref e) => write_err!(f, "invalid hash when parsing slice"; e),
+ Self::InvalidPreimageHashPair { ref preimage, ref hash, ref hash_type } => {
// directly using debug forms of psbthash enums
write!(f, "Preimage {:?} does not match {:?} hash {:?}", preimage, hash_type, hash)
}
- CombineInconsistentKeySources(ref s) => {
+ Self::CombineInconsistentKeySources(ref s) => {
write!(f, "combine conflict: {}", s)
}
- ConsensusEncoding(ref e) => write_err!(f, "bitcoin consensus encoding error"; e),
- ConsensusDeserialize(ref e) =>
+ Self::ConsensusEncoding(ref e) => write_err!(f, "bitcoin consensus encoding error"; e),
+ Self::ConsensusDeserialize(ref e) =>
write_err!(f, "bitcoin consensus deserialization error"; e),
- ConsensusParse(ref e) =>
+ Self::ConsensusParse(ref e) =>
write_err!(f, "error parsing bitcoin consensus encoded object"; e),
- NegativeFee => f.write_str("PSBT has a negative fee which is not allowed"),
- FeeOverflow => f.write_str("integer overflow in fee calculation"),
- IncorrectNonWitnessUtxo { index, input_outpoint, non_witness_utxo_txid } => {
+ Self::NegativeFee => f.write_str("PSBT has a negative fee which is not allowed"),
+ Self::FeeOverflow => f.write_str("integer overflow in fee calculation"),
+ Self::IncorrectNonWitnessUtxo { index, input_outpoint, non_witness_utxo_txid } => {
write!(
f,
"non-witness utxo txid is {}, which does not match input {}'s outpoint {}",
non_witness_utxo_txid, index, input_outpoint
)
}
- InvalidPublicKey(ref e) => write_err!(f, "invalid public key"; e),
- InvalidSecp256k1PublicKey(ref e) => write_err!(f, "invalid secp256k1 public key"; e),
- InvalidXOnlyPublicKey => f.write_str("invalid xonly public key"),
- InvalidEcdsaSignature(ref e) => write_err!(f, "invalid ECDSA signature"; e),
- InvalidTaprootSignature(ref e) => write_err!(f, "invalid Taproot signature"; e),
- InvalidControlBlock => f.write_str("invalid control block"),
- InvalidLeafVersion => f.write_str("invalid leaf version"),
- Taproot(s) => write!(f, "Taproot error - {}", s),
- TapTree(ref e) => write_err!(f, "Taproot tree error"; e),
- XPubKey(s) => write!(f, "xpub key error - {}", s),
- Version(s) => write!(f, "version error {}", s),
- PartialDataConsumption =>
+ Self::InvalidPublicKey(ref e) => write_err!(f, "invalid public key"; e),
+ Self::InvalidSecp256k1PublicKey(ref e) =>
+ write_err!(f, "invalid secp256k1 public key"; e),
+ Self::InvalidXOnlyPublicKey => f.write_str("invalid xonly public key"),
+ Self::InvalidEcdsaSignature(ref e) => write_err!(f, "invalid ECDSA signature"; e),
+ Self::InvalidTaprootSignature(ref e) => write_err!(f, "invalid Taproot signature"; e),
+ Self::InvalidControlBlock => f.write_str("invalid control block"),
+ Self::InvalidLeafVersion => f.write_str("invalid leaf version"),
+ Self::Taproot(s) => write!(f, "Taproot error - {}", s),
+ Self::TapTree(ref e) => write_err!(f, "Taproot tree error"; e),
+ Self::XPubKey(s) => write!(f, "xpub key error - {}", s),
+ Self::Version(s) => write!(f, "version error {}", s),
+ Self::PartialDataConsumption =>
f.write_str("data not consumed entirely when explicitly deserializing"),
- Io(ref e) => write_err!(f, "I/O error"; e),
+ Self::Io(ref e) => write_err!(f, "I/O error"; e),
}
}
}
@@ -192,44 +193,42 @@ impl fmt::Display for Error {
#[cfg(feature = "std")]
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
- use Error::*;
-
- match *self {
- InvalidHash(ref e) => Some(e),
- ConsensusEncoding(ref e) => Some(e),
- ConsensusDeserialize(ref e) => Some(e),
- ConsensusParse(ref e) => Some(e),
- Io(ref e) => Some(e),
- InvalidMagic
- | MissingUtxo
- | InvalidSeparator
- | PsbtUtxoOutOfbounds
- | InvalidKey(_)
- | InvalidProprietaryKey
- | DuplicateKey(_)
- | UnsignedTxHasScriptSigs
- | UnsignedTxHasScriptWitnesses
- | MustHaveUnsignedTx
- | NoMorePairs
- | UnexpectedUnsignedTx { .. }
- | NonStandardSighashType(_)
- | InvalidPreimageHashPair { .. }
- | CombineInconsistentKeySources(_)
- | NegativeFee
- | FeeOverflow
- | IncorrectNonWitnessUtxo { .. }
- | InvalidPublicKey(_)
- | InvalidSecp256k1PublicKey(_)
- | InvalidXOnlyPublicKey
- | InvalidEcdsaSignature(_)
- | InvalidTaprootSignature(_)
- | InvalidControlBlock
- | InvalidLeafVersion
- | Taproot(_)
- | TapTree(_)
- | XPubKey(_)
- | Version(_)
- | PartialDataConsumption => None,
+ match self {
+ Self::InvalidHash(ref e) => Some(e),
+ Self::ConsensusEncoding(ref e) => Some(e),
+ Self::ConsensusDeserialize(ref e) => Some(e),
+ Self::ConsensusParse(ref e) => Some(e),
+ Self::Io(ref e) => Some(e),
+ Self::InvalidMagic
+ | Self::MissingUtxo
+ | Self::InvalidSeparator
+ | Self::PsbtUtxoOutOfbounds
+ | Self::InvalidKey(_)
+ | Self::InvalidProprietaryKey
+ | Self::DuplicateKey(_)
+ | Self::UnsignedTxHasScriptSigs
+ | Self::UnsignedTxHasScriptWitnesses
+ | Self::MustHaveUnsignedTx
+ | Self::NoMorePairs
+ | Self::UnexpectedUnsignedTx { .. }
+ | Self::NonStandardSighashType(_)
+ | Self::InvalidPreimageHashPair { .. }
+ | Self::CombineInconsistentKeySources(_)
+ | Self::NegativeFee
+ | Self::FeeOverflow
+ | Self::IncorrectNonWitnessUtxo { .. }
+ | Self::InvalidPublicKey(_)
+ | Self::InvalidSecp256k1PublicKey(_)
+ | Self::InvalidXOnlyPublicKey
+ | Self::InvalidEcdsaSignature(_)
+ | Self::InvalidTaprootSignature(_)
+ | Self::InvalidControlBlock
+ | Self::InvalidLeafVersion
+ | Self::Taproot(_)
+ | Self::TapTree(_)
+ | Self::XPubKey(_)
+ | Self::Version(_)
+ | Self::PartialDataConsumption => None,
}
}
}
diff --git a/bitcoin/src/psbt/mod.rs b/bitcoin/src/psbt/mod.rs
index faf9f35b..5f2bf9df 100644
--- a/bitcoin/src/psbt/mod.rs
+++ b/bitcoin/src/psbt/mod.rs
@@ -961,11 +961,9 @@ impl From<Infallible> for GetKeyError {
impl fmt::Display for GetKeyError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- use GetKeyError::*;
-
- match *self {
- Bip32(ref e) => write_err!(f, "bip32 derivation"; e),
- NotSupported =>
+ match self {
+ Self::Bip32(ref e) => write_err!(f, "bip32 derivation"; e),
+ Self::NotSupported =>
f.write_str("the GetKey operation is not supported for this key request"),
}
}
@@ -974,11 +972,9 @@ impl fmt::Display for GetKeyError {
#[cfg(feature = "std")]
impl std::error::Error for GetKeyError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
- use GetKeyError::*;
-
- match *self {
- NotSupported => None,
- Bip32(ref e) => Some(e),
+ match self {
+ Self::NotSupported => None,
+ Self::Bip32(ref e) => Some(e),
}
}
}
@@ -1072,26 +1068,25 @@ impl From<Infallible> for SignError {
impl fmt::Display for SignError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- use SignError::*;
-
- match *self {
- IndexOutOfBounds(ref e) => write_err!(f, "index out of bounds"; e),
- InvalidSighashType => write!(f, "invalid sighash type"),
- MissingInputUtxo => write!(f, "missing input utxo in PSBT"),
- MissingRedeemScript => write!(f, "missing redeem script"),
- MissingSpendUtxo => write!(f, "missing spend utxo in PSBT"),
- MissingWitnessScript => write!(f, "missing witness script"),
- MismatchedAlgoKey => write!(f, "signing algorithm and key type does not match"),
- NotEcdsa => write!(f, "attempted to ECDSA sign a non-ECDSA input"),
- NotWpkh => write!(f, "the scriptPubkey is not a P2WPKH script"),
- SegwitV0Sighash(ref e) => write_err!(f, "SegWit v0 sighash"; e),
- P2wpkhSighash(ref e) => write_err!(f, "p2wpkh sighash"; e),
- TaprootError(ref e) => write_err!(f, "Taproot sighash"; e),
- UnknownOutputType => write!(f, "unable to determine the output type"),
- KeyNotFound => write!(f, "unable to find key"),
- WrongSigningAlgorithm =>
+ match self {
+ Self::IndexOutOfBounds(ref e) => write_err!(f, "index out of bounds"; e),
+ Self::InvalidSighashType => write!(f, "invalid sighash type"),
+ Self::MissingInputUtxo => write!(f, "missing input utxo in PSBT"),
+ Self::MissingRedeemScript => write!(f, "missing redeem script"),
+ Self::MissingSpendUtxo => write!(f, "missing spend utxo in PSBT"),
+ Self::MissingWitnessScript => write!(f, "missing witness script"),
+ Self::MismatchedAlgoKey =>
+ write!(f, "signing algorithm and key type does not match"),
+ Self::NotEcdsa => write!(f, "attempted to ECDSA sign a non-ECDSA input"),
+ Self::NotWpkh => write!(f, "the scriptPubkey is not a P2WPKH script"),
+ Self::SegwitV0Sighash(ref e) => write_err!(f, "SegWit v0 sighash"; e),
+ Self::P2wpkhSighash(ref e) => write_err!(f, "p2wpkh sighash"; e),
+ Self::TaprootError(ref e) => write_err!(f, "Taproot sighash"; e),
+ Self::UnknownOutputType => write!(f, "unable to determine the output type"),
+ Self::KeyNotFound => write!(f, "unable to find key"),
+ Self::WrongSigningAlgorithm =>
write!(f, "attempt to sign an input with the wrong signing algorithm"),
- Unsupported => write!(f, "signing request currently unsupported"),
+ Self::Unsupported => write!(f, "signing request currently unsupported"),
}
}
}
@@ -1099,25 +1094,23 @@ impl fmt::Display for SignError {
#[cfg(feature = "std")]
impl std::error::Error for SignError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
- use SignError::*;
-
- match *self {
- SegwitV0Sighash(ref e) => Some(e),
- P2wpkhSighash(ref e) => Some(e),
- TaprootError(ref e) => Some(e),
- IndexOutOfBounds(ref e) => Some(e),
- InvalidSighashType
- | MissingInputUtxo
- | MissingRedeemScript
- | MissingSpendUtxo
- | MissingWitnessScript
- | MismatchedAlgoKey
- | NotEcdsa
- | NotWpkh
- | UnknownOutputType
- | KeyNotFound
- | WrongSigningAlgorithm
- | Unsupported => None,
+ match self {
+ Self::SegwitV0Sighash(ref e) => Some(e),
+ Self::P2wpkhSighash(ref e) => Some(e),
+ Self::TaprootError(ref e) => Some(e),
+ Self::IndexOutOfBounds(ref e) => Some(e),
+ Self::InvalidSighashType
+ | Self::MissingInputUtxo
+ | Self::MissingRedeemScript
+ | Self::MissingSpendUtxo
+ | Self::MissingWitnessScript
+ | Self::MismatchedAlgoKey
+ | Self::NotEcdsa
+ | Self::NotWpkh
+ | Self::UnknownOutputType
+ | Self::KeyNotFound
+ | Self::WrongSigningAlgorithm
+ | Self::Unsupported => None,
}
}
}
@@ -1163,19 +1156,17 @@ impl From<Infallible> for ExtractTxError {
impl fmt::Display for ExtractTxError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- use ExtractTxError::*;
-
- match *self {
- AbsurdFeeRate { fee_rate, .. } => write!(
+ match self {
+ Self::AbsurdFeeRate { fee_rate, .. } => write!(
f,
"an absurdly high fee rate of {} sat/kwu",
fee_rate.to_sat_per_kwu_floor()
),
- MissingInputAmount { .. } => write!(
+ Self::MissingInputAmount { .. } => write!(
f,
"one of the inputs lacked amount information (witness_utxo or non_witness_utxo)"
),
- SendingTooMuch { .. } => write!(
+ Self::SendingTooMuch { .. } => write!(
f,
"transaction would be invalid due to output amount being greater than input amount."
),
@@ -1186,10 +1177,10 @@ impl fmt::Display for ExtractTxError {
#[cfg(feature = "std")]
impl std::error::Error for ExtractTxError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
- use ExtractTxError::*;
-
- match *self {
- AbsurdFeeRate { .. } | MissingInputAmount { .. } | SendingTooMuch { .. } => None,
+ match self {
+ Self::AbsurdFeeRate { .. }
+ | Self::MissingInputAmount { .. }
+ | Self::SendingTooMuch { .. } => None,
}
}
}
@@ -1220,15 +1211,13 @@ impl From<Infallible> for IndexOutOfBoundsError {
impl fmt::Display for IndexOutOfBoundsError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- use IndexOutOfBoundsError::*;
-
- match *self {
- Inputs { ref index, ref length } => write!(
+ match self {
+ Self::Inputs { ref index, ref length } => write!(
f,
"index {} is out-of-bounds for PSBT inputs vector length {}",
index, length
),
- TxInput { ref index, ref length } => write!(
+ Self::TxInput { ref index, ref length } => write!(
f,
"index {} is out-of-bounds for PSBT unsigned tx input vector length {}",
index, length
@@ -1240,10 +1229,8 @@ impl fmt::Display for IndexOutOfBoundsError {
#[cfg(feature = "std")]
impl std::error::Error for IndexOutOfBoundsError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
- use IndexOutOfBoundsError::*;
-
- match *self {
- Inputs { .. } | TxInput { .. } => None,
+ match self {
+ Self::Inputs { .. } | Self::TxInput { .. } => None,
}
}
}
@@ -1276,11 +1263,10 @@ mod display_from_str {
impl fmt::Display for PsbtParseError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- use self::PsbtParseError::*;
-
- match *self {
- PsbtEncoding(ref e) => write_err!(f, "error in internal PSBT data structure"; e),
- Base64Encoding(ref e) => write_err!(f, "error in PSBT base64 encoding"; e),
+ match self {
+ Self::PsbtEncoding(ref e) =>
+ write_err!(f, "error in internal PSBT data structure"; e),
+ Self::Base64Encoding(ref e) => write_err!(f, "error in PSBT base64 encoding"; e),
}
}
}
@@ -1288,11 +1274,9 @@ mod display_from_str {
#[cfg(feature = "std")]
impl std::error::Error for PsbtParseError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
- use self::PsbtParseError::*;
-
match self {
- PsbtEncoding(e) => Some(e),
- Base64Encoding(e) => Some(e),
+ Self::PsbtEncoding(e) => Some(e),
+ Self::Base64Encoding(e) => Some(e),
}
}
}
diff --git a/bitcoin/src/psbt/serialize.rs b/bitcoin/src/psbt/serialize.rs
index 64833a48..819cfd91 100644
--- a/bitcoin/src/psbt/serialize.rs
+++ b/bitcoin/src/psbt/serialize.rs
@@ -304,12 +304,12 @@ impl Serialize for taproot::Signature {
impl Deserialize for taproot::Signature {
fn deserialize(bytes: &[u8]) -> Result<Self, Error> {
- use taproot::SigFromSliceError::*;
-
Self::from_slice(bytes).map_err(|e| match e {
- SighashType(err) => Error::NonStandardSighashType(err.0),
- InvalidSignatureSize(_) => Error::InvalidTaprootSignature(e),
- Secp256k1(..) => Error::InvalidTaprootSignature(e),
+ taproot::SigFromSliceError::SighashType(err) =>
+ Error::NonStandardSighashType(err.0),
+ taproot::SigFromSliceError::InvalidSignatureSize(_) =>
+ Error::InvalidTaprootSignature(e),
+ taproot::SigFromSliceError::Secp256k1(..) => Error::InvalidTaprootSignature(e),
})
}
}
diff --git a/bitcoin/src/sign_message.rs b/bitcoin/src/sign_message.rs
index 853ea565..4af5cf99 100644
--- a/bitcoin/src/sign_message.rs
+++ b/bitcoin/src/sign_message.rs
@@ -51,13 +51,11 @@ mod message_signing {
impl fmt::Display for MessageSignatureError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- use MessageSignatureError::*;
-
- match *self {
- InvalidLength => write!(f, "length not 65 bytes"),
- InvalidEncoding(ref e) => write_err!(f, "invalid encoding"; e),
- InvalidBase64 => write!(f, "invalid base64"),
- UnsupportedAddressType(ref address_type) =>
+ match self {
+ Self::InvalidLength => write!(f, "length not 65 bytes"),
+ Self::InvalidEncoding(ref e) => write_err!(f, "invalid encoding"; e),
+ Self::InvalidBase64 => write!(f, "invalid base64"),
+ Self::UnsupportedAddressType(ref address_type) =>
write!(f, "unsupported address type: {}", address_type),
}
}
@@ -66,11 +64,10 @@ mod message_signing {
#[cfg(feature = "std")]
impl std::error::Error for MessageSignatureError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
- use MessageSignatureError::*;
-
- match *self {
- InvalidEncoding(ref e) => Some(e),
- InvalidLength | InvalidBase64 | UnsupportedAddressType(_) => None,
+ match self {
+ Self::InvalidEncoding(ref e) => Some(e),
+ Self::InvalidLength | Self::InvalidBase64 | Self::UnsupportedAddressType(_) =>
+ None,
}
}
}
diff --git a/bitcoin/src/taproot/mod.rs b/bitcoin/src/taproot/mod.rs
index 24bf7fa6..3a282a6d 100644
--- a/bitcoin/src/taproot/mod.rs
+++ b/bitcoin/src/taproot/mod.rs
@@ -670,22 +670,18 @@ impl From<Infallible> for IncompleteBuilderError {
impl IncompleteBuilderError {
/// Converts error into the original incomplete [`TaprootBuilder`] instance.
pub fn into_builder(self) -> TaprootBuilder {
- use IncompleteBuilderError::*;
-
match self {
- NotFinalized(builder) | HiddenParts(builder) => builder,
+ Self::NotFinalized(builder) | Self::HiddenParts(builder) => builder,
}
}
}
impl core::fmt::Display for IncompleteBuilderError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
- use IncompleteBuilderError::*;
-
f.write_str(match self {
- NotFinalized(_) =>
+ Self::NotFinalized(_) =>
"an attempt to construct a Taproot tree from a builder containing incomplete branches",
- HiddenParts(_) =>
+ Self::HiddenParts(_) =>
"an attempt to construct a Taproot tree from a builder containing hidden parts",
})
}
@@ -694,10 +690,8 @@ impl core::fmt::Display for IncompleteBuilderError {
#[cfg(feature = "std")]
impl std::error::Error for IncompleteBuilderError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
- use IncompleteBuilderError::*;
-
- match *self {
- NotFinalized(_) | HiddenParts(_) => None,
+ match self {
+ Self::NotFinalized(_) | Self::HiddenParts(_) => None,
}
}
}
@@ -718,20 +712,16 @@ impl From<Infallible> for HiddenNodesError {
impl HiddenNodesError {
/// Converts error into the original incomplete [`NodeInfo`] instance.
pub fn into_node_info(self) -> NodeInfo {
- use HiddenNodesError::*;
-
match self {
- HiddenParts(node_info) => node_info,
+ Self::HiddenParts(node_info) => node_info,
}
}
}
impl core::fmt::Display for HiddenNodesError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
- use HiddenNodesError::*;
-
f.write_str(match self {
- HiddenParts(_) =>
+ Self::HiddenParts(_) =>
"an attempt to construct a Taproot tree from a node_info containing hidden parts",
})
}
@@ -740,10 +730,8 @@ impl core::fmt::Display for HiddenNodesError {
#[cfg(feature = "std")]
impl std::error::Error for HiddenNodesError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
- use HiddenNodesError::*;
-
match self {
- HiddenParts(_) => None,
+ Self::HiddenParts(_) => None,
}
}
}
@@ -1477,19 +1465,17 @@ impl From<Infallible> for TaprootBuilderError {
impl fmt::Display for TaprootBuilderError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- use TaprootBuilderError::*;
-
- match *self {
- InvalidMerkleTreeDepth(ref e) => write_err!(f, "invalid Merkle tree depth"; e),
- NodeNotInDfsOrder => {
+ match self {
+ Self::InvalidMerkleTreeDepth(ref e) => write_err!(f, "invalid Merkle tree depth"; e),
+ Self::NodeNotInDfsOrder => {
write!(f, "add_leaf/add_hidden must be called in DFS walk order",)
}
- OverCompleteTree => write!(
+ Self::OverCompleteTree => write!(
f,
"attempted to create a tree with two nodes at depth 0. There must\
only be exactly one node at depth 0",
),
- EmptyTree => {
+ Self::EmptyTree => {
write!(f, "called finalize on an empty tree")
}
}
@@ -1499,11 +1485,9 @@ impl fmt::Display for TaprootBuilderError {
#[cfg(feature = "std")]
impl std::error::Error for TaprootBuilderError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
- use TaprootBuilderError::*;
-
- match *self {
- InvalidMerkleTreeDepth(ref e) => Some(e),
- NodeNotInDfsOrder | OverCompleteTree | EmptyTree => None,
+ match self {
+ Self::InvalidMerkleTreeDepth(ref e) => Some(e),
+ Self::NodeNotInDfsOrder | Self::OverCompleteTree | Self::EmptyTree => None,
}
}
}
@@ -1537,15 +1521,13 @@ impl From<Infallible> for TaprootError {
impl fmt::Display for TaprootError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- use TaprootError::*;
-
- match *self {
- InvalidMerkleBranchSize(ref e) => write_err!(f, "invalid Merkle branch size"; e),
- InvalidMerkleTreeDepth(ref e) => write_err!(f, "invalid Merkle tree depth"; e),
- InvalidTaprootLeafVersion(ref e) => write_err!(f, "invalid Taproot leaf version"; e),
- InvalidControlBlockSize(ref e) => write_err!(f, "invalid control block size"; e),
- InvalidControlBlockHex(ref e) => write_err!(f, "invalid control block hex"; e),
- InvalidInternalKey(ref e) => write_err!(f, "invalid internal x-only key"; e),
+ match self {
+ Self::InvalidMerkleBranchSize(ref e) => write_err!(f, "invalid Merkle branch size"; e),
+ Self::InvalidMerkleTreeDepth(ref e) => write_err!(f, "invalid Merkle tree depth"; e),
+ Self::InvalidTaprootLeafVersion(ref e) => write_err!(f, "invalid Taproot leaf version"; e),
+ Self::InvalidControlBlockSize(ref e) => write_err!(f, "invalid control block size"; e),
+ Self::InvalidControlBlockHex(ref e) => write_err!(f, "invalid control block hex"; e),
+ Self::InvalidInternalKey(ref e) => write_err!(f, "invalid internal x-only key"; e),
}
}
}
@@ -1553,14 +1535,12 @@ impl fmt::Display for TaprootError {
#[cfg(feature = "std")]
impl std::error::Error for TaprootError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
- use TaprootError::*;
-
match self {
- InvalidInternalKey(e) => Some(e),
- InvalidTaprootLeafVersion(ref e) => Some(e),
- InvalidMerkleTreeDepth(ref e) => Some(e),
- InvalidControlBlockHex(ref e) => Some(e),
- InvalidMerkleBranchSize(_) | InvalidControlBlockSize(_) => None,
+ Self::InvalidInternalKey(e) => Some(e),
+ Self::InvalidTaprootLeafVersion(ref e) => Some(e),
+ Self::InvalidMerkleTreeDepth(ref e) => Some(e),
+ Self::InvalidControlBlockHex(ref e) => Some(e),
+ Self::InvalidMerkleBranchSize(_) | Self::InvalidControlBlockSize(_) => None,
}
}
}
diff --git a/units/src/amount/tests.rs b/units/src/amount/tests.rs
index 37e0770a..8c7a938c 100644
--- a/units/src/amount/tests.rs
+++ b/units/src/amount/tests.rs
@@ -661,8 +661,7 @@ fn unsigned_signed_conversion() {
#[allow(clippy::inconsistent_digit_grouping)] // Group to show 100,000,000 sats per bitcoin.
#[allow(clippy::items_after_statements)] // Define functions where we use them.
fn from_str() {
- use ParseDenominationError::*;
-
+ use super::ParseDenominationError;
use super::ParseAmountError as E;
assert_eq!(
@@ -671,11 +670,11 @@ fn from_str() {
);
assert_eq!(
"xBTC".parse::<Amount>(),
- Err(Unknown(UnknownDenominationError("xBTC".into())).into()),
+ Err(ParseDenominationError::Unknown(UnknownDenominationError("xBTC".into())).into()),
);
assert_eq!(
"5 BTC BTC".parse::<Amount>(),
- Err(Unknown(UnknownDenominationError("BTC BTC".into())).into()),
+ Err(ParseDenominationError::Unknown(UnknownDenominationError("BTC BTC".into())).into()),
);
assert_eq!(
"5BTC BTC".parse::<Amount>(),
@@ -683,7 +682,7 @@ fn from_str() {
);
assert_eq!(
"5 5 BTC".parse::<Amount>(),
- Err(Unknown(UnknownDenominationError("5 BTC".into())).into()),
+ Err(ParseDenominationError::Unknown(UnknownDenominationError("5 BTC".into())).into()),
);
#[track_caller]
@@ -712,7 +711,10 @@ fn from_str() {
assert_eq!(s.replace(' ', "").parse::<SignedAmount>(), expected);
}
- case("5 BCH", Err(Unknown(UnknownDenominationError("BCH".into()))));
+ case(
+ "5 BCH",
+ Err(ParseDenominationError::Unknown(UnknownDenominationError("BCH".into()))),
+ );
case("-1 BTC", Err(OutOfRangeError::negative()));
case("-0.0 BTC", Err(OutOfRangeError::negative()));
@@ -818,8 +820,7 @@ fn to_from_string_in() {
#[cfg(feature = "alloc")]
#[test]
fn to_string_with_denomination_from_str_roundtrip() {
- use ParseDenominationError::*;
-
+ use super::ParseDenominationError;
use super::Denomination as D;
let amt = sat(42);
@@ -833,11 +834,17 @@ fn to_string_with_denomination_from_str_roundtrip() {
assert_eq!(
"42 satoshi BTC".parse::<Amount>(),
- Err(Unknown(UnknownDenominationError("satoshi BTC".into())).into()),
+ Err(
+ ParseDenominationError::Unknown(UnknownDenominationError("satoshi BTC".into()))
+ .into(),
+ ),
);
assert_eq!(
"-42 satoshi BTC".parse::<SignedAmount>(),
- Err(Unknown(UnknownDenominationError("satoshi BTC".into())).into()),
+ Err(
+ ParseDenominationError::Unknown(UnknownDenominationError("satoshi BTC".into()))
+ .into(),
+ ),
);
}
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.