From 482c8cb7f8e172091dba1592ef49fbc415f33987 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Tue, 6 Feb 2024 12:48:22 +1100 Subject: [PATCH 1/2] Clean up error type from impls Make the `From` impls conform to our convention. Refactor only, no logic changes. --- bitcoin/src/crypto/ecdsa.rs | 6 +++--- bitcoin/src/crypto/key.rs | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/bitcoin/src/crypto/ecdsa.rs b/bitcoin/src/crypto/ecdsa.rs index aaf8046a..fd5cb4ae 100644 --- a/bitcoin/src/crypto/ecdsa.rs +++ b/bitcoin/src/crypto/ecdsa.rs @@ -241,15 +241,15 @@ impl std::error::Error for Error { } impl From for Error { - fn from(e: secp256k1::Error) -> Error { Error::Secp256k1(e) } + fn from(e: secp256k1::Error) -> Self { Self::Secp256k1(e) } } impl From for Error { - fn from(err: NonStandardSighashTypeError) -> Self { Error::SighashType(err) } + fn from(e: NonStandardSighashTypeError) -> Self { Self::SighashType(e) } } impl From for Error { - fn from(err: hex::HexToBytesError) -> Self { Error::Hex(err) } + fn from(e: hex::HexToBytesError) -> Self { Self::Hex(e) } } #[cfg(test)] diff --git a/bitcoin/src/crypto/key.rs b/bitcoin/src/crypto/key.rs index 364a946c..4bc8b3fb 100644 --- a/bitcoin/src/crypto/key.rs +++ b/bitcoin/src/crypto/key.rs @@ -921,7 +921,7 @@ impl std::error::Error for FromSliceError { } impl From for FromSliceError { - fn from(e: secp256k1::Error) -> FromSliceError { Self::Secp256k1(e) } + fn from(e: secp256k1::Error) -> Self { Self::Secp256k1(e) } } /// Error generated from WIF key format. @@ -956,11 +956,11 @@ impl std::error::Error for FromWifError { } impl From for FromWifError { - fn from(e: base58::Error) -> FromWifError { Self::Base58(e) } + fn from(e: base58::Error) -> Self { Self::Base58(e) } } impl From for FromWifError { - fn from(e: secp256k1::Error) -> FromWifError { Self::Secp256k1(e) } + fn from(e: secp256k1::Error) -> Self { Self::Secp256k1(e) } } /// Error returned while constructing public key from string. @@ -1033,11 +1033,11 @@ impl std::error::Error for ParseCompressedPublicKeyError { } impl From for ParseCompressedPublicKeyError { - fn from(e: secp256k1::Error) -> ParseCompressedPublicKeyError { Self::Secp256k1(e) } + fn from(e: secp256k1::Error) -> Self { Self::Secp256k1(e) } } impl From for ParseCompressedPublicKeyError { - fn from(e: hex::HexToArrayError) -> ParseCompressedPublicKeyError { Self::HexError(e) } + fn from(e: hex::HexToArrayError) -> Self { Self::HexError(e) } } /// Segwit public keys must always be compressed. From 86f8043e801c624731673283a3ee27c6b88edbd2 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Mon, 12 Feb 2024 13:25:38 +1100 Subject: [PATCH 2/2] Remove Error suffix from variant We do not use a suffix on error variants, remove it. --- bitcoin/src/crypto/key.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bitcoin/src/crypto/key.rs b/bitcoin/src/crypto/key.rs index 4bc8b3fb..fd363813 100644 --- a/bitcoin/src/crypto/key.rs +++ b/bitcoin/src/crypto/key.rs @@ -1007,7 +1007,7 @@ pub enum ParseCompressedPublicKeyError { /// Secp256k1 Error. Secp256k1(secp256k1::Error), /// hex to array conversion error. - HexError(hex::HexToArrayError), + Hex(hex::HexToArrayError), } impl fmt::Display for ParseCompressedPublicKeyError { @@ -1015,7 +1015,7 @@ impl fmt::Display for ParseCompressedPublicKeyError { use ParseCompressedPublicKeyError::*; match self { Secp256k1(e) => write_err!(f, "secp256k1 error"; e), - HexError(e) => write_err!(f, "invalid hex"; e) + Hex(e) => write_err!(f, "invalid hex"; e) } } } @@ -1027,7 +1027,7 @@ impl std::error::Error for ParseCompressedPublicKeyError { match self { Secp256k1(e) => Some(e), - HexError(e) => Some(e), + Hex(e) => Some(e), } } } @@ -1037,7 +1037,7 @@ impl From for ParseCompressedPublicKeyError { } impl From for ParseCompressedPublicKeyError { - fn from(e: hex::HexToArrayError) -> Self { Self::HexError(e) } + fn from(e: hex::HexToArrayError) -> Self { Self::Hex(e) } } /// Segwit public keys must always be compressed.