Change type of final script witness to Witness from Vec<Vec<u8>>

This commit is contained in:
sanket1729 2022-01-11 14:40:28 +05:30
parent e4d5039a86
commit 9a8ab3f3ff
3 changed files with 8 additions and 7 deletions

View File

@ -18,6 +18,7 @@ use ::{EcdsaSig, io};
use secp256k1; use secp256k1;
use blockdata::script::Script; use blockdata::script::Script;
use blockdata::witness::Witness;
use blockdata::transaction::{EcdsaSigHashType, Transaction, TxOut}; use blockdata::transaction::{EcdsaSigHashType, Transaction, TxOut};
use consensus::encode; use consensus::encode;
use hashes::{self, hash160, ripemd160, sha256, sha256d}; use hashes::{self, hash160, ripemd160, sha256, sha256d};
@ -105,7 +106,7 @@ pub struct Input {
pub final_script_sig: Option<Script>, pub final_script_sig: Option<Script>,
/// The finalized, fully-constructed scriptWitness with signatures and any /// The finalized, fully-constructed scriptWitness with signatures and any
/// other scripts necessary for this input to pass validation. /// other scripts necessary for this input to pass validation.
pub final_script_witness: Option<Vec<Vec<u8>>>, pub final_script_witness: Option<Witness>,
/// TODO: Proof of reserves commitment /// TODO: Proof of reserves commitment
/// RIPEMD160 hash to preimage map /// RIPEMD160 hash to preimage map
#[cfg_attr(feature = "serde", serde(with = "::serde_utils::btreemap_byte_values"))] #[cfg_attr(feature = "serde", serde(with = "::serde_utils::btreemap_byte_values"))]
@ -192,7 +193,7 @@ impl Map for Input {
} }
PSBT_IN_FINAL_SCRIPTWITNESS => { PSBT_IN_FINAL_SCRIPTWITNESS => {
impl_psbt_insert_pair! { impl_psbt_insert_pair! {
self.final_script_witness <= <raw_key: _>|<raw_value: Vec<Vec<u8>>> self.final_script_witness <= <raw_key: _>|<raw_value: Witness>
} }
} }
PSBT_IN_RIPEMD160 => { PSBT_IN_RIPEMD160 => {
@ -290,7 +291,7 @@ impl Map for Input {
} }
impl_psbt_get_pair! { impl_psbt_get_pair! {
rv.push(self.final_script_witness as <PSBT_IN_FINAL_SCRIPTWITNESS, _>|<Script>) rv.push(self.final_script_witness as <PSBT_IN_FINAL_SCRIPTWITNESS, _>|<Witness>)
} }
impl_psbt_get_pair! { impl_psbt_get_pair! {

View File

@ -27,7 +27,6 @@ use consensus::encode::MAX_VEC_SIZE;
use prelude::*; use prelude::*;
use io; use io;
use blockdata::witness::Witness;
mod error; mod error;
pub use self::error::Error; pub use self::error::Error;
@ -112,7 +111,7 @@ impl PartiallySignedTransaction {
for (vin, psbtin) in tx.input.iter_mut().zip(self.inputs.into_iter()) { for (vin, psbtin) in tx.input.iter_mut().zip(self.inputs.into_iter()) {
vin.script_sig = psbtin.final_script_sig.unwrap_or_else(Script::new); vin.script_sig = psbtin.final_script_sig.unwrap_or_else(Script::new);
vin.witness = Witness::from_vec(psbtin.final_script_witness.unwrap_or_else(Vec::new)); vin.witness = psbtin.final_script_witness.unwrap_or_default();
} }
tx tx
@ -478,7 +477,7 @@ mod tests {
"304402204f67e2afb76142d44fae58a2495d33a3419daa26cd0db8d04f3452b63289ac0f022010762a9fb67e94cc5cad9026f6dc99ff7f070f4278d30fbc7d0c869dd38c7fe701".parse().unwrap(), "304402204f67e2afb76142d44fae58a2495d33a3419daa26cd0db8d04f3452b63289ac0f022010762a9fb67e94cc5cad9026f6dc99ff7f070f4278d30fbc7d0c869dd38c7fe701".parse().unwrap(),
)].into_iter().collect(), )].into_iter().collect(),
bip32_derivation: keypaths.clone(), bip32_derivation: keypaths.clone(),
final_script_witness: Some(vec![vec![1, 3], vec![5]]), final_script_witness: Some(Witness::from_vec(vec![vec![1, 3], vec![5]])),
ripemd160_preimages: vec![(ripemd160::Hash::hash(&[]), vec![1, 2])].into_iter().collect(), ripemd160_preimages: vec![(ripemd160::Hash::hash(&[]), vec![1, 2])].into_iter().collect(),
sha256_preimages: vec![(sha256::Hash::hash(&[]), vec![1, 2])].into_iter().collect(), sha256_preimages: vec![(sha256::Hash::hash(&[]), vec![1, 2])].into_iter().collect(),
hash160_preimages: vec![(hash160::Hash::hash(&[]), vec![1, 2])].into_iter().collect(), hash160_preimages: vec![(hash160::Hash::hash(&[]), vec![1, 2])].into_iter().collect(),

View File

@ -23,6 +23,7 @@ use prelude::*;
use io; use io;
use blockdata::script::Script; use blockdata::script::Script;
use blockdata::witness::Witness;
use blockdata::transaction::{EcdsaSigHashType, Transaction, TxOut}; use blockdata::transaction::{EcdsaSigHashType, Transaction, TxOut};
use consensus::encode::{self, serialize, Decodable, Encodable, deserialize_partial}; use consensus::encode::{self, serialize, Decodable, Encodable, deserialize_partial};
use secp256k1::{self, XOnlyPublicKey}; use secp256k1::{self, XOnlyPublicKey};
@ -51,7 +52,7 @@ pub trait Deserialize: Sized {
impl_psbt_de_serialize!(Transaction); impl_psbt_de_serialize!(Transaction);
impl_psbt_de_serialize!(TxOut); impl_psbt_de_serialize!(TxOut);
impl_psbt_de_serialize!(Vec<Vec<u8>>); // scriptWitness impl_psbt_de_serialize!(Witness);
impl_psbt_hash_de_serialize!(ripemd160::Hash); impl_psbt_hash_de_serialize!(ripemd160::Hash);
impl_psbt_hash_de_serialize!(sha256::Hash); impl_psbt_hash_de_serialize!(sha256::Hash);
impl_psbt_hash_de_serialize!(TapLeafHash); impl_psbt_hash_de_serialize!(TapLeafHash);