New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
API to find funding utxos in psbt #853
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -20,14 +20,14 @@ | |||||
//! | ||||||
|
||||||
use blockdata::script::Script; | ||||||
use blockdata::transaction::Transaction; | ||||||
use blockdata::transaction::{ TxOut, Transaction}; | ||||||
use consensus::{encode, Encodable, Decodable}; | ||||||
use consensus::encode::MAX_VEC_SIZE; | ||||||
pub use util::sighash::Prevouts; | ||||||
|
||||||
use prelude::*; | ||||||
|
||||||
use io; | ||||||
|
||||||
mod error; | ||||||
pub use self::error::Error; | ||||||
|
||||||
|
@@ -72,6 +72,32 @@ pub struct PartiallySignedTransaction { | |||||
} | ||||||
|
||||||
impl PartiallySignedTransaction { | ||||||
/// Returns an iterator for the funding UTXOs of the psbt | ||||||
Kixunil marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
/// | ||||||
/// For each PSBT input that contains UTXO information `Ok` is returned containing that information. | ||||||
/// The order of returned items is same as the order of inputs. | ||||||
/// | ||||||
/// ## Errors | ||||||
/// | ||||||
/// The function returns error when UTXO information is not present or is invalid. | ||||||
/// | ||||||
/// ## Panics | ||||||
/// | ||||||
/// The function panics if the length of transaction inputs is not equal to the length of PSBT inputs. | ||||||
pub fn iter_funding_utxos(&self) -> impl Iterator<Item = Result<&TxOut, Error>> { | ||||||
assert_eq!(self.inputs.len(), self.unsigned_tx.input.len()); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi ! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, sorry. |
||||||
self.unsigned_tx.input.iter().zip(&self.inputs).map(|(tx_input, psbt_input)| { | ||||||
match (&psbt_input.witness_utxo, &psbt_input.non_witness_utxo) { | ||||||
(Some(witness_utxo), _) => Ok(witness_utxo), | ||||||
(None, Some(non_witness_utxo)) => { | ||||||
let vout = tx_input.previous_output.vout as usize; | ||||||
non_witness_utxo.output.get(vout).ok_or(Error::PsbtUtxoOutOfbounds) | ||||||
}, | ||||||
(None, None) => Err(Error::MissingUtxo), | ||||||
} | ||||||
}) | ||||||
} | ||||||
|
||||||
/// Checks that unsigned transaction does not have scriptSig's or witness | ||||||
/// data | ||||||
fn unsigned_tx_checks(&self) -> Result<(), Error> { | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please no 'random' whitespace changes. The reason is that it makes reviewing the PR harder because reviewers must stop to think what is this, why is it being done, is it correct, is it a step backwards in readability. All easy questions but unnecessary for getting your work merged. The easier you make it for reviewers to ack your work the easier you'll get PR's merged, that's a win for everyone :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, silly mistake of mine ... will take care of it from next commits.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cheers mate, no stress. If I had a dollar for ever mistake I made in this repo in the last three months I'd be fiat rich :)