Serde implementation for PSBT

This commit is contained in:
Dr Maxim Orlovsky 2020-10-11 04:25:39 +02:00
parent a4a7035a94
commit 00c3466363
No known key found for this signature in database
GPG Key ID: FFC0250947E5C6F7
5 changed files with 12 additions and 0 deletions

View File

@ -32,6 +32,7 @@ pub struct Global {
/// Unknown global key-value pairs. /// Unknown global key-value pairs.
pub unknown: BTreeMap<raw::Key, Vec<u8>>, pub unknown: BTreeMap<raw::Key, Vec<u8>>,
} }
serde_struct_impl!(Global, unsigned_tx, unknown);
impl Global { impl Global {
/// Create a Global from an unsigned transaction, error if not unsigned /// Create a Global from an unsigned transaction, error if not unsigned

View File

@ -58,6 +58,11 @@ pub struct Input {
/// Unknown key-value pairs for this input. /// Unknown key-value pairs for this input.
pub unknown: BTreeMap<raw::Key, Vec<u8>>, pub unknown: BTreeMap<raw::Key, Vec<u8>>,
} }
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 { impl Map for Input {
fn insert_pair(&mut self, pair: raw::Pair) -> Result<(), encode::Error> { fn insert_pair(&mut self, pair: raw::Pair) -> Result<(), encode::Error> {

View File

@ -38,6 +38,9 @@ pub struct Output {
/// Unknown key-value pairs for this output. /// Unknown key-value pairs for this output.
pub unknown: BTreeMap<raw::Key, Vec<u8>>, pub unknown: BTreeMap<raw::Key, Vec<u8>>,
} }
serde_struct_impl!(
Output, redeem_script, witness_script, hd_keypaths, unknown
);
impl Map for Output { impl Map for Output {
fn insert_pair(&mut self, pair: raw::Pair) -> Result<(), encode::Error> { fn insert_pair(&mut self, pair: raw::Pair) -> Result<(), encode::Error> {

View File

@ -49,6 +49,7 @@ pub struct PartiallySignedTransaction {
/// transaction. /// transaction.
pub outputs: Vec<Output>, pub outputs: Vec<Output>,
} }
serde_struct_impl!(PartiallySignedTransaction, global, inputs, outputs);
impl PartiallySignedTransaction { impl PartiallySignedTransaction {
/// Create a PartiallySignedTransaction from an unsigned transaction, error /// Create a PartiallySignedTransaction from an unsigned transaction, error

View File

@ -31,6 +31,7 @@ pub struct Key {
/// The key itself in raw byte form. /// The key itself in raw byte form.
pub key: Vec<u8>, pub key: Vec<u8>,
} }
serde_struct_impl!(Key, type_value, key);
/// A PSBT key-value pair in its raw byte form. /// A PSBT key-value pair in its raw byte form.
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq)]
@ -40,6 +41,7 @@ pub struct Pair {
/// The value of this key-value pair in raw byte form. /// The value of this key-value pair in raw byte form.
pub value: Vec<u8>, pub value: Vec<u8>,
} }
serde_struct_impl!(Pair, key, value);
impl fmt::Display for Key { impl fmt::Display for Key {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {