Skip to content

Commit c244442

Browse files
committed
add decodepsbt
1 parent bdc9f9b commit c244442

File tree

2 files changed

+109
-0
lines changed

2 files changed

+109
-0
lines changed

client/src/client.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,6 +1123,10 @@ pub trait RpcApi: Sized {
11231123
self.call("finalizepsbt", handle_defaults(&mut args, &[true.into()]))
11241124
}
11251125

1126+
fn decode_psbt(&self, psbt: &str) -> Result<json::DecodePsbtResult> {
1127+
self.call("decodepsbt", &[into_json(psbt)?])
1128+
}
1129+
11261130
fn derive_addresses(&self, descriptor: &str, range: Option<[u32; 2]>) -> Result<Vec<Address>> {
11271131
let mut args = [into_json(descriptor)?, opt_into_json(range)?];
11281132
self.call("deriveaddresses", handle_defaults(&mut args, &[null()]))

json/src/lib.rs

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1697,6 +1697,111 @@ pub struct FinalizePsbtResult {
16971697
pub complete: bool,
16981698
}
16991699

1700+
#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)]
1701+
pub struct DecodePsbtResultTransaction {
1702+
pub txid: bitcoin::Txid,
1703+
pub hash: bitcoin::Wtxid,
1704+
pub version: u32,
1705+
pub size: u32,
1706+
pub vsize: u32,
1707+
pub weight: u32,
1708+
pub locktime: u32,
1709+
pub vin: Vec<GetRawTransactionResultVin>,
1710+
pub vout: Vec<GetRawTransactionResultVout>,
1711+
}
1712+
1713+
#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)]
1714+
#[serde(rename_all = "camelCase")]
1715+
pub struct DecodePsbtResultInputWitnessUtxo {
1716+
#[serde(with = "bitcoin::util::amount::serde::as_btc")]
1717+
pub amount: Amount,
1718+
pub script_pub_key: GetRawTransactionResultVoutScriptPubKey,
1719+
}
1720+
1721+
#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)]
1722+
pub struct DecodePsbtResultScript {
1723+
pub asm: String,
1724+
#[serde(with = "crate::serde_hex")]
1725+
pub hex: Vec<u8>,
1726+
#[serde(rename = "type")]
1727+
pub type_: String,
1728+
}
1729+
1730+
#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)]
1731+
pub struct DecodePsbtResultBip32Derivs {
1732+
pub master_fingerprint: String,
1733+
pub path: String,
1734+
pub pubkey: String,
1735+
}
1736+
1737+
#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)]
1738+
pub struct DecodePsbtResultInput {
1739+
pub non_witness_utxo: Option<DecodePsbtResultTransaction>,
1740+
pub witness_utxo: Option<DecodePsbtResultInputWitnessUtxo>,
1741+
pub partial_signatures: Option<HashMap<String, String>>,
1742+
pub sighash: Option<String>,
1743+
pub redeem_script: Option<DecodePsbtResultScript>,
1744+
pub witness_script: Option<DecodePsbtResultScript>,
1745+
pub bip32_derivs: Option<Vec<DecodePsbtResultBip32Derivs>>,
1746+
pub final_scriptsig: Option<GetRawTransactionResultVinScriptSig>,
1747+
pub final_scriptwitness: Option<Vec<String>>,
1748+
pub ripemd160_preimages: Option<HashMap<String, String>>,
1749+
pub sha256_preimages: Option<HashMap<String, String>>,
1750+
pub hash160_preimages: Option<HashMap<String, String>>,
1751+
pub hash256_preimages: Option<HashMap<String, String>>,
1752+
pub unknown: Option<HashMap<String, Vec<u8>>>,
1753+
#[serde(default)]
1754+
pub proprietary: Vec<DecodePsbtResultProprietary>,
1755+
}
1756+
1757+
#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)]
1758+
pub struct DecodePsbtResultOutput {
1759+
pub redeem_script: Option<DecodePsbtResultScript>,
1760+
pub witness_script: Option<DecodePsbtResultScript>,
1761+
pub bip32_derivs: Option<Vec<DecodePsbtResultBip32Derivs>>,
1762+
pub unknown: Option<HashMap<String, Vec<u8>>>,
1763+
#[serde(default)]
1764+
pub proprietary: Vec<DecodePsbtResultProprietary>,
1765+
}
1766+
1767+
#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)]
1768+
pub struct DecodePsbtResultGlobalXpubs {
1769+
pub xpub: String,
1770+
#[serde(with = "crate::serde_hex")]
1771+
pub master_fingerprint: Vec<u8>,
1772+
pub path: String,
1773+
}
1774+
1775+
#[derive(Clone, PartialEq, Eq, Debug, Default, Deserialize, Serialize)]
1776+
pub struct DecodePsbtResultProprietary {
1777+
#[serde(with = "crate::serde_hex")]
1778+
pub identifier: Vec<u8>,
1779+
subtype: u32,
1780+
#[serde(with = "crate::serde_hex")]
1781+
key: Vec<u8>,
1782+
#[serde(with = "crate::serde_hex")]
1783+
value: Vec<u8>,
1784+
}
1785+
1786+
/// Models the result of "decodepsbt"
1787+
#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)]
1788+
pub struct DecodePsbtResult {
1789+
pub tx: DecodePsbtResultTransaction,
1790+
#[serde(default)]
1791+
pub global_xpubs: Vec<DecodePsbtResultGlobalXpubs>,
1792+
pub psbt_version: u32,
1793+
pub proprietary: Vec<DecodePsbtResultProprietary>,
1794+
pub unknown: HashMap<String, String>,
1795+
pub inputs: Vec<DecodePsbtResultInput>,
1796+
pub outputs: Vec<DecodePsbtResultOutput>,
1797+
#[serde(
1798+
default,
1799+
with = "bitcoin::util::amount::serde::as_btc::opt",
1800+
skip_serializing_if = "Option::is_none"
1801+
)]
1802+
pub fee: Option<Amount>,
1803+
}
1804+
17001805
/// Models the result of "getchaintips"
17011806
pub type GetChainTipsResult = Vec<GetChainTipsResultTip>;
17021807

0 commit comments

Comments
 (0)