From 3e924ef53f804c40628635941b5db7430c53164f Mon Sep 17 00:00:00 2001 From: thesimplekid Date: Tue, 29 Nov 2022 20:37:17 -0500 Subject: [PATCH 1/3] add decodepsbt --- client/src/client.rs | 4 ++ json/src/lib.rs | 105 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 109 insertions(+) diff --git a/client/src/client.rs b/client/src/client.rs index fb6f44b8..a4e16c2e 100644 --- a/client/src/client.rs +++ b/client/src/client.rs @@ -1168,6 +1168,10 @@ pub trait RpcApi: Sized { self.call("finalizepsbt", handle_defaults(&mut args, &[true.into()])) } + fn decode_psbt(&self, psbt: &str) -> Result { + self.call("decodepsbt", &[into_json(psbt)?]) + } + fn derive_addresses(&self, descriptor: &str, range: Option<[u32; 2]>) -> Result> { let mut args = [into_json(descriptor)?, opt_into_json(range)?]; self.call("deriveaddresses", handle_defaults(&mut args, &[null()])) diff --git a/json/src/lib.rs b/json/src/lib.rs index 6a251eb2..d7e9ee71 100644 --- a/json/src/lib.rs +++ b/json/src/lib.rs @@ -1731,6 +1731,111 @@ pub struct DecodeRawTransactionResult { pub vout: Vec, } +#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)] +pub struct DecodePsbtResultTransaction { + pub txid: bitcoin::Txid, + pub hash: bitcoin::Wtxid, + pub version: u32, + pub size: u32, + pub vsize: u32, + pub weight: u32, + pub locktime: u32, + pub vin: Vec, + pub vout: Vec, +} + +#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct DecodePsbtResultInputWitnessUtxo { + #[serde(with = "bitcoin::util::amount::serde::as_btc")] + pub amount: Amount, + pub script_pub_key: GetRawTransactionResultVoutScriptPubKey, +} + +#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)] +pub struct DecodePsbtResultScript { + pub asm: String, + #[serde(with = "crate::serde_hex")] + pub hex: Vec, + #[serde(rename = "type")] + pub type_: String, +} + +#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)] +pub struct DecodePsbtResultBip32Derivs { + pub master_fingerprint: String, + pub path: String, + pub pubkey: String, +} + +#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)] +pub struct DecodePsbtResultInput { + pub non_witness_utxo: Option, + pub witness_utxo: Option, + pub partial_signatures: Option>, + pub sighash: Option, + pub redeem_script: Option, + pub witness_script: Option, + pub bip32_derivs: Option>, + pub final_scriptsig: Option, + pub final_scriptwitness: Option>, + pub ripemd160_preimages: Option>, + pub sha256_preimages: Option>, + pub hash160_preimages: Option>, + pub hash256_preimages: Option>, + pub unknown: Option>>, + #[serde(default)] + pub proprietary: Vec, +} + +#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)] +pub struct DecodePsbtResultOutput { + pub redeem_script: Option, + pub witness_script: Option, + pub bip32_derivs: Option>, + pub unknown: Option>>, + #[serde(default)] + pub proprietary: Vec, +} + +#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)] +pub struct DecodePsbtResultGlobalXpubs { + pub xpub: String, + #[serde(with = "crate::serde_hex")] + pub master_fingerprint: Vec, + pub path: String, +} + +#[derive(Clone, PartialEq, Eq, Debug, Default, Deserialize, Serialize)] +pub struct DecodePsbtResultProprietary { + #[serde(with = "crate::serde_hex")] + pub identifier: Vec, + subtype: u32, + #[serde(with = "crate::serde_hex")] + key: Vec, + #[serde(with = "crate::serde_hex")] + value: Vec, +} + +/// Models the result of "decodepsbt" +#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)] +pub struct DecodePsbtResult { + pub tx: DecodePsbtResultTransaction, + #[serde(default)] + pub global_xpubs: Vec, + pub psbt_version: u32, + pub proprietary: Vec, + pub unknown: HashMap, + pub inputs: Vec, + pub outputs: Vec, + #[serde( + default, + with = "bitcoin::util::amount::serde::as_btc::opt", + skip_serializing_if = "Option::is_none" + )] + pub fee: Option, +} + /// Models the result of "getchaintips" pub type GetChainTipsResult = Vec; From 8fdb14f5971f6dac58290a3da0710957827e2a65 Mon Sep 17 00:00:00 2001 From: thesimplekid Date: Mon, 19 Dec 2022 09:51:01 -0500 Subject: [PATCH 2/3] `psbt_version` and `proprierary` as options --- json/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/json/src/lib.rs b/json/src/lib.rs index d7e9ee71..c21516d2 100644 --- a/json/src/lib.rs +++ b/json/src/lib.rs @@ -1823,8 +1823,8 @@ pub struct DecodePsbtResult { pub tx: DecodePsbtResultTransaction, #[serde(default)] pub global_xpubs: Vec, - pub psbt_version: u32, - pub proprietary: Vec, + pub psbt_version: Option, + pub proprietary: Option>, pub unknown: HashMap, pub inputs: Vec, pub outputs: Vec, From 7fdc58f022c49a9153df73d4b728fa1852f3a06a Mon Sep 17 00:00:00 2001 From: thesimplekid Date: Sat, 24 Dec 2022 02:50:16 -0500 Subject: [PATCH 3/3] taproot fields --- json/src/lib.rs | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/json/src/lib.rs b/json/src/lib.rs index c21516d2..326c4a9a 100644 --- a/json/src/lib.rs +++ b/json/src/lib.rs @@ -1783,16 +1783,55 @@ pub struct DecodePsbtResultInput { pub sha256_preimages: Option>, pub hash160_preimages: Option>, pub hash256_preimages: Option>, + pub taproot_key_path_sig: Option>, + pub taproot_script_path_sigs: Option>, + pub taproot_scripts: Option>, + pub taproot_bip32_derivs: Option, + pub taproot_internal_key: Option, + pub taproot_merkle_root: Option, pub unknown: Option>>, #[serde(default)] pub proprietary: Vec, } +#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)] +pub struct DecodePsbtResultTaprootScriptPathSig { + pub pubkey: String, + pub leaf_hash: String, + pub sig: String, +} + +#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)] +pub struct DecodePsbtResultTaprootScript { + #[serde(with = "crate::serde_hex")] + pub script: Vec, + pub leaf_ver: u32, + pub control_blocks: Vec>, +} + +#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)] +pub struct DecodePsbtResultTaprootTree { + pub depth: u32, + pub leaf_ver: u32, + pub script: String, +} + +#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)] +pub struct DecodePsbtResultTaprootBip32Derivs { + pub pubkey: String, + pub master_fingerprint: String, + pub path: String, + pub leaf_hashes: Vec, +} + #[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)] pub struct DecodePsbtResultOutput { pub redeem_script: Option, pub witness_script: Option, pub bip32_derivs: Option>, + pub taproot_internal_key: Option>, + pub taproot_tree: Option>, + pub taproot_bip32_derivs: Option, pub unknown: Option>>, #[serde(default)] pub proprietary: Vec,