Merge rust-bitcoin/rust-bitcoin#625: Improvements to Error types (part 4)
994079b099
Refactoring error variants: removing unused; better names & inner types (Dr Maxim Orlovsky) Pull request description: Removes controversial aspects from #560 (all `io::Error`-related changes) and leaves the rest ACKs for top commit: sanket1729: ACK994079b099
apoelstra: ACK994079b099
Tree-SHA512: 020e49193c885e862f45e5f7baabf1d22a3ec09e78fd7f573b2f3d327beb4f91683951ba080b3d804e8337a188dcad0f38ba70ee8059aef0681a0b2bba0a2140
This commit is contained in:
commit
13a6c3b4d6
|
@ -429,7 +429,7 @@ pub enum Error {
|
||||||
/// A pk->pk derivation was attempted on a hardened key
|
/// A pk->pk derivation was attempted on a hardened key
|
||||||
CannotDeriveFromHardenedKey,
|
CannotDeriveFromHardenedKey,
|
||||||
/// A secp256k1 error occurred
|
/// A secp256k1 error occurred
|
||||||
Ecdsa(secp256k1::Error), // TODO: This is not necessary ECDSA error and should be renamed
|
Secp256k1(secp256k1::Error),
|
||||||
/// A child number was provided that was out of range
|
/// A child number was provided that was out of range
|
||||||
InvalidChildNumber(u32),
|
InvalidChildNumber(u32),
|
||||||
/// Invalid childnumber format.
|
/// Invalid childnumber format.
|
||||||
|
@ -448,7 +448,7 @@ impl fmt::Display for Error {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
match *self {
|
match *self {
|
||||||
Error::CannotDeriveFromHardenedKey => f.write_str("cannot derive hardened key from public key"),
|
Error::CannotDeriveFromHardenedKey => f.write_str("cannot derive hardened key from public key"),
|
||||||
Error::Ecdsa(ref e) => fmt::Display::fmt(e, f),
|
Error::Secp256k1(ref e) => fmt::Display::fmt(e, f),
|
||||||
Error::InvalidChildNumber(ref n) => write!(f, "child number {} is invalid (not within [0, 2^31 - 1])", n),
|
Error::InvalidChildNumber(ref n) => write!(f, "child number {} is invalid (not within [0, 2^31 - 1])", n),
|
||||||
Error::InvalidChildNumberFormat => f.write_str("invalid child number format"),
|
Error::InvalidChildNumberFormat => f.write_str("invalid child number format"),
|
||||||
Error::InvalidDerivationPathFormat => f.write_str("invalid derivation path format"),
|
Error::InvalidDerivationPathFormat => f.write_str("invalid derivation path format"),
|
||||||
|
@ -462,7 +462,7 @@ impl fmt::Display for Error {
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
impl error::Error for Error {
|
impl error::Error for Error {
|
||||||
fn cause(&self) -> Option<&dyn error::Error> {
|
fn cause(&self) -> Option<&dyn error::Error> {
|
||||||
if let Error::Ecdsa(ref e) = *self {
|
if let Error::Secp256k1(ref e) = *self {
|
||||||
Some(e)
|
Some(e)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
@ -474,13 +474,13 @@ impl From<key::Error> for Error {
|
||||||
fn from(err: key::Error) -> Self {
|
fn from(err: key::Error) -> Self {
|
||||||
match err {
|
match err {
|
||||||
key::Error::Base58(e) => Error::Base58(e),
|
key::Error::Base58(e) => Error::Base58(e),
|
||||||
key::Error::Secp256k1(e) => Error::Ecdsa(e),
|
key::Error::Secp256k1(e) => Error::Secp256k1(e),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<secp256k1::Error> for Error {
|
impl From<secp256k1::Error> for Error {
|
||||||
fn from(e: secp256k1::Error) -> Error { Error::Ecdsa(e) }
|
fn from(e: secp256k1::Error) -> Error { Error::Secp256k1(e) }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<base58::Error> for Error {
|
impl From<base58::Error> for Error {
|
||||||
|
|
|
@ -21,6 +21,7 @@ use consensus::encode;
|
||||||
use util::psbt::raw;
|
use util::psbt::raw;
|
||||||
|
|
||||||
use hashes;
|
use hashes;
|
||||||
|
use util::bip32::ExtendedPubKey;
|
||||||
|
|
||||||
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
|
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
|
||||||
/// Enum for marking psbt hash error
|
/// Enum for marking psbt hash error
|
||||||
|
@ -73,8 +74,9 @@ pub enum Error {
|
||||||
/// Hash value
|
/// Hash value
|
||||||
hash: Box<[u8]>,
|
hash: Box<[u8]>,
|
||||||
},
|
},
|
||||||
/// Data inconsistency/conflicting data during merge procedure
|
/// Conflicting data during merge procedure:
|
||||||
MergeConflict(String),
|
/// global extended public key has inconsistent key sources
|
||||||
|
MergeInconsistentKeySources(ExtendedPubKey),
|
||||||
/// Serialization error in bitcoin consensus-encoded structures
|
/// Serialization error in bitcoin consensus-encoded structures
|
||||||
ConsensusEncoding,
|
ConsensusEncoding,
|
||||||
}
|
}
|
||||||
|
@ -100,7 +102,7 @@ impl fmt::Display for Error {
|
||||||
// directly using debug forms of psbthash enums
|
// directly using debug forms of psbthash enums
|
||||||
write!(f, "Preimage {:?} does not match {:?} hash {:?}", preimage, hash_type, hash )
|
write!(f, "Preimage {:?} does not match {:?} hash {:?}", preimage, hash_type, hash )
|
||||||
}
|
}
|
||||||
Error::MergeConflict(ref s) => { write!(f, "Merge conflict: {}", s) }
|
Error::MergeInconsistentKeySources(ref s) => { write!(f, "merge conflict: {}", s) }
|
||||||
Error::ConsensusEncoding => f.write_str("bitcoin consensus or BIP-174 encoding error"),
|
Error::ConsensusEncoding => f.write_str("bitcoin consensus or BIP-174 encoding error"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -213,9 +213,7 @@ impl Map for Global {
|
||||||
entry.insert((fingerprint1, derivation1));
|
entry.insert((fingerprint1, derivation1));
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
return Err(psbt::Error::MergeConflict(format!(
|
return Err(psbt::Error::MergeInconsistentKeySources(xpub));
|
||||||
"global xpub {} has inconsistent key sources", xpub
|
|
||||||
)));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue