From 3fefd3c1fbacb058e1505795294055f33b1608c2 Mon Sep 17 00:00:00 2001 From: thunderbiscuit Date: Thu, 1 Sep 2022 13:05:35 -0400 Subject: [PATCH] Allow TxBuilder.add_recipient() to take Script --- src/bdk.udl | 21 ++++++++++++--- src/lib.rs | 77 +++++++++++++++++++++++++++++++++++++++++------------ 2 files changed, 77 insertions(+), 21 deletions(-) diff --git a/src/bdk.udl b/src/bdk.udl index 39f3d0af..c03dd4e2 100644 --- a/src/bdk.udl +++ b/src/bdk.udl @@ -173,8 +173,8 @@ dictionary LocalUtxo { boolean is_spent; }; -dictionary AddressAmount { - string address; +dictionary ScriptAmount { + Script script; u64 amount; }; @@ -211,6 +211,8 @@ interface PartiallySignedBitcoinTransaction { string txid(); + sequence extract_tx(); + [Throws=Error] PartiallySignedBitcoinTransaction combine(PartiallySignedBitcoinTransaction other); }; @@ -218,7 +220,7 @@ interface PartiallySignedBitcoinTransaction { interface TxBuilder { constructor(); - TxBuilder add_recipient(string address, u64 amount); + TxBuilder add_recipient(Script script, u64 amount); TxBuilder add_unspendable(OutPoint unspendable); @@ -248,7 +250,7 @@ interface TxBuilder { TxBuilder add_data(sequence data); - TxBuilder set_recipients(sequence recipients); + TxBuilder set_recipients(sequence recipients); [Throws=Error] PartiallySignedBitcoinTransaction finish([ByRef] Wallet wallet); @@ -296,3 +298,14 @@ interface DescriptorPublicKey { string as_string(); }; + +interface Address { + [Throws=Error] + constructor(string address); + + Script script_pubkey(); +}; + +interface Script { + constructor(sequence raw_output_script); +}; diff --git a/src/lib.rs b/src/lib.rs index 586b2e22..a59cff6a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,8 +1,10 @@ +use bdk::bitcoin::blockdata::script::Script as BdkScript; use bdk::bitcoin::hashes::hex::ToHex; use bdk::bitcoin::secp256k1::Secp256k1; use bdk::bitcoin::util::bip32::DerivationPath as BdkDerivationPath; +use bdk::bitcoin::util::psbt::serialize::Serialize; use bdk::bitcoin::util::psbt::PartiallySignedTransaction; -use bdk::bitcoin::{Address, Network, OutPoint as BdkOutPoint, Script, Txid}; +use bdk::bitcoin::{Address as BdkAddress, Network, OutPoint as BdkOutPoint, Txid}; use bdk::blockchain::any::{AnyBlockchain, AnyBlockchainConfig}; use bdk::blockchain::GetBlockHash; use bdk::blockchain::GetHeight; @@ -35,8 +37,9 @@ use std::sync::{Arc, Mutex, MutexGuard}; uniffi_macros::include_scaffolding!("bdk"); -pub struct AddressAmount { - pub address: String, +/// A output script and an amount of satoshis. +pub struct ScriptAmount { + pub script: Arc