Skip to content

Commit 3e924ef

Browse files
committed
add decodepsbt
1 parent 9e6dff7 commit 3e924ef

File tree

2 files changed

+109
-0
lines changed

2 files changed

+109
-0
lines changed

client/src/client.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1168,6 +1168,10 @@ pub trait RpcApi: Sized {
11681168
self.call("finalizepsbt", handle_defaults(&mut args, &[true.into()]))
11691169
}
11701170

1171+
fn decode_psbt(&self, psbt: &str) -> Result<json::DecodePsbtResult> {
1172+
self.call("decodepsbt", &[into_json(psbt)?])
1173+
}
1174+
11711175
fn derive_addresses(&self, descriptor: &str, range: Option<[u32; 2]>) -> Result<Vec<Address>> {
11721176
let mut args = [into_json(descriptor)?, opt_into_json(range)?];
11731177
self.call("deriveaddresses", handle_defaults(&mut args, &[null()]))

json/src/lib.rs

+105
Original file line numberDiff line numberDiff line change
@@ -1731,6 +1731,111 @@ pub struct DecodeRawTransactionResult {
17311731
pub vout: Vec<GetRawTransactionResultVout>,
17321732
}
17331733

1734+
#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)]
1735+
pub struct DecodePsbtResultTransaction {
1736+
pub txid: bitcoin::Txid,
1737+
pub hash: bitcoin::Wtxid,
1738+
pub version: u32,
1739+
pub size: u32,
1740+
pub vsize: u32,
1741+
pub weight: u32,
1742+
pub locktime: u32,
1743+
pub vin: Vec<GetRawTransactionResultVin>,
1744+
pub vout: Vec<GetRawTransactionResultVout>,
1745+
}
1746+
1747+
#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)]
1748+
#[serde(rename_all = "camelCase")]
1749+
pub struct DecodePsbtResultInputWitnessUtxo {
1750+
#[serde(with = "bitcoin::util::amount::serde::as_btc")]
1751+
pub amount: Amount,
1752+
pub script_pub_key: GetRawTransactionResultVoutScriptPubKey,
1753+
}
1754+
1755+
#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)]
1756+
pub struct DecodePsbtResultScript {
1757+
pub asm: String,
1758+
#[serde(with = "crate::serde_hex")]
1759+
pub hex: Vec<u8>,
1760+
#[serde(rename = "type")]
1761+
pub type_: String,
1762+
}
1763+
1764+
#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)]
1765+
pub struct DecodePsbtResultBip32Derivs {
1766+
pub master_fingerprint: String,
1767+
pub path: String,
1768+
pub pubkey: String,
1769+
}
1770+
1771+
#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)]
1772+
pub struct DecodePsbtResultInput {
1773+
pub non_witness_utxo: Option<DecodePsbtResultTransaction>,
1774+
pub witness_utxo: Option<DecodePsbtResultInputWitnessUtxo>,
1775+
pub partial_signatures: Option<HashMap<String, String>>,
1776+
pub sighash: Option<String>,
1777+
pub redeem_script: Option<DecodePsbtResultScript>,
1778+
pub witness_script: Option<DecodePsbtResultScript>,
1779+
pub bip32_derivs: Option<Vec<DecodePsbtResultBip32Derivs>>,
1780+
pub final_scriptsig: Option<GetRawTransactionResultVinScriptSig>,
1781+
pub final_scriptwitness: Option<Vec<String>>,
1782+
pub ripemd160_preimages: Option<HashMap<String, String>>,
1783+
pub sha256_preimages: Option<HashMap<String, String>>,
1784+
pub hash160_preimages: Option<HashMap<String, String>>,
1785+
pub hash256_preimages: Option<HashMap<String, String>>,
1786+
pub unknown: Option<HashMap<String, Vec<u8>>>,
1787+
#[serde(default)]
1788+
pub proprietary: Vec<DecodePsbtResultProprietary>,
1789+
}
1790+
1791+
#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)]
1792+
pub struct DecodePsbtResultOutput {
1793+
pub redeem_script: Option<DecodePsbtResultScript>,
1794+
pub witness_script: Option<DecodePsbtResultScript>,
1795+
pub bip32_derivs: Option<Vec<DecodePsbtResultBip32Derivs>>,
1796+
pub unknown: Option<HashMap<String, Vec<u8>>>,
1797+
#[serde(default)]
1798+
pub proprietary: Vec<DecodePsbtResultProprietary>,
1799+
}
1800+
1801+
#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)]
1802+
pub struct DecodePsbtResultGlobalXpubs {
1803+
pub xpub: String,
1804+
#[serde(with = "crate::serde_hex")]
1805+
pub master_fingerprint: Vec<u8>,
1806+
pub path: String,
1807+
}
1808+
1809+
#[derive(Clone, PartialEq, Eq, Debug, Default, Deserialize, Serialize)]
1810+
pub struct DecodePsbtResultProprietary {
1811+
#[serde(with = "crate::serde_hex")]
1812+
pub identifier: Vec<u8>,
1813+
subtype: u32,
1814+
#[serde(with = "crate::serde_hex")]
1815+
key: Vec<u8>,
1816+
#[serde(with = "crate::serde_hex")]
1817+
value: Vec<u8>,
1818+
}
1819+
1820+
/// Models the result of "decodepsbt"
1821+
#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)]
1822+
pub struct DecodePsbtResult {
1823+
pub tx: DecodePsbtResultTransaction,
1824+
#[serde(default)]
1825+
pub global_xpubs: Vec<DecodePsbtResultGlobalXpubs>,
1826+
pub psbt_version: u32,
1827+
pub proprietary: Vec<DecodePsbtResultProprietary>,
1828+
pub unknown: HashMap<String, String>,
1829+
pub inputs: Vec<DecodePsbtResultInput>,
1830+
pub outputs: Vec<DecodePsbtResultOutput>,
1831+
#[serde(
1832+
default,
1833+
with = "bitcoin::util::amount::serde::as_btc::opt",
1834+
skip_serializing_if = "Option::is_none"
1835+
)]
1836+
pub fee: Option<Amount>,
1837+
}
1838+
17341839
/// Models the result of "getchaintips"
17351840
pub type GetChainTipsResult = Vec<GetChainTipsResultTip>;
17361841

0 commit comments

Comments
 (0)