bitcoin/util/psbt/
error.rs1use std::error;
16use std::fmt;
17
18use blockdata::transaction::Transaction;
19use consensus::encode;
20use util::psbt::raw;
21
22use hashes;
23
24#[derive(Copy, Clone, PartialEq, Eq, Debug)]
25pub enum PsbtHash {
27 Ripemd,
28 Sha256,
29 Hash160,
30 Hash256,
31}
32#[derive(Clone, PartialEq, Eq, Debug)]
34pub enum Error {
35 InvalidMagic,
38 InvalidSeparator,
40 InvalidKey(raw::Key),
42 InvalidProprietaryKey,
44 DuplicateKey(raw::Key),
46 UnsignedTxHasScriptSigs,
48 UnsignedTxHasScriptWitnesses,
50 MustHaveUnsignedTx,
52 NoMorePairs,
54 UnexpectedUnsignedTx {
57 expected: Transaction,
59 actual: Transaction,
61 },
62 NonStandardSigHashType(u32),
64 HashParseError(hashes::Error),
66 InvalidPreimageHashPair {
68 hash_type: PsbtHash,
70 preimage: Vec<u8>,
72 hash: Vec<u8>,
74 },
75 MergeConflict(String),
77 ConsensusEncoding,
79}
80
81impl fmt::Display for Error {
82 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
83 match *self {
84 Error::InvalidKey(ref rkey) => write!(f, "invalid key: {}", rkey),
85 Error::InvalidProprietaryKey => write!(f, "non-proprietary key type found when proprietary key was expected"),
86 Error::DuplicateKey(ref rkey) => write!(f, "duplicate key: {}", rkey),
87 Error::UnexpectedUnsignedTx { expected: ref e, actual: ref a } => write!(f, "different unsigned transaction: expected {}, actual {}", e.txid(), a.txid()),
88 Error::NonStandardSigHashType(ref sht) => write!(f, "non-standard sighash type: {}", sht),
89 Error::InvalidMagic => f.write_str("invalid magic"),
90 Error::InvalidSeparator => f.write_str("invalid separator"),
91 Error::UnsignedTxHasScriptSigs => f.write_str("the unsigned transaction has script sigs"),
92 Error::UnsignedTxHasScriptWitnesses => f.write_str("the unsigned transaction has script witnesses"),
93 Error::MustHaveUnsignedTx => {
94 f.write_str("partially signed transactions must have an unsigned transaction")
95 }
96 Error::NoMorePairs => f.write_str("no more key-value pairs for this psbt map"),
97 Error::HashParseError(e) => write!(f, "Hash Parse Error: {}", e),
98 Error::InvalidPreimageHashPair{ref preimage, ref hash, ref hash_type} => {
99 write!(f, "Preimage {:?} does not match {:?} hash {:?}", preimage, hash_type, hash )
101 }
102 Error::MergeConflict(ref s) => { write!(f, "Merge conflict: {}", s) }
103 Error::ConsensusEncoding => f.write_str("bitcoin consensus encoding error"),
104 }
105 }
106}
107
108impl error::Error for Error {}
109
110#[doc(hidden)]
111impl From<hashes::Error> for Error {
112 fn from(e: hashes::Error) -> Error {
113 Error::HashParseError(e)
114 }
115}
116
117impl From<encode::Error> for Error {
118 fn from(err: encode::Error) -> Self {
119 match err {
120 encode::Error::Psbt(err) => err,
121 _ => Error::ConsensusEncoding,
122 }
123 }
124}