From badb0f2a7763f425ef359d855687ec6e1ae6e8a4 Mon Sep 17 00:00:00 2001 From: Carl Dong Date: Sat, 8 Sep 2018 21:30:38 -0700 Subject: [PATCH] Add PSBT input data key-value map type - Implement psbt::Map trait for psbt::Input - Add (en)decoding logic for psbt::Input - Implement PSBT (de)serialization trait for relevant psbt::Input types --- src/util/psbt/map/input.rs | 183 +++++++++++++++++++++++++++++++++++++ src/util/psbt/map/mod.rs | 2 + src/util/psbt/mod.rs | 2 +- src/util/psbt/serialize.rs | 36 +++++++- 4 files changed, 221 insertions(+), 2 deletions(-) create mode 100644 src/util/psbt/map/input.rs diff --git a/src/util/psbt/map/input.rs b/src/util/psbt/map/input.rs new file mode 100644 index 00000000..b53fcacd --- /dev/null +++ b/src/util/psbt/map/input.rs @@ -0,0 +1,183 @@ +use std::collections::HashMap; + +use blockdata::script::Script; +use blockdata::transaction::{SigHashType, Transaction, TxOut}; +use consensus::encode; +use util::bip32::{DerivationPath, Fingerprint}; +use util::key::PublicKey; +use util::psbt; +use util::psbt::map::Map; +use util::psbt::raw; +use util::psbt::Error; + +/// A key-value map for an input of the corresponding index in the unsigned +/// transaction. +#[derive(Clone, Default, Debug, PartialEq)] +pub struct Input { + /// The non-witness transaction this input spends from. Should only be + /// [std::option::Option::Some] for inputs which spend non-segwit outputs or + /// if it is unknown whether an input spends a segwit output. + pub non_witness_utxo: Option, + /// The transaction output this input spends from. Should only be + /// [std::option::Option::Some] for inputs which spend segwit outputs, + /// including P2SH embedded ones. + pub witness_utxo: Option, + /// A map from public keys to their corresponding signature as would be + /// pushed to the stack from a scriptSig or witness. + pub partial_sigs: HashMap>, + /// The sighash type to be used for this input. Signatures for this input + /// must use the sighash type. + pub sighash_type: Option, + /// The redeem script for this input. + pub redeem_script: Option