Make error types uniform
On our way to v1.0.0 we are defining a standard for our error types, this includes: - Uses the following derives (unless not possible, usually because of `io::Error`) `#[derive(Debug, Clone, PartialEq, Eq)]` - Has `non_exhaustive` unless we really know we can commit to not adding anything. Furthermore, we are trying to make the codebase easy to read. Error code is write-once-read-many (well it should be) so if we make all the error code super uniform the users can flick to an error and quickly see what it includes. In an effort to achieve this I have made up a style and over recent times have change much of the error code to that new style, this PR audits _all_ error types in the code base and enforces the style, specifically: - Is layed out: definition, [impl block], Display impl, error::Error impl, From impls - `error::Error` impl matches on enum even if it returns `None` for all variants - Display/Error impls import enum variants locally - match uses *self and `ref e` - error::Error variants that return `Some` come first, `None` after Re: non_exhaustive To make dev and review easier I have added `non_exhaustive` to _every_ error type. We can then remove it error by error as we see fit. This is because it takes a bit of thinking to do and review where as this patch should not take much brain power to review.
This commit is contained in:
parent
43d3306822
commit
10374af75c
|
@ -82,6 +82,7 @@ impl From<witness_program::Error> for Error {
|
||||||
|
|
||||||
/// Address type is either invalid or not supported in rust-bitcoin.
|
/// Address type is either invalid or not supported in rust-bitcoin.
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
|
#[non_exhaustive]
|
||||||
pub struct UnknownAddressTypeError(pub String);
|
pub struct UnknownAddressTypeError(pub String);
|
||||||
|
|
||||||
impl fmt::Display for UnknownAddressTypeError {
|
impl fmt::Display for UnknownAddressTypeError {
|
||||||
|
@ -96,7 +97,7 @@ impl std::error::Error for UnknownAddressTypeError {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Address parsing error.
|
/// Address parsing error.
|
||||||
#[derive(Debug, PartialEq, Eq, Clone)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
#[non_exhaustive]
|
#[non_exhaustive]
|
||||||
pub enum ParseError {
|
pub enum ParseError {
|
||||||
/// Base58 error.
|
/// Base58 error.
|
||||||
|
|
|
@ -160,16 +160,17 @@ pub enum ParseAmountError {
|
||||||
|
|
||||||
impl fmt::Display for ParseAmountError {
|
impl fmt::Display for ParseAmountError {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
use ParseAmountError::*;
|
||||||
|
|
||||||
match *self {
|
match *self {
|
||||||
ParseAmountError::Negative => f.write_str("amount is negative"),
|
Negative => f.write_str("amount is negative"),
|
||||||
ParseAmountError::TooBig => f.write_str("amount is too big"),
|
TooBig => f.write_str("amount is too big"),
|
||||||
ParseAmountError::TooPrecise => f.write_str("amount has a too high precision"),
|
TooPrecise => f.write_str("amount has a too high precision"),
|
||||||
ParseAmountError::InvalidFormat => f.write_str("invalid number format"),
|
InvalidFormat => f.write_str("invalid number format"),
|
||||||
ParseAmountError::InputTooLarge => f.write_str("input string was too large"),
|
InputTooLarge => f.write_str("input string was too large"),
|
||||||
ParseAmountError::InvalidCharacter(c) => write!(f, "invalid character in input: {}", c),
|
InvalidCharacter(c) => write!(f, "invalid character in input: {}", c),
|
||||||
ParseAmountError::UnknownDenomination(ref d) =>
|
UnknownDenomination(ref d) => write!(f, "unknown denomination: {}", d),
|
||||||
write!(f, "unknown denomination: {}", d),
|
PossiblyConfusingDenomination(ref d) => {
|
||||||
ParseAmountError::PossiblyConfusingDenomination(ref d) => {
|
|
||||||
let (letter, upper, lower) = match d.chars().next() {
|
let (letter, upper, lower) = match d.chars().next() {
|
||||||
Some('M') => ('M', "Mega", "milli"),
|
Some('M') => ('M', "Mega", "milli"),
|
||||||
Some('P') => ('P', "Peta", "pico"),
|
Some('P') => ('P', "Peta", "pico"),
|
||||||
|
@ -185,7 +186,7 @@ impl fmt::Display for ParseAmountError {
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
impl std::error::Error for ParseAmountError {
|
impl std::error::Error for ParseAmountError {
|
||||||
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
||||||
use self::ParseAmountError::*;
|
use ParseAmountError::*;
|
||||||
|
|
||||||
match *self {
|
match *self {
|
||||||
Negative
|
Negative
|
||||||
|
|
|
@ -213,16 +213,18 @@ pub enum Error {
|
||||||
|
|
||||||
impl fmt::Display for Error {
|
impl fmt::Display for Error {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
use Error::*;
|
||||||
|
|
||||||
match *self {
|
match *self {
|
||||||
Error::BadByte(b) => write!(f, "invalid base58 character {:#x}", b),
|
BadByte(b) => write!(f, "invalid base58 character {:#x}", b),
|
||||||
Error::BadChecksum(exp, actual) =>
|
BadChecksum(exp, actual) =>
|
||||||
write!(f, "base58ck checksum {:#x} does not match expected {:#x}", actual, exp),
|
write!(f, "base58ck checksum {:#x} does not match expected {:#x}", actual, exp),
|
||||||
Error::InvalidLength(ell) => write!(f, "length {} invalid for this base58 type", ell),
|
InvalidLength(ell) => write!(f, "length {} invalid for this base58 type", ell),
|
||||||
Error::InvalidExtendedKeyVersion(ref v) =>
|
InvalidExtendedKeyVersion(ref v) =>
|
||||||
write!(f, "extended key version {:#04x?} is invalid for this base58 type", v),
|
write!(f, "extended key version {:#04x?} is invalid for this base58 type", v),
|
||||||
Error::InvalidAddressVersion(ref v) =>
|
InvalidAddressVersion(ref v) =>
|
||||||
write!(f, "address version {} is invalid for this base58 type", v),
|
write!(f, "address version {} is invalid for this base58 type", v),
|
||||||
Error::TooShort(_) => write!(f, "base58ck data not even long enough for a checksum"),
|
TooShort(_) => write!(f, "base58ck data not even long enough for a checksum"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -230,7 +232,7 @@ impl fmt::Display for Error {
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
impl std::error::Error for Error {
|
impl std::error::Error for Error {
|
||||||
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
||||||
use self::Error::*;
|
use Error::*;
|
||||||
|
|
||||||
match self {
|
match self {
|
||||||
BadByte(_)
|
BadByte(_)
|
||||||
|
|
|
@ -314,7 +314,8 @@ impl Decodable for BlockTransactionsRequest {
|
||||||
|
|
||||||
/// A transaction index is requested that is out of range from the
|
/// A transaction index is requested that is out of range from the
|
||||||
/// corresponding block.
|
/// corresponding block.
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
|
#[non_exhaustive]
|
||||||
pub struct TxIndexOutOfRangeError(u64);
|
pub struct TxIndexOutOfRangeError(u64);
|
||||||
|
|
||||||
impl fmt::Display for TxIndexOutOfRangeError {
|
impl fmt::Display for TxIndexOutOfRangeError {
|
||||||
|
|
|
@ -70,9 +70,11 @@ pub enum Error {
|
||||||
|
|
||||||
impl Display for Error {
|
impl Display for Error {
|
||||||
fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> {
|
fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> {
|
||||||
|
use Error::*;
|
||||||
|
|
||||||
match *self {
|
match *self {
|
||||||
Error::UtxoMissing(ref coin) => write!(f, "unresolved UTXO {}", coin),
|
UtxoMissing(ref coin) => write!(f, "unresolved UTXO {}", coin),
|
||||||
Error::Io(ref e) => write_err!(f, "IO error"; e),
|
Io(ref e) => write_err!(f, "IO error"; e),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -80,11 +82,11 @@ impl Display for Error {
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
impl std::error::Error for Error {
|
impl std::error::Error for Error {
|
||||||
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
||||||
use self::Error::*;
|
use Error::*;
|
||||||
|
|
||||||
match self {
|
match *self {
|
||||||
UtxoMissing(_) => None,
|
UtxoMissing(_) => None,
|
||||||
Io(e) => Some(e),
|
Io(ref e) => Some(e),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -494,21 +494,22 @@ pub enum Error {
|
||||||
|
|
||||||
impl fmt::Display for Error {
|
impl fmt::Display for Error {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
use Error::*;
|
||||||
|
|
||||||
match *self {
|
match *self {
|
||||||
Error::CannotDeriveFromHardenedKey =>
|
CannotDeriveFromHardenedKey =>
|
||||||
f.write_str("cannot derive hardened key from public key"),
|
f.write_str("cannot derive hardened key from public key"),
|
||||||
Error::Secp256k1(ref e) => write_err!(f, "secp256k1 error"; e),
|
Secp256k1(ref e) => write_err!(f, "secp256k1 error"; e),
|
||||||
Error::InvalidChildNumber(ref n) =>
|
InvalidChildNumber(ref n) =>
|
||||||
write!(f, "child number {} is invalid (not within [0, 2^31 - 1])", n),
|
write!(f, "child number {} is invalid (not within [0, 2^31 - 1])", n),
|
||||||
Error::InvalidChildNumberFormat => f.write_str("invalid child number format"),
|
InvalidChildNumberFormat => f.write_str("invalid child number format"),
|
||||||
Error::InvalidDerivationPathFormat => f.write_str("invalid derivation path format"),
|
InvalidDerivationPathFormat => f.write_str("invalid derivation path format"),
|
||||||
Error::UnknownVersion(ref bytes) =>
|
UnknownVersion(ref bytes) => write!(f, "unknown version magic bytes: {:?}", bytes),
|
||||||
write!(f, "unknown version magic bytes: {:?}", bytes),
|
WrongExtendedKeyLength(ref len) =>
|
||||||
Error::WrongExtendedKeyLength(ref len) =>
|
|
||||||
write!(f, "encoded extended key data has wrong length {}", len),
|
write!(f, "encoded extended key data has wrong length {}", len),
|
||||||
Error::Base58(ref e) => write_err!(f, "base58 encoding error"; e),
|
Base58(ref e) => write_err!(f, "base58 encoding error"; e),
|
||||||
Error::Hex(ref e) => write_err!(f, "Hexadecimal decoding error"; e),
|
Hex(ref e) => write_err!(f, "Hexadecimal decoding error"; e),
|
||||||
Error::InvalidPublicKeyHexLength(got) =>
|
InvalidPublicKeyHexLength(got) =>
|
||||||
write!(f, "PublicKey hex should be 66 or 130 digits long, got: {}", got),
|
write!(f, "PublicKey hex should be 66 or 130 digits long, got: {}", got),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -517,12 +518,12 @@ impl fmt::Display for Error {
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
impl std::error::Error for Error {
|
impl std::error::Error for Error {
|
||||||
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
||||||
use self::Error::*;
|
use Error::*;
|
||||||
|
|
||||||
match self {
|
match *self {
|
||||||
Secp256k1(e) => Some(e),
|
Secp256k1(ref e) => Some(e),
|
||||||
Base58(e) => Some(e),
|
Base58(ref e) => Some(e),
|
||||||
Hex(e) => Some(e),
|
Hex(ref e) => Some(e),
|
||||||
CannotDeriveFromHardenedKey
|
CannotDeriveFromHardenedKey
|
||||||
| InvalidChildNumber(_)
|
| InvalidChildNumber(_)
|
||||||
| InvalidChildNumberFormat
|
| InvalidChildNumberFormat
|
||||||
|
|
|
@ -387,13 +387,15 @@ pub enum Bip34Error {
|
||||||
|
|
||||||
impl fmt::Display for Bip34Error {
|
impl fmt::Display for Bip34Error {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
use Bip34Error::*;
|
||||||
|
|
||||||
match *self {
|
match *self {
|
||||||
Bip34Error::Unsupported => write!(f, "block doesn't support BIP34"),
|
Unsupported => write!(f, "block doesn't support BIP34"),
|
||||||
Bip34Error::NotPresent => write!(f, "BIP34 push not present in block's coinbase"),
|
NotPresent => write!(f, "BIP34 push not present in block's coinbase"),
|
||||||
Bip34Error::UnexpectedPush(ref p) => {
|
UnexpectedPush(ref p) => {
|
||||||
write!(f, "unexpected byte push of > 8 bytes: {:?}", p)
|
write!(f, "unexpected byte push of > 8 bytes: {:?}", p)
|
||||||
}
|
}
|
||||||
Bip34Error::NegativeHeight => write!(f, "negative BIP34 height"),
|
NegativeHeight => write!(f, "negative BIP34 height"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -401,16 +403,17 @@ impl fmt::Display for Bip34Error {
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
impl std::error::Error for Bip34Error {
|
impl std::error::Error for Bip34Error {
|
||||||
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
||||||
use self::Bip34Error::*;
|
use Bip34Error::*;
|
||||||
|
|
||||||
match self {
|
match *self {
|
||||||
Unsupported | NotPresent | UnexpectedPush(_) | NegativeHeight => None,
|
Unsupported | NotPresent | UnexpectedPush(_) | NegativeHeight => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A block validation error.
|
/// A block validation error.
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
|
#[non_exhaustive]
|
||||||
pub enum ValidationError {
|
pub enum ValidationError {
|
||||||
/// The header hash is not below the target.
|
/// The header hash is not below the target.
|
||||||
BadProofOfWork,
|
BadProofOfWork,
|
||||||
|
|
|
@ -575,7 +575,7 @@ pub enum Error {
|
||||||
|
|
||||||
impl fmt::Display for Error {
|
impl fmt::Display for Error {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
use self::Error::*;
|
use Error::*;
|
||||||
|
|
||||||
match *self {
|
match *self {
|
||||||
Conversion(ref e) => write_err!(f, "error converting lock time value"; e),
|
Conversion(ref e) => write_err!(f, "error converting lock time value"; e),
|
||||||
|
@ -588,7 +588,7 @@ impl fmt::Display for Error {
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
impl std::error::Error for Error {
|
impl std::error::Error for Error {
|
||||||
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
||||||
use self::Error::*;
|
use Error::*;
|
||||||
|
|
||||||
match *self {
|
match *self {
|
||||||
Conversion(ref e) => Some(e),
|
Conversion(ref e) => Some(e),
|
||||||
|
@ -614,7 +614,8 @@ impl From<ParseIntError> for Error {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// An error that occurs when converting a `u32` to a lock time variant.
|
/// An error that occurs when converting a `u32` to a lock time variant.
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
|
#[non_exhaustive]
|
||||||
pub struct ConversionError {
|
pub struct ConversionError {
|
||||||
/// The expected timelock unit, height (blocks) or time (seconds).
|
/// The expected timelock unit, height (blocks) or time (seconds).
|
||||||
unit: LockTimeUnit,
|
unit: LockTimeUnit,
|
||||||
|
@ -671,7 +672,7 @@ pub enum OperationError {
|
||||||
|
|
||||||
impl fmt::Display for OperationError {
|
impl fmt::Display for OperationError {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
use self::OperationError::*;
|
use OperationError::*;
|
||||||
|
|
||||||
match *self {
|
match *self {
|
||||||
InvalidComparison =>
|
InvalidComparison =>
|
||||||
|
@ -682,7 +683,13 @@ impl fmt::Display for OperationError {
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
impl std::error::Error for OperationError {
|
impl std::error::Error for OperationError {
|
||||||
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { None }
|
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
||||||
|
use OperationError::*;
|
||||||
|
|
||||||
|
match *self {
|
||||||
|
InvalidComparison => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
|
@ -311,15 +311,17 @@ pub enum Error {
|
||||||
|
|
||||||
impl fmt::Display for Error {
|
impl fmt::Display for Error {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
use Error::*;
|
||||||
|
|
||||||
match *self {
|
match *self {
|
||||||
Self::IntegerOverflow(val) => write!(
|
IntegerOverflow(val) => write!(
|
||||||
f,
|
f,
|
||||||
"{} seconds is too large to be encoded to a 16 bit 512 second interval",
|
"{} seconds is too large to be encoded to a 16 bit 512 second interval",
|
||||||
val
|
val
|
||||||
),
|
),
|
||||||
Self::IncompatibleHeight(lock, height) =>
|
IncompatibleHeight(lock, height) =>
|
||||||
write!(f, "tried to satisfy lock {} with height: {}", lock, height),
|
write!(f, "tried to satisfy lock {} with height: {}", lock, height),
|
||||||
Self::IncompatibleTime(lock, time) =>
|
IncompatibleTime(lock, time) =>
|
||||||
write!(f, "tried to satisfy lock {} with time: {}", lock, time),
|
write!(f, "tried to satisfy lock {} with time: {}", lock, time),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -328,7 +330,7 @@ impl fmt::Display for Error {
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
impl std::error::Error for Error {
|
impl std::error::Error for Error {
|
||||||
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
||||||
use self::Error::*;
|
use Error::*;
|
||||||
|
|
||||||
match *self {
|
match *self {
|
||||||
IntegerOverflow(_) | IncompatibleHeight(_, _) | IncompatibleTime(_, _) => None,
|
IntegerOverflow(_) | IncompatibleHeight(_, _) | IncompatibleTime(_, _) => None,
|
||||||
|
|
|
@ -698,13 +698,15 @@ pub enum Error {
|
||||||
|
|
||||||
impl fmt::Display for Error {
|
impl fmt::Display for Error {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
use Error::*;
|
||||||
|
|
||||||
match *self {
|
match *self {
|
||||||
Error::NonMinimalPush => f.write_str("non-minimal datapush"),
|
NonMinimalPush => f.write_str("non-minimal datapush"),
|
||||||
Error::EarlyEndOfScript => f.write_str("unexpected end of script"),
|
EarlyEndOfScript => f.write_str("unexpected end of script"),
|
||||||
Error::NumericOverflow =>
|
NumericOverflow =>
|
||||||
f.write_str("numeric overflow (number on stack larger than 4 bytes)"),
|
f.write_str("numeric overflow (number on stack larger than 4 bytes)"),
|
||||||
Error::UnknownSpentOutput(ref point) => write!(f, "unknown spent output: {}", point),
|
UnknownSpentOutput(ref point) => write!(f, "unknown spent output: {}", point),
|
||||||
Error::Serialization =>
|
Serialization =>
|
||||||
f.write_str("can not serialize the spending transaction in Transaction::verify()"),
|
f.write_str("can not serialize the spending transaction in Transaction::verify()"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -713,7 +715,7 @@ impl fmt::Display for Error {
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
impl std::error::Error for Error {
|
impl std::error::Error for Error {
|
||||||
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
||||||
use self::Error::*;
|
use Error::*;
|
||||||
|
|
||||||
match *self {
|
match *self {
|
||||||
NonMinimalPush
|
NonMinimalPush
|
||||||
|
|
|
@ -66,7 +66,7 @@ pub enum Error {
|
||||||
|
|
||||||
impl fmt::Display for Error {
|
impl fmt::Display for Error {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
use self::Error::*;
|
use Error::*;
|
||||||
|
|
||||||
match *self {
|
match *self {
|
||||||
InvalidLength(len) =>
|
InvalidLength(len) =>
|
||||||
|
@ -80,9 +80,9 @@ impl fmt::Display for Error {
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
impl std::error::Error for Error {
|
impl std::error::Error for Error {
|
||||||
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
||||||
use self::Error::*;
|
use Error::*;
|
||||||
|
|
||||||
match self {
|
match *self {
|
||||||
InvalidLength(_) | InvalidSegwitV0Length(_) => None,
|
InvalidLength(_) | InvalidSegwitV0Length(_) => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -168,6 +168,7 @@ impl From<WitnessVersion> for Opcode {
|
||||||
|
|
||||||
/// Error parsing [`WitnessVersion`] from a string.
|
/// Error parsing [`WitnessVersion`] from a string.
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
|
#[non_exhaustive]
|
||||||
pub enum FromStrError {
|
pub enum FromStrError {
|
||||||
/// Unable to parse integer from string.
|
/// Unable to parse integer from string.
|
||||||
Unparsable(ParseIntError),
|
Unparsable(ParseIntError),
|
||||||
|
@ -204,6 +205,7 @@ impl From<TryFromError> for FromStrError {
|
||||||
|
|
||||||
/// Error attempting to create a [`WitnessVersion`] from an [`Instruction`]
|
/// Error attempting to create a [`WitnessVersion`] from an [`Instruction`]
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
|
#[non_exhaustive]
|
||||||
pub enum TryFromInstructionError {
|
pub enum TryFromInstructionError {
|
||||||
/// Cannot not convert OP to a witness version.
|
/// Cannot not convert OP to a witness version.
|
||||||
TryFrom(TryFromError),
|
TryFrom(TryFromError),
|
||||||
|
@ -240,6 +242,7 @@ impl From<TryFromError> for TryFromInstructionError {
|
||||||
|
|
||||||
/// Error attempting to create a [`WitnessVersion`] from an integer.
|
/// Error attempting to create a [`WitnessVersion`] from an integer.
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
|
#[non_exhaustive]
|
||||||
pub struct TryFromError {
|
pub struct TryFromError {
|
||||||
/// The invalid non-witness version integer.
|
/// The invalid non-witness version integer.
|
||||||
pub invalid: u8,
|
pub invalid: u8,
|
||||||
|
|
|
@ -116,13 +116,14 @@ pub enum ParseOutPointError {
|
||||||
|
|
||||||
impl fmt::Display for ParseOutPointError {
|
impl fmt::Display for ParseOutPointError {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
use ParseOutPointError::*;
|
||||||
|
|
||||||
match *self {
|
match *self {
|
||||||
ParseOutPointError::Txid(ref e) => write_err!(f, "error parsing TXID"; e),
|
Txid(ref e) => write_err!(f, "error parsing TXID"; e),
|
||||||
ParseOutPointError::Vout(ref e) => write_err!(f, "error parsing vout"; e),
|
Vout(ref e) => write_err!(f, "error parsing vout"; e),
|
||||||
ParseOutPointError::Format => write!(f, "OutPoint not in <txid>:<vout> format"),
|
Format => write!(f, "OutPoint not in <txid>:<vout> format"),
|
||||||
ParseOutPointError::TooLong => write!(f, "vout should be at most 10 digits"),
|
TooLong => write!(f, "vout should be at most 10 digits"),
|
||||||
ParseOutPointError::VoutNotCanonical =>
|
VoutNotCanonical => write!(f, "no leading zeroes or + allowed in vout part"),
|
||||||
write!(f, "no leading zeroes or + allowed in vout part"),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -130,7 +131,7 @@ impl fmt::Display for ParseOutPointError {
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
impl std::error::Error for ParseOutPointError {
|
impl std::error::Error for ParseOutPointError {
|
||||||
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
||||||
use self::ParseOutPointError::*;
|
use ParseOutPointError::*;
|
||||||
|
|
||||||
match self {
|
match self {
|
||||||
Txid(e) => Some(e),
|
Txid(e) => Some(e),
|
||||||
|
|
|
@ -63,15 +63,17 @@ pub enum Error {
|
||||||
|
|
||||||
impl fmt::Display for Error {
|
impl fmt::Display for Error {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
use Error::*;
|
||||||
|
|
||||||
match *self {
|
match *self {
|
||||||
Error::Io(ref e) => write_err!(f, "IO error"; e),
|
Io(ref e) => write_err!(f, "IO error"; e),
|
||||||
Error::OversizedVectorAllocation { requested: ref r, max: ref m } =>
|
OversizedVectorAllocation { requested: ref r, max: ref m } =>
|
||||||
write!(f, "allocation of oversized vector: requested {}, maximum {}", r, m),
|
write!(f, "allocation of oversized vector: requested {}, maximum {}", r, m),
|
||||||
Error::InvalidChecksum { expected: ref e, actual: ref a } =>
|
InvalidChecksum { expected: ref e, actual: ref a } =>
|
||||||
write!(f, "invalid checksum: expected {:x}, actual {:x}", e.as_hex(), a.as_hex()),
|
write!(f, "invalid checksum: expected {:x}, actual {:x}", e.as_hex(), a.as_hex()),
|
||||||
Error::NonMinimalVarInt => write!(f, "non-minimal varint"),
|
NonMinimalVarInt => write!(f, "non-minimal varint"),
|
||||||
Error::ParseFailed(ref s) => write!(f, "parse failed: {}", s),
|
ParseFailed(ref s) => write!(f, "parse failed: {}", s),
|
||||||
Error::UnsupportedSegwitFlag(ref swflag) =>
|
UnsupportedSegwitFlag(ref swflag) =>
|
||||||
write!(f, "unsupported segwit version: {}", swflag),
|
write!(f, "unsupported segwit version: {}", swflag),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -80,7 +82,7 @@ impl fmt::Display for Error {
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
impl std::error::Error for Error {
|
impl std::error::Error for Error {
|
||||||
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
||||||
use self::Error::*;
|
use Error::*;
|
||||||
|
|
||||||
match self {
|
match self {
|
||||||
Io(e) => Some(e),
|
Io(e) => Some(e),
|
||||||
|
|
|
@ -179,6 +179,7 @@ impl Transaction {
|
||||||
// 2. We want to implement `std::error::Error` if the "std" feature is enabled in `rust-bitcoin` but
|
// 2. We want to implement `std::error::Error` if the "std" feature is enabled in `rust-bitcoin` but
|
||||||
// not in `bitcoinconsensus`.
|
// not in `bitcoinconsensus`.
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
|
#[non_exhaustive]
|
||||||
pub struct BitcoinconsensusError(bitcoinconsensus::Error);
|
pub struct BitcoinconsensusError(bitcoinconsensus::Error);
|
||||||
|
|
||||||
impl fmt::Display for BitcoinconsensusError {
|
impl fmt::Display for BitcoinconsensusError {
|
||||||
|
@ -203,6 +204,7 @@ impl From<bitcoinconsensus::Error> for BitcoinconsensusError {
|
||||||
|
|
||||||
/// An error during transaction validation.
|
/// An error during transaction validation.
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
|
#[non_exhaustive]
|
||||||
pub enum TxVerifyError {
|
pub enum TxVerifyError {
|
||||||
/// Error validating the script with bitcoinconsensus library.
|
/// Error validating the script with bitcoinconsensus library.
|
||||||
ScriptVerification(BitcoinconsensusError),
|
ScriptVerification(BitcoinconsensusError),
|
||||||
|
|
|
@ -212,12 +212,12 @@ impl fmt::Display for Error {
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
impl std::error::Error for Error {
|
impl std::error::Error for Error {
|
||||||
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
||||||
use self::Error::*;
|
use Error::*;
|
||||||
|
|
||||||
match self {
|
match *self {
|
||||||
Hex(e) => Some(e),
|
Hex(ref e) => Some(e),
|
||||||
Secp256k1(e) => Some(e),
|
Secp256k1(ref e) => Some(e),
|
||||||
SighashType(e) => Some(e),
|
SighashType(ref e) => Some(e),
|
||||||
EmptySignature => None,
|
EmptySignature => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -720,12 +720,12 @@ impl fmt::Display for Error {
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
impl std::error::Error for Error {
|
impl std::error::Error for Error {
|
||||||
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
||||||
use self::Error::*;
|
use Error::*;
|
||||||
|
|
||||||
match self {
|
match *self {
|
||||||
Base58(e) => Some(e),
|
Base58(ref e) => Some(e),
|
||||||
Secp256k1(e) => Some(e),
|
Secp256k1(ref e) => Some(e),
|
||||||
Hex(e) => Some(e),
|
Hex(ref e) => Some(e),
|
||||||
InvalidKeyPrefix(_) | InvalidHexLength(_) => None,
|
InvalidKeyPrefix(_) | InvalidHexLength(_) => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -247,7 +247,7 @@ impl fmt::Display for Error {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
use Error::*;
|
use Error::*;
|
||||||
|
|
||||||
match self {
|
match *self {
|
||||||
Io(error_kind) => write!(f, "writer errored: {:?}", error_kind),
|
Io(error_kind) => write!(f, "writer errored: {:?}", error_kind),
|
||||||
IndexOutOfInputsBounds { index, inputs_size } => write!(f, "requested index ({}) is greater or equal than the number of transaction inputs ({})", index, inputs_size),
|
IndexOutOfInputsBounds { index, inputs_size } => write!(f, "requested index ({}) is greater or equal than the number of transaction inputs ({})", index, inputs_size),
|
||||||
SingleWithoutCorrespondingOutput { index, outputs_size } => write!(f, "SIGHASH_SINGLE for input ({}) haven't a corresponding output (#outputs:{})", index, outputs_size),
|
SingleWithoutCorrespondingOutput { index, outputs_size } => write!(f, "SIGHASH_SINGLE for input ({}) haven't a corresponding output (#outputs:{})", index, outputs_size),
|
||||||
|
@ -266,7 +266,7 @@ impl std::error::Error for Error {
|
||||||
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
||||||
use Error::*;
|
use Error::*;
|
||||||
|
|
||||||
match self {
|
match *self {
|
||||||
Io(_)
|
Io(_)
|
||||||
| IndexOutOfInputsBounds { .. }
|
| IndexOutOfInputsBounds { .. }
|
||||||
| SingleWithoutCorrespondingOutput { .. }
|
| SingleWithoutCorrespondingOutput { .. }
|
||||||
|
@ -523,7 +523,8 @@ impl TapSighashType {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Integer is not a consensus valid sighash type.
|
/// Integer is not a consensus valid sighash type.
|
||||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
|
#[non_exhaustive]
|
||||||
pub struct InvalidSighashTypeError(pub u32);
|
pub struct InvalidSighashTypeError(pub u32);
|
||||||
|
|
||||||
impl fmt::Display for InvalidSighashTypeError {
|
impl fmt::Display for InvalidSighashTypeError {
|
||||||
|
@ -539,7 +540,8 @@ impl std::error::Error for InvalidSighashTypeError {
|
||||||
|
|
||||||
/// This type is consensus valid but an input including it would prevent the transaction from
|
/// This type is consensus valid but an input including it would prevent the transaction from
|
||||||
/// being relayed on today's Bitcoin network.
|
/// being relayed on today's Bitcoin network.
|
||||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
|
#[non_exhaustive]
|
||||||
pub struct NonStandardSighashTypeError(pub u32);
|
pub struct NonStandardSighashTypeError(pub u32);
|
||||||
|
|
||||||
impl fmt::Display for NonStandardSighashTypeError {
|
impl fmt::Display for NonStandardSighashTypeError {
|
||||||
|
@ -557,6 +559,7 @@ impl std::error::Error for NonStandardSighashTypeError {
|
||||||
///
|
///
|
||||||
/// This is currently returned for unrecognized sighash strings.
|
/// This is currently returned for unrecognized sighash strings.
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
|
#[non_exhaustive]
|
||||||
pub struct SighashTypeParseError {
|
pub struct SighashTypeParseError {
|
||||||
/// The unrecognized string we attempted to parse.
|
/// The unrecognized string we attempted to parse.
|
||||||
pub unrecognized: String,
|
pub unrecognized: String,
|
||||||
|
|
|
@ -87,9 +87,9 @@ impl std::error::Error for SigFromSliceError {
|
||||||
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
||||||
use SigFromSliceError::*;
|
use SigFromSliceError::*;
|
||||||
|
|
||||||
match self {
|
match *self {
|
||||||
Secp256k1(e) => Some(e),
|
Secp256k1(ref e) => Some(e),
|
||||||
SighashType(e) => Some(e),
|
SighashType(ref e) => Some(e),
|
||||||
InvalidSignatureSize(_) => None,
|
InvalidSignatureSize(_) => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -497,7 +497,7 @@ pub enum MerkleBlockError {
|
||||||
|
|
||||||
impl fmt::Display for MerkleBlockError {
|
impl fmt::Display for MerkleBlockError {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
use self::MerkleBlockError::*;
|
use MerkleBlockError::*;
|
||||||
|
|
||||||
match *self {
|
match *self {
|
||||||
MerkleRootMismatch => write!(f, "merkle header root doesn't match to the root calculated from the partial merkle tree"),
|
MerkleRootMismatch => write!(f, "merkle header root doesn't match to the root calculated from the partial merkle tree"),
|
||||||
|
@ -517,7 +517,7 @@ impl fmt::Display for MerkleBlockError {
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
impl std::error::Error for MerkleBlockError {
|
impl std::error::Error for MerkleBlockError {
|
||||||
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
||||||
use self::MerkleBlockError::*;
|
use MerkleBlockError::*;
|
||||||
|
|
||||||
match *self {
|
match *self {
|
||||||
MerkleRootMismatch | NoTransactions | TooManyTransactions | TooManyHashes
|
MerkleRootMismatch | NoTransactions | TooManyTransactions | TooManyHashes
|
||||||
|
|
|
@ -194,6 +194,7 @@ pub mod as_core_arg {
|
||||||
|
|
||||||
/// An error in parsing network string.
|
/// An error in parsing network string.
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
|
#[non_exhaustive]
|
||||||
pub struct ParseNetworkError(String);
|
pub struct ParseNetworkError(String);
|
||||||
|
|
||||||
impl fmt::Display for ParseNetworkError {
|
impl fmt::Display for ParseNetworkError {
|
||||||
|
@ -241,6 +242,7 @@ impl fmt::Display for Network {
|
||||||
|
|
||||||
/// Error in parsing network from chain hash.
|
/// Error in parsing network from chain hash.
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
|
#[non_exhaustive]
|
||||||
pub struct UnknownChainHashError(ChainHash);
|
pub struct UnknownChainHashError(ChainHash);
|
||||||
|
|
||||||
impl Display for UnknownChainHashError {
|
impl Display for UnknownChainHashError {
|
||||||
|
|
|
@ -129,6 +129,7 @@ impl Decodable for CommandString {
|
||||||
///
|
///
|
||||||
/// This is currently returned for command strings longer than 12.
|
/// This is currently returned for command strings longer than 12.
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
|
#[non_exhaustive]
|
||||||
pub struct CommandStringError {
|
pub struct CommandStringError {
|
||||||
cow: Cow<'static, str>,
|
cow: Cow<'static, str>,
|
||||||
}
|
}
|
||||||
|
|
|
@ -325,7 +325,8 @@ impl BorrowMut<[u8; 4]> for Magic {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// An error in parsing magic bytes.
|
/// An error in parsing magic bytes.
|
||||||
#[derive(Debug, PartialEq, Eq, Clone)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
|
#[non_exhaustive]
|
||||||
pub struct ParseMagicError {
|
pub struct ParseMagicError {
|
||||||
/// The error that occurred when parsing the string.
|
/// The error that occurred when parsing the string.
|
||||||
error: hex::HexToArrayError,
|
error: hex::HexToArrayError,
|
||||||
|
@ -346,6 +347,7 @@ impl std::error::Error for ParseMagicError {
|
||||||
|
|
||||||
/// Error in creating a Network from Magic bytes.
|
/// Error in creating a Network from Magic bytes.
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
|
#[non_exhaustive]
|
||||||
pub struct UnknownMagicError(Magic);
|
pub struct UnknownMagicError(Magic);
|
||||||
|
|
||||||
impl fmt::Display for UnknownMagicError {
|
impl fmt::Display for UnknownMagicError {
|
||||||
|
|
|
@ -18,6 +18,7 @@ use crate::prelude::*;
|
||||||
/// in a performance-critical application you may want to box it or throw away the context by
|
/// in a performance-critical application you may want to box it or throw away the context by
|
||||||
/// converting to `core` type.
|
/// converting to `core` type.
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
|
#[non_exhaustive]
|
||||||
pub struct ParseIntError {
|
pub struct ParseIntError {
|
||||||
input: String,
|
input: String,
|
||||||
// for displaying - see Display impl with nice error message below
|
// for displaying - see Display impl with nice error message below
|
||||||
|
|
|
@ -707,7 +707,8 @@ impl<T: Into<u128>> From<T> for U256 {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Error from `TryFrom<signed type>` implementations, occurs when input is negative.
|
/// Error from `TryFrom<signed type>` implementations, occurs when input is negative.
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
|
#[non_exhaustive]
|
||||||
pub struct TryFromError(i128);
|
pub struct TryFromError(i128);
|
||||||
|
|
||||||
impl fmt::Display for TryFromError {
|
impl fmt::Display for TryFromError {
|
||||||
|
|
|
@ -106,57 +106,56 @@ pub enum Error {
|
||||||
|
|
||||||
impl fmt::Display for Error {
|
impl fmt::Display for Error {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
use Error::*;
|
||||||
|
|
||||||
match *self {
|
match *self {
|
||||||
Error::InvalidMagic => f.write_str("invalid magic"),
|
InvalidMagic => f.write_str("invalid magic"),
|
||||||
Error::MissingUtxo => f.write_str("UTXO information is not present in PSBT"),
|
MissingUtxo => f.write_str("UTXO information is not present in PSBT"),
|
||||||
Error::InvalidSeparator => f.write_str("invalid separator"),
|
InvalidSeparator => f.write_str("invalid separator"),
|
||||||
Error::PsbtUtxoOutOfbounds =>
|
PsbtUtxoOutOfbounds =>
|
||||||
f.write_str("output index is out of bounds of non witness script output array"),
|
f.write_str("output index is out of bounds of non witness script output array"),
|
||||||
Error::InvalidKey(ref rkey) => write!(f, "invalid key: {}", rkey),
|
InvalidKey(ref rkey) => write!(f, "invalid key: {}", rkey),
|
||||||
Error::InvalidProprietaryKey =>
|
InvalidProprietaryKey =>
|
||||||
write!(f, "non-proprietary key type found when proprietary key was expected"),
|
write!(f, "non-proprietary key type found when proprietary key was expected"),
|
||||||
Error::DuplicateKey(ref rkey) => write!(f, "duplicate key: {}", rkey),
|
DuplicateKey(ref rkey) => write!(f, "duplicate key: {}", rkey),
|
||||||
Error::UnsignedTxHasScriptSigs =>
|
UnsignedTxHasScriptSigs => f.write_str("the unsigned transaction has script sigs"),
|
||||||
f.write_str("the unsigned transaction has script sigs"),
|
UnsignedTxHasScriptWitnesses =>
|
||||||
Error::UnsignedTxHasScriptWitnesses =>
|
|
||||||
f.write_str("the unsigned transaction has script witnesses"),
|
f.write_str("the unsigned transaction has script witnesses"),
|
||||||
Error::MustHaveUnsignedTx =>
|
MustHaveUnsignedTx =>
|
||||||
f.write_str("partially signed transactions must have an unsigned transaction"),
|
f.write_str("partially signed transactions must have an unsigned transaction"),
|
||||||
Error::NoMorePairs => f.write_str("no more key-value pairs for this psbt map"),
|
NoMorePairs => f.write_str("no more key-value pairs for this psbt map"),
|
||||||
Error::UnexpectedUnsignedTx { expected: ref e, actual: ref a } => write!(
|
UnexpectedUnsignedTx { expected: ref e, actual: ref a } => write!(
|
||||||
f,
|
f,
|
||||||
"different unsigned transaction: expected {}, actual {}",
|
"different unsigned transaction: expected {}, actual {}",
|
||||||
e.txid(),
|
e.txid(),
|
||||||
a.txid()
|
a.txid()
|
||||||
),
|
),
|
||||||
Error::NonStandardSighashType(ref sht) =>
|
NonStandardSighashType(ref sht) => write!(f, "non-standard sighash type: {}", sht),
|
||||||
write!(f, "non-standard sighash type: {}", sht),
|
InvalidHash(ref e) => write_err!(f, "invalid hash when parsing slice"; e),
|
||||||
Error::InvalidHash(ref e) => write_err!(f, "invalid hash when parsing slice"; e),
|
InvalidPreimageHashPair { ref preimage, ref hash, ref hash_type } => {
|
||||||
Error::InvalidPreimageHashPair { ref preimage, ref hash, ref hash_type } => {
|
|
||||||
// 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::CombineInconsistentKeySources(ref s) => {
|
CombineInconsistentKeySources(ref s) => {
|
||||||
write!(f, "combine conflict: {}", s)
|
write!(f, "combine conflict: {}", s)
|
||||||
}
|
}
|
||||||
Error::ConsensusEncoding(ref e) => write_err!(f, "bitcoin consensus encoding error"; e),
|
ConsensusEncoding(ref e) => write_err!(f, "bitcoin consensus encoding error"; e),
|
||||||
Error::NegativeFee => f.write_str("PSBT has a negative fee which is not allowed"),
|
NegativeFee => f.write_str("PSBT has a negative fee which is not allowed"),
|
||||||
Error::FeeOverflow => f.write_str("integer overflow in fee calculation"),
|
FeeOverflow => f.write_str("integer overflow in fee calculation"),
|
||||||
Error::InvalidPublicKey(ref e) => write_err!(f, "invalid public key"; e),
|
InvalidPublicKey(ref e) => write_err!(f, "invalid public key"; e),
|
||||||
Error::InvalidSecp256k1PublicKey(ref e) =>
|
InvalidSecp256k1PublicKey(ref e) => write_err!(f, "invalid secp256k1 public key"; e),
|
||||||
write_err!(f, "invalid secp256k1 public key"; e),
|
InvalidXOnlyPublicKey => f.write_str("invalid xonly public key"),
|
||||||
Error::InvalidXOnlyPublicKey => f.write_str("invalid xonly public key"),
|
InvalidEcdsaSignature(ref e) => write_err!(f, "invalid ECDSA signature"; e),
|
||||||
Error::InvalidEcdsaSignature(ref e) => write_err!(f, "invalid ECDSA signature"; e),
|
InvalidTaprootSignature(ref e) => write_err!(f, "invalid taproot signature"; e),
|
||||||
Error::InvalidTaprootSignature(ref e) => write_err!(f, "invalid taproot signature"; e),
|
InvalidControlBlock => f.write_str("invalid control block"),
|
||||||
Error::InvalidControlBlock => f.write_str("invalid control block"),
|
InvalidLeafVersion => f.write_str("invalid leaf version"),
|
||||||
Error::InvalidLeafVersion => f.write_str("invalid leaf version"),
|
Taproot(s) => write!(f, "taproot error - {}", s),
|
||||||
Error::Taproot(s) => write!(f, "taproot error - {}", s),
|
TapTree(ref e) => write_err!(f, "taproot tree error"; e),
|
||||||
Error::TapTree(ref e) => write_err!(f, "taproot tree error"; e),
|
XPubKey(s) => write!(f, "xpub key error - {}", s),
|
||||||
Error::XPubKey(s) => write!(f, "xpub key error - {}", s),
|
Version(s) => write!(f, "version error {}", s),
|
||||||
Error::Version(s) => write!(f, "version error {}", s),
|
PartialDataConsumption =>
|
||||||
Error::PartialDataConsumption =>
|
|
||||||
f.write_str("data not consumed entirely when explicitly deserializing"),
|
f.write_str("data not consumed entirely when explicitly deserializing"),
|
||||||
Error::Io(ref e) => write_err!(f, "I/O error"; e),
|
Io(ref e) => write_err!(f, "I/O error"; e),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -164,12 +163,12 @@ impl fmt::Display for Error {
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
impl std::error::Error for Error {
|
impl std::error::Error for Error {
|
||||||
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
||||||
use self::Error::*;
|
use Error::*;
|
||||||
|
|
||||||
match self {
|
match *self {
|
||||||
InvalidHash(e) => Some(e),
|
InvalidHash(ref e) => Some(e),
|
||||||
ConsensusEncoding(e) => Some(e),
|
ConsensusEncoding(ref e) => Some(e),
|
||||||
Io(e) => Some(e),
|
Io(ref e) => Some(e),
|
||||||
InvalidMagic
|
InvalidMagic
|
||||||
| MissingUtxo
|
| MissingUtxo
|
||||||
| InvalidSeparator
|
| InvalidSeparator
|
||||||
|
|
|
@ -796,7 +796,7 @@ pub enum SignError {
|
||||||
|
|
||||||
impl fmt::Display for SignError {
|
impl fmt::Display for SignError {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
use self::SignError::*;
|
use SignError::*;
|
||||||
|
|
||||||
match *self {
|
match *self {
|
||||||
IndexOutOfBounds(ref e) => write_err!(f, "index out of bounds"; e),
|
IndexOutOfBounds(ref e) => write_err!(f, "index out of bounds"; e),
|
||||||
|
@ -821,9 +821,11 @@ impl fmt::Display for SignError {
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
impl std::error::Error for SignError {
|
impl std::error::Error for SignError {
|
||||||
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
||||||
use self::SignError::*;
|
use SignError::*;
|
||||||
|
|
||||||
match *self {
|
match *self {
|
||||||
|
SighashComputation(ref e) => Some(e),
|
||||||
|
IndexOutOfBounds(ref e) => Some(e),
|
||||||
InvalidSighashType
|
InvalidSighashType
|
||||||
| MissingInputUtxo
|
| MissingInputUtxo
|
||||||
| MissingRedeemScript
|
| MissingRedeemScript
|
||||||
|
@ -836,8 +838,6 @@ impl std::error::Error for SignError {
|
||||||
| KeyNotFound
|
| KeyNotFound
|
||||||
| WrongSigningAlgorithm
|
| WrongSigningAlgorithm
|
||||||
| Unsupported => None,
|
| Unsupported => None,
|
||||||
SighashComputation(ref e) => Some(e),
|
|
||||||
IndexOutOfBounds(ref e) => Some(e),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -850,8 +850,9 @@ impl From<IndexOutOfBoundsError> for SignError {
|
||||||
fn from(e: IndexOutOfBoundsError) -> Self { SignError::IndexOutOfBounds(e) }
|
fn from(e: IndexOutOfBoundsError) -> Self { SignError::IndexOutOfBounds(e) }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
||||||
/// This error is returned when extracting a [`Transaction`] from a [`Psbt`].
|
/// This error is returned when extracting a [`Transaction`] from a [`Psbt`].
|
||||||
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
|
#[non_exhaustive]
|
||||||
pub enum ExtractTxError {
|
pub enum ExtractTxError {
|
||||||
/// The [`FeeRate`] is too high
|
/// The [`FeeRate`] is too high
|
||||||
AbsurdFeeRate {
|
AbsurdFeeRate {
|
||||||
|
@ -874,14 +875,16 @@ pub enum ExtractTxError {
|
||||||
|
|
||||||
impl fmt::Display for ExtractTxError {
|
impl fmt::Display for ExtractTxError {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
match self {
|
use ExtractTxError::*;
|
||||||
ExtractTxError::AbsurdFeeRate { fee_rate, .. } =>
|
|
||||||
|
match *self {
|
||||||
|
AbsurdFeeRate { fee_rate, .. } =>
|
||||||
write!(f, "An absurdly high fee rate of {}", fee_rate),
|
write!(f, "An absurdly high fee rate of {}", fee_rate),
|
||||||
ExtractTxError::MissingInputValue { .. } => write!(
|
MissingInputValue { .. } => write!(
|
||||||
f,
|
f,
|
||||||
"One of the inputs lacked value information (witness_utxo or non_witness_utxo)"
|
"One of the inputs lacked value information (witness_utxo or non_witness_utxo)"
|
||||||
),
|
),
|
||||||
ExtractTxError::SendingTooMuch { .. } => write!(
|
SendingTooMuch { .. } => write!(
|
||||||
f,
|
f,
|
||||||
"Transaction would be invalid due to output value being greater than input value."
|
"Transaction would be invalid due to output value being greater than input value."
|
||||||
),
|
),
|
||||||
|
@ -891,11 +894,18 @@ impl fmt::Display for ExtractTxError {
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
impl std::error::Error for ExtractTxError {
|
impl std::error::Error for ExtractTxError {
|
||||||
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { None }
|
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
||||||
|
use ExtractTxError::*;
|
||||||
|
|
||||||
|
match *self {
|
||||||
|
AbsurdFeeRate { .. } | MissingInputValue { .. } | SendingTooMuch { .. } => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Input index out of bounds (actual index, maximum index allowed).
|
/// Input index out of bounds (actual index, maximum index allowed).
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
|
#[non_exhaustive]
|
||||||
pub enum IndexOutOfBoundsError {
|
pub enum IndexOutOfBoundsError {
|
||||||
/// The index is out of bounds for the `psbt.inputs` vector.
|
/// The index is out of bounds for the `psbt.inputs` vector.
|
||||||
Inputs {
|
Inputs {
|
||||||
|
@ -934,7 +944,13 @@ impl fmt::Display for IndexOutOfBoundsError {
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
impl std::error::Error for IndexOutOfBoundsError {
|
impl std::error::Error for IndexOutOfBoundsError {
|
||||||
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { None }
|
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
||||||
|
use IndexOutOfBoundsError::*;
|
||||||
|
|
||||||
|
match *self {
|
||||||
|
Inputs { .. } | TxInput { .. } => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "base64")]
|
#[cfg(feature = "base64")]
|
||||||
|
|
|
@ -43,12 +43,13 @@ mod message_signing {
|
||||||
|
|
||||||
impl fmt::Display for MessageSignatureError {
|
impl fmt::Display for MessageSignatureError {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
use MessageSignatureError::*;
|
||||||
|
|
||||||
match *self {
|
match *self {
|
||||||
MessageSignatureError::InvalidLength => write!(f, "length not 65 bytes"),
|
InvalidLength => write!(f, "length not 65 bytes"),
|
||||||
MessageSignatureError::InvalidEncoding(ref e) =>
|
InvalidEncoding(ref e) => write_err!(f, "invalid encoding"; e),
|
||||||
write_err!(f, "invalid encoding"; e),
|
InvalidBase64 => write!(f, "invalid base64"),
|
||||||
MessageSignatureError::InvalidBase64 => write!(f, "invalid base64"),
|
UnsupportedAddressType(ref address_type) =>
|
||||||
MessageSignatureError::UnsupportedAddressType(ref address_type) =>
|
|
||||||
write!(f, "unsupported address type: {}", address_type),
|
write!(f, "unsupported address type: {}", address_type),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -57,10 +58,10 @@ mod message_signing {
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
impl std::error::Error for MessageSignatureError {
|
impl std::error::Error for MessageSignatureError {
|
||||||
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
||||||
use self::MessageSignatureError::*;
|
use MessageSignatureError::*;
|
||||||
|
|
||||||
match self {
|
match *self {
|
||||||
InvalidEncoding(e) => Some(e),
|
InvalidEncoding(ref e) => Some(e),
|
||||||
InvalidLength | InvalidBase64 | UnsupportedAddressType(_) => None,
|
InvalidLength | InvalidBase64 | UnsupportedAddressType(_) => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,6 +36,7 @@ pub trait FromHexStr: Sized {
|
||||||
|
|
||||||
/// Hex parsing error
|
/// Hex parsing error
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
|
#[non_exhaustive]
|
||||||
pub enum FromHexError<E> {
|
pub enum FromHexError<E> {
|
||||||
/// The input was not a valid hex string, contains the error that occurred while parsing.
|
/// The input was not a valid hex string, contains the error that occurred while parsing.
|
||||||
ParseHex(E),
|
ParseHex(E),
|
||||||
|
@ -49,7 +50,7 @@ impl<E> From<E> for FromHexError<E> {
|
||||||
|
|
||||||
impl<E: fmt::Display> fmt::Display for FromHexError<E> {
|
impl<E: fmt::Display> fmt::Display for FromHexError<E> {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
use self::FromHexError::*;
|
use FromHexError::*;
|
||||||
|
|
||||||
match *self {
|
match *self {
|
||||||
ParseHex(ref e) => write_err!(f, "failed to parse hex string"; e),
|
ParseHex(ref e) => write_err!(f, "failed to parse hex string"; e),
|
||||||
|
@ -65,7 +66,7 @@ where
|
||||||
E: std::error::Error + 'static,
|
E: std::error::Error + 'static,
|
||||||
{
|
{
|
||||||
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
||||||
use self::FromHexError::*;
|
use FromHexError::*;
|
||||||
|
|
||||||
match *self {
|
match *self {
|
||||||
ParseHex(ref e) => Some(e),
|
ParseHex(ref e) => Some(e),
|
||||||
|
|
|
@ -574,7 +574,7 @@ impl Default for TaprootBuilder {
|
||||||
|
|
||||||
/// Error happening when [`TapTree`] is constructed from a [`TaprootBuilder`]
|
/// Error happening when [`TapTree`] is constructed from a [`TaprootBuilder`]
|
||||||
/// having hidden branches or not being finalized.
|
/// having hidden branches or not being finalized.
|
||||||
#[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
#[non_exhaustive]
|
#[non_exhaustive]
|
||||||
pub enum IncompleteBuilderError {
|
pub enum IncompleteBuilderError {
|
||||||
/// Indicates an attempt to construct a tap tree from a builder containing incomplete branches.
|
/// Indicates an attempt to construct a tap tree from a builder containing incomplete branches.
|
||||||
|
@ -620,7 +620,7 @@ impl std::error::Error for IncompleteBuilderError {
|
||||||
|
|
||||||
/// Error happening when [`TapTree`] is constructed from a [`NodeInfo`]
|
/// Error happening when [`TapTree`] is constructed from a [`NodeInfo`]
|
||||||
/// having hidden branches.
|
/// having hidden branches.
|
||||||
#[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
#[non_exhaustive]
|
#[non_exhaustive]
|
||||||
pub enum HiddenNodesError {
|
pub enum HiddenNodesError {
|
||||||
/// Indicates an attempt to construct a tap tree from a builder containing hidden parts.
|
/// Indicates an attempt to construct a tap tree from a builder containing hidden parts.
|
||||||
|
@ -630,16 +630,20 @@ pub enum HiddenNodesError {
|
||||||
impl HiddenNodesError {
|
impl HiddenNodesError {
|
||||||
/// Converts error into the original incomplete [`NodeInfo`] instance.
|
/// Converts error into the original incomplete [`NodeInfo`] instance.
|
||||||
pub fn into_node_info(self) -> NodeInfo {
|
pub fn into_node_info(self) -> NodeInfo {
|
||||||
|
use HiddenNodesError::*;
|
||||||
|
|
||||||
match self {
|
match self {
|
||||||
HiddenNodesError::HiddenParts(node_info) => node_info,
|
HiddenParts(node_info) => node_info,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl core::fmt::Display for HiddenNodesError {
|
impl core::fmt::Display for HiddenNodesError {
|
||||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||||
|
use HiddenNodesError::*;
|
||||||
|
|
||||||
f.write_str(match self {
|
f.write_str(match self {
|
||||||
HiddenNodesError::HiddenParts(_) =>
|
HiddenParts(_) =>
|
||||||
"an attempt to construct a tap tree from a node_info containing hidden parts.",
|
"an attempt to construct a tap tree from a node_info containing hidden parts.",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -648,7 +652,7 @@ impl core::fmt::Display for HiddenNodesError {
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
impl std::error::Error for HiddenNodesError {
|
impl std::error::Error for HiddenNodesError {
|
||||||
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
||||||
use self::HiddenNodesError::*;
|
use HiddenNodesError::*;
|
||||||
|
|
||||||
match self {
|
match self {
|
||||||
HiddenParts(_) => None,
|
HiddenParts(_) => None,
|
||||||
|
@ -1447,26 +1451,28 @@ pub enum TaprootBuilderError {
|
||||||
|
|
||||||
impl fmt::Display for TaprootBuilderError {
|
impl fmt::Display for TaprootBuilderError {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
use TaprootBuilderError::*;
|
||||||
|
|
||||||
match *self {
|
match *self {
|
||||||
TaprootBuilderError::InvalidMerkleTreeDepth(d) => {
|
InvalidMerkleTreeDepth(d) => {
|
||||||
write!(
|
write!(
|
||||||
f,
|
f,
|
||||||
"Merkle Tree depth({}) must be less than {}",
|
"Merkle Tree depth({}) must be less than {}",
|
||||||
d, TAPROOT_CONTROL_MAX_NODE_COUNT
|
d, TAPROOT_CONTROL_MAX_NODE_COUNT
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
TaprootBuilderError::NodeNotInDfsOrder => {
|
NodeNotInDfsOrder => {
|
||||||
write!(f, "add_leaf/add_hidden must be called in DFS walk order",)
|
write!(f, "add_leaf/add_hidden must be called in DFS walk order",)
|
||||||
}
|
}
|
||||||
TaprootBuilderError::OverCompleteTree => write!(
|
OverCompleteTree => write!(
|
||||||
f,
|
f,
|
||||||
"Attempted to create a tree with two nodes at depth 0. There must\
|
"Attempted to create a tree with two nodes at depth 0. There must\
|
||||||
only be a exactly one node at depth 0",
|
only be a exactly one node at depth 0",
|
||||||
),
|
),
|
||||||
TaprootBuilderError::InvalidInternalKey(ref e) => {
|
InvalidInternalKey(ref e) => {
|
||||||
write_err!(f, "invalid internal x-only key"; e)
|
write_err!(f, "invalid internal x-only key"; e)
|
||||||
}
|
}
|
||||||
TaprootBuilderError::EmptyTree => {
|
EmptyTree => {
|
||||||
write!(f, "Called finalize on an empty tree")
|
write!(f, "Called finalize on an empty tree")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1476,7 +1482,7 @@ impl fmt::Display for TaprootBuilderError {
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
impl std::error::Error for TaprootBuilderError {
|
impl std::error::Error for TaprootBuilderError {
|
||||||
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
||||||
use self::TaprootBuilderError::*;
|
use TaprootBuilderError::*;
|
||||||
|
|
||||||
match self {
|
match self {
|
||||||
InvalidInternalKey(e) => Some(e),
|
InvalidInternalKey(e) => Some(e),
|
||||||
|
@ -1507,30 +1513,32 @@ pub enum TaprootError {
|
||||||
|
|
||||||
impl fmt::Display for TaprootError {
|
impl fmt::Display for TaprootError {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
use TaprootError::*;
|
||||||
|
|
||||||
match *self {
|
match *self {
|
||||||
TaprootError::InvalidMerkleBranchSize(sz) => write!(
|
InvalidMerkleBranchSize(sz) => write!(
|
||||||
f,
|
f,
|
||||||
"Merkle branch size({}) must be a multiple of {}",
|
"Merkle branch size({}) must be a multiple of {}",
|
||||||
sz, TAPROOT_CONTROL_NODE_SIZE
|
sz, TAPROOT_CONTROL_NODE_SIZE
|
||||||
),
|
),
|
||||||
TaprootError::InvalidMerkleTreeDepth(d) => write!(
|
InvalidMerkleTreeDepth(d) => write!(
|
||||||
f,
|
f,
|
||||||
"Merkle Tree depth({}) must be less than {}",
|
"Merkle Tree depth({}) must be less than {}",
|
||||||
d, TAPROOT_CONTROL_MAX_NODE_COUNT
|
d, TAPROOT_CONTROL_MAX_NODE_COUNT
|
||||||
),
|
),
|
||||||
TaprootError::InvalidTaprootLeafVersion(v) => {
|
InvalidTaprootLeafVersion(v) => {
|
||||||
write!(f, "Leaf version({}) must have the least significant bit 0", v)
|
write!(f, "Leaf version({}) must have the least significant bit 0", v)
|
||||||
}
|
}
|
||||||
TaprootError::InvalidControlBlockSize(sz) => write!(
|
InvalidControlBlockSize(sz) => write!(
|
||||||
f,
|
f,
|
||||||
"Control Block size({}) must be of the form 33 + 32*m where 0 <= m <= {} ",
|
"Control Block size({}) must be of the form 33 + 32*m where 0 <= m <= {} ",
|
||||||
sz, TAPROOT_CONTROL_MAX_NODE_COUNT
|
sz, TAPROOT_CONTROL_MAX_NODE_COUNT
|
||||||
),
|
),
|
||||||
TaprootError::InvalidInternalKey(ref e) => {
|
InvalidInternalKey(ref e) => {
|
||||||
write_err!(f, "invalid internal x-only key"; e)
|
write_err!(f, "invalid internal x-only key"; e)
|
||||||
}
|
}
|
||||||
TaprootError::InvalidParity(_) => write!(f, "invalid parity value for internal key"),
|
InvalidParity(_) => write!(f, "invalid parity value for internal key"),
|
||||||
TaprootError::EmptyTree => write!(f, "Taproot Tree must contain at least one script"),
|
EmptyTree => write!(f, "Taproot Tree must contain at least one script"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1538,7 +1546,7 @@ impl fmt::Display for TaprootError {
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
impl std::error::Error for TaprootError {
|
impl std::error::Error for TaprootError {
|
||||||
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
||||||
use self::TaprootError::*;
|
use TaprootError::*;
|
||||||
|
|
||||||
match self {
|
match self {
|
||||||
InvalidInternalKey(e) => Some(e),
|
InvalidInternalKey(e) => Some(e),
|
||||||
|
|
|
@ -225,7 +225,8 @@ pub trait Hash:
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Attempted to create a hash from an invalid length slice.
|
/// Attempted to create a hash from an invalid length slice.
|
||||||
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
|
#[non_exhaustive]
|
||||||
pub struct FromSliceError {
|
pub struct FromSliceError {
|
||||||
expected: usize,
|
expected: usize,
|
||||||
got: usize,
|
got: usize,
|
||||||
|
|
Loading…
Reference in New Issue