1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
use std::error;
use std::fmt;
use blockdata::transaction::Transaction;
use consensus::encode;
use util::psbt::raw;
use hashes;
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub enum PsbtHash {
Ripemd,
Sha256,
Hash160,
Hash256,
}
#[derive(Clone, PartialEq, Eq, Debug)]
pub enum Error {
InvalidMagic,
InvalidSeparator,
InvalidKey(raw::Key),
InvalidProprietaryKey,
DuplicateKey(raw::Key),
UnsignedTxHasScriptSigs,
UnsignedTxHasScriptWitnesses,
MustHaveUnsignedTx,
NoMorePairs,
UnexpectedUnsignedTx {
expected: Transaction,
actual: Transaction,
},
NonStandardSigHashType(u32),
HashParseError(hashes::Error),
InvalidPreimageHashPair {
hash_type: PsbtHash,
preimage: Vec<u8>,
hash: Vec<u8>,
},
MergeConflict(String),
ConsensusEncoding,
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
Error::InvalidKey(ref rkey) => write!(f, "invalid key: {}", rkey),
Error::InvalidProprietaryKey => write!(f, "non-proprietary key type found when proprietary key was expected"),
Error::DuplicateKey(ref rkey) => write!(f, "duplicate key: {}", rkey),
Error::UnexpectedUnsignedTx { expected: ref e, actual: ref a } => write!(f, "different unsigned transaction: expected {}, actual {}", e.txid(), a.txid()),
Error::NonStandardSigHashType(ref sht) => write!(f, "non-standard sighash type: {}", sht),
Error::InvalidMagic => f.write_str("invalid magic"),
Error::InvalidSeparator => f.write_str("invalid separator"),
Error::UnsignedTxHasScriptSigs => f.write_str("the unsigned transaction has script sigs"),
Error::UnsignedTxHasScriptWitnesses => f.write_str("the unsigned transaction has script witnesses"),
Error::MustHaveUnsignedTx => {
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"),
Error::HashParseError(e) => write!(f, "Hash Parse Error: {}", e),
Error::InvalidPreimageHashPair{ref preimage, ref hash, ref hash_type} => {
write!(f, "Preimage {:?} does not match {:?} hash {:?}", preimage, hash_type, hash )
}
Error::MergeConflict(ref s) => { write!(f, "Merge conflict: {}", s) }
Error::ConsensusEncoding => f.write_str("bitcoin consensus encoding error"),
}
}
}
impl error::Error for Error {}
#[doc(hidden)]
impl From<hashes::Error> for Error {
fn from(e: hashes::Error) -> Error {
Error::HashParseError(e)
}
}
impl From<encode::Error> for Error {
fn from(err: encode::Error) -> Self {
match err {
encode::Error::Psbt(err) => err,
_ => Error::ConsensusEncoding,
}
}
}