diff --git a/bdk-ffi/src/bdk.udl b/bdk-ffi/src/bdk.udl index da76097..8ae88d0 100644 --- a/bdk-ffi/src/bdk.udl +++ b/bdk-ffi/src/bdk.udl @@ -435,9 +435,42 @@ interface Address { [Throws=BdkError] constructor(string address); + Payload payload(); + + Network network(); + Script script_pubkey(); }; +[Enum] +interface Payload { + PubkeyHash(sequence pubkey_hash); + + ScriptHash(sequence script_hash); + + WitnessProgram(WitnessVersion version, sequence program); +}; + +enum WitnessVersion { + "V0", + "V1", + "V2", + "V3", + "V4", + "V5", + "V6", + "V7", + "V8", + "V9", + "V10", + "V11", + "V12", + "V13", + "V14", + "V15", + "V16" +}; + interface Script { constructor(sequence raw_output_script); }; diff --git a/bdk-ffi/src/lib.rs b/bdk-ffi/src/lib.rs index 1583854..1e0e04b 100644 --- a/bdk-ffi/src/lib.rs +++ b/bdk-ffi/src/lib.rs @@ -19,6 +19,7 @@ use bdk::bitcoin::blockdata::transaction::TxIn as BdkTxIn; use bdk::bitcoin::blockdata::transaction::TxOut as BdkTxOut; use bdk::bitcoin::consensus::Decodable; use bdk::bitcoin::psbt::serialize::Serialize; +use bdk::bitcoin::util::address::{Payload as BdkPayload, WitnessVersion}; use bdk::bitcoin::{ Address as BdkAddress, Network, OutPoint as BdkOutPoint, Transaction as BdkTransaction, Txid, }; @@ -356,6 +357,25 @@ impl Address { .map_err(|e| BdkError::Generic(e.to_string())) } + fn payload(&self) -> Payload { + match &self.address.payload.clone() { + BdkPayload::PubkeyHash(pubkey_hash) => Payload::PubkeyHash { + pubkey_hash: pubkey_hash.to_vec(), + }, + BdkPayload::ScriptHash(script_hash) => Payload::ScriptHash { + script_hash: script_hash.to_vec(), + }, + BdkPayload::WitnessProgram { version, program } => Payload::WitnessProgram { + version: *version, + program: program.clone(), + }, + } + } + + fn network(&self) -> Network { + self.address.network + } + fn script_pubkey(&self) -> Arc