Skip to content

Commit 15545a5

Browse files
committed
Refactoring error variants: removing unused; better names & inner types
1 parent abff973 commit 15545a5

3 files changed

Lines changed: 11 additions & 11 deletions

File tree

src/util/bip32.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ pub enum Error {
427427
/// A pk->pk derivation was attempted on a hardened key
428428
CannotDeriveFromHardenedKey,
429429
/// A secp256k1 error occurred
430-
Ecdsa(secp256k1::Error), // TODO: This is not necessary ECDSA error and should be renamed
430+
Secp256k1(secp256k1::Error),
431431
/// A child number was provided that was out of range
432432
InvalidChildNumber(u32),
433433
/// Invalid childnumber format.
@@ -446,7 +446,7 @@ impl fmt::Display for Error {
446446
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
447447
match *self {
448448
Error::CannotDeriveFromHardenedKey => f.write_str("cannot derive hardened key from public key"),
449-
Error::Ecdsa(ref e) => fmt::Display::fmt(e, f),
449+
Error::Secp256k1(ref e) => fmt::Display::fmt(e, f),
450450
Error::InvalidChildNumber(ref n) => write!(f, "child number {} is invalid (not within [0, 2^31 - 1])", n),
451451
Error::InvalidChildNumberFormat => f.write_str("invalid child number format"),
452452
Error::InvalidDerivationPathFormat => f.write_str("invalid derivation path format"),
@@ -459,7 +459,7 @@ impl fmt::Display for Error {
459459

460460
impl error::Error for Error {
461461
fn cause(&self) -> Option<&dyn error::Error> {
462-
if let Error::Ecdsa(ref e) = *self {
462+
if let Error::Secp256k1(ref e) = *self {
463463
Some(e)
464464
} else {
465465
None
@@ -471,13 +471,13 @@ impl From<key::Error> for Error {
471471
fn from(err: key::Error) -> Self {
472472
match err {
473473
key::Error::Base58(e) => Error::Base58(e),
474-
key::Error::Secp256k1(e) => Error::Ecdsa(e),
474+
key::Error::Secp256k1(e) => Error::Secp256k1(e),
475475
}
476476
}
477477
}
478478

479479
impl From<secp256k1::Error> for Error {
480-
fn from(e: secp256k1::Error) -> Error { Error::Ecdsa(e) }
480+
fn from(e: secp256k1::Error) -> Error { Error::Secp256k1(e) }
481481
}
482482

483483
impl From<base58::Error> for Error {

src/util/psbt/error.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use consensus::encode;
2020
use util::psbt::raw;
2121

2222
use hashes;
23+
use util::bip32::ExtendedPubKey;
2324

2425
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
2526
/// Enum for marking psbt hash error
@@ -72,8 +73,9 @@ pub enum Error {
7273
/// Hash value
7374
hash: Box<[u8]>,
7475
},
75-
/// Data inconsistency/conflicting data during merge procedure
76-
MergeConflict(String),
76+
/// Conflicting data during merge procedure:
77+
/// global extended public key has inconsistent key sources
78+
MergeInconsistentKeySources(ExtendedPubKey),
7779
/// Serialization error in bitcoin consensus-encoded structures
7880
ConsensusEncoding,
7981
}
@@ -99,7 +101,7 @@ impl fmt::Display for Error {
99101
// directly using debug forms of psbthash enums
100102
write!(f, "Preimage {:?} does not match {:?} hash {:?}", preimage, hash_type, hash )
101103
}
102-
Error::MergeConflict(ref s) => { write!(f, "Merge conflict: {}", s) }
104+
Error::MergeInconsistentKeySources(ref s) => { write!(f, "merge conflict: {}", s) }
103105
Error::ConsensusEncoding => f.write_str("bitcoin consensus or BIP-174 encoding error"),
104106
}
105107
}

src/util/psbt/map/global.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,7 @@ impl Map for Global {
213213
entry.insert((fingerprint1, derivation1));
214214
continue
215215
}
216-
return Err(psbt::Error::MergeConflict(format!(
217-
"global xpub {} has inconsistent key sources", xpub
218-
).to_owned()));
216+
return Err(psbt::Error::MergeInconsistentKeySources(xpub));
219217
}
220218
}
221219
}

0 commit comments

Comments
 (0)