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