Skip to content

Commit 3337b7a

Browse files
committed
psbt: introduce IncorrectNonWitnessUtxo error variant
Putting this in its own commit so that the fix and the test can live in separate commits which reviewers can swap.
1 parent 732a83c commit 3337b7a

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

bitcoin/src/psbt/error.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,16 @@ pub enum Error {
8080
NegativeFee,
8181
/// Integer overflow in fee calculation
8282
FeeOverflow,
83+
/// Non-witness UTXO (which is a complete transaction) has [`crate::Txid`] that
84+
/// does not match the transaction input.
85+
IncorrectNonWitnessUtxo {
86+
/// The index of the input in question.
87+
index: usize,
88+
/// The outpoint of the input, as it appears in the unsigned transaction.
89+
input_outpoint: crate::OutPoint,
90+
/// The ['crate::Txid`] of the non-witness UTXO.
91+
non_witness_utxo_txid: crate::Txid,
92+
},
8393
/// Parsing error indicating invalid public keys
8494
InvalidPublicKey(crate::crypto::key::FromSliceError),
8595
/// Parsing error indicating invalid secp256k1 public keys
@@ -154,6 +164,13 @@ impl fmt::Display for Error {
154164
write_err!(f, "error parsing bitcoin consensus encoded object"; e),
155165
NegativeFee => f.write_str("PSBT has a negative fee which is not allowed"),
156166
FeeOverflow => f.write_str("integer overflow in fee calculation"),
167+
IncorrectNonWitnessUtxo { index, input_outpoint, non_witness_utxo_txid } => {
168+
write!(
169+
f,
170+
"non-witness utxo txid is {}, which does not match input {}'s outpoint {}",
171+
non_witness_utxo_txid, index, input_outpoint
172+
)
173+
}
157174
InvalidPublicKey(ref e) => write_err!(f, "invalid public key"; e),
158175
InvalidSecp256k1PublicKey(ref e) => write_err!(f, "invalid secp256k1 public key"; e),
159176
InvalidXOnlyPublicKey => f.write_str("invalid xonly public key"),
@@ -200,6 +217,7 @@ impl std::error::Error for Error {
200217
| CombineInconsistentKeySources(_)
201218
| NegativeFee
202219
| FeeOverflow
220+
| IncorrectNonWitnessUtxo { .. }
203221
| InvalidPublicKey(_)
204222
| InvalidSecp256k1PublicKey(_)
205223
| InvalidXOnlyPublicKey

0 commit comments

Comments
 (0)