From 00c34663638a28cbae534a8f2effe4d64bc5565e Mon Sep 17 00:00:00 2001 From: Dr Maxim Orlovsky Date: Sun, 11 Oct 2020 04:25:39 +0200 Subject: [PATCH] Serde implementation for PSBT --- src/util/psbt/map/global.rs | 1 + src/util/psbt/map/input.rs | 5 +++++ src/util/psbt/map/output.rs | 3 +++ src/util/psbt/mod.rs | 1 + src/util/psbt/raw.rs | 2 ++ 5 files changed, 12 insertions(+) diff --git a/src/util/psbt/map/global.rs b/src/util/psbt/map/global.rs index f6b411d4..681a3e1b 100644 --- a/src/util/psbt/map/global.rs +++ b/src/util/psbt/map/global.rs @@ -32,6 +32,7 @@ pub struct Global { /// Unknown global key-value pairs. pub unknown: BTreeMap>, } +serde_struct_impl!(Global, unsigned_tx, unknown); impl Global { /// Create a Global from an unsigned transaction, error if not unsigned diff --git a/src/util/psbt/map/input.rs b/src/util/psbt/map/input.rs index 72f33942..4481f755 100644 --- a/src/util/psbt/map/input.rs +++ b/src/util/psbt/map/input.rs @@ -58,6 +58,11 @@ pub struct Input { /// Unknown key-value pairs for this input. pub unknown: BTreeMap>, } +serde_struct_impl!( + Input, non_witness_utxo, witness_utxo, partial_sigs, + sighash_type, redeem_script, witness_script, hd_keypaths, + final_script_sig, final_script_witness, unknown +); impl Map for Input { fn insert_pair(&mut self, pair: raw::Pair) -> Result<(), encode::Error> { diff --git a/src/util/psbt/map/output.rs b/src/util/psbt/map/output.rs index 856396aa..a089fdbc 100644 --- a/src/util/psbt/map/output.rs +++ b/src/util/psbt/map/output.rs @@ -38,6 +38,9 @@ pub struct Output { /// Unknown key-value pairs for this output. pub unknown: BTreeMap>, } +serde_struct_impl!( + Output, redeem_script, witness_script, hd_keypaths, unknown +); impl Map for Output { fn insert_pair(&mut self, pair: raw::Pair) -> Result<(), encode::Error> { diff --git a/src/util/psbt/mod.rs b/src/util/psbt/mod.rs index 1fe55d04..cbf47ab7 100644 --- a/src/util/psbt/mod.rs +++ b/src/util/psbt/mod.rs @@ -49,6 +49,7 @@ pub struct PartiallySignedTransaction { /// transaction. pub outputs: Vec, } +serde_struct_impl!(PartiallySignedTransaction, global, inputs, outputs); impl PartiallySignedTransaction { /// Create a PartiallySignedTransaction from an unsigned transaction, error diff --git a/src/util/psbt/raw.rs b/src/util/psbt/raw.rs index 9bf73ff9..16185715 100644 --- a/src/util/psbt/raw.rs +++ b/src/util/psbt/raw.rs @@ -31,6 +31,7 @@ pub struct Key { /// The key itself in raw byte form. pub key: Vec, } +serde_struct_impl!(Key, type_value, key); /// A PSBT key-value pair in its raw byte form. #[derive(Debug, PartialEq)] @@ -40,6 +41,7 @@ pub struct Pair { /// The value of this key-value pair in raw byte form. pub value: Vec, } +serde_struct_impl!(Pair, key, value); impl fmt::Display for Key { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {