|
20 | 20 | //!
|
21 | 21 |
|
22 | 22 | use blockdata::script::Script;
|
23 |
| -use blockdata::transaction::Transaction; |
| 23 | +use blockdata::transaction::{ TxOut, Transaction}; |
24 | 24 | use consensus::{encode, Encodable, Decodable};
|
25 | 25 | use consensus::encode::MAX_VEC_SIZE;
|
| 26 | +pub use util::sighash::Prevouts; |
26 | 27 |
|
27 | 28 | use prelude::*;
|
28 | 29 |
|
29 | 30 | use io;
|
30 |
| - |
31 | 31 | mod error;
|
32 | 32 | pub use self::error::Error;
|
33 | 33 |
|
@@ -72,6 +72,32 @@ pub struct PartiallySignedTransaction {
|
72 | 72 | }
|
73 | 73 |
|
74 | 74 | impl PartiallySignedTransaction {
|
| 75 | + /// Returns an iterator for the funding UTXOs of the psbt |
| 76 | + /// |
| 77 | + /// For each PSBT input that contains UTXO information `Ok` is returned containing that information. |
| 78 | + /// The order of returned items is same as the order of inputs. |
| 79 | + /// |
| 80 | + /// ## Errors |
| 81 | + /// |
| 82 | + /// The function returns error when UTXO information is not present or is invalid. |
| 83 | + /// |
| 84 | + /// ## Panics |
| 85 | + /// |
| 86 | + /// The function panics if the length of transaction inputs is not equal to the length of PSBT inputs. |
| 87 | + pub fn iter_funding_utxos(&self) -> impl Iterator<Item = Result<&TxOut, Error>> { |
| 88 | + assert_eq!(self.inputs.len(), self.unsigned_tx.input.len()); |
| 89 | + self.unsigned_tx.input.iter().zip(&self.inputs).map(|(tx_input, psbt_input)| { |
| 90 | + match (&psbt_input.witness_utxo, &psbt_input.non_witness_utxo) { |
| 91 | + (Some(witness_utxo), _) => Ok(witness_utxo), |
| 92 | + (None, Some(non_witness_utxo)) => { |
| 93 | + let vout = tx_input.previous_output.vout as usize; |
| 94 | + non_witness_utxo.output.get(vout).ok_or(Error::PsbtUtxoOutOfbounds) |
| 95 | + }, |
| 96 | + (None, None) => Err(Error::MissingUtxo), |
| 97 | + } |
| 98 | + }) |
| 99 | + } |
| 100 | + |
75 | 101 | /// Checks that unsigned transaction does not have scriptSig's or witness
|
76 | 102 | /// data
|
77 | 103 | fn unsigned_tx_checks(&self) -> Result<(), Error> {
|
|
0 commit comments