From 6b177f089359e48af43c2add2a945f615be924c7 Mon Sep 17 00:00:00 2001 From: thunderbiscuit Date: Wed, 6 Dec 2023 11:38:34 -0500 Subject: [PATCH] feat: add new types module --- bdk-ffi/src/bdk.udl | 68 ++++++---- bdk-ffi/src/bitcoin.rs | 19 +++ bdk-ffi/src/descriptor.rs | 3 + bdk-ffi/src/lib.rs | 266 +------------------------------------- bdk-ffi/src/types.rs | 148 +++++++++++++++++++++ bdk-ffi/src/wallet.rs | 13 +- 6 files changed, 228 insertions(+), 289 deletions(-) create mode 100644 bdk-ffi/src/types.rs diff --git a/bdk-ffi/src/bdk.udl b/bdk-ffi/src/bdk.udl index 7833eabd..924ccbc2 100644 --- a/bdk-ffi/src/bdk.udl +++ b/bdk-ffi/src/bdk.udl @@ -1,7 +1,7 @@ namespace bdk {}; // ------------------------------------------------------------------------ -// bdk crate - root module +// bdk crate - types module // ------------------------------------------------------------------------ enum KeychainKind { @@ -9,6 +9,45 @@ enum KeychainKind { "Internal", }; +dictionary AddressInfo { + u32 index; + Address address; + KeychainKind keychain; +}; + +[Enum] +interface AddressIndex { + New(); + LastUnused(); + Peek(u32 index); +}; + +dictionary Balance { + u64 immature; + + u64 trusted_pending; + + u64 untrusted_pending; + + u64 confirmed; + + u64 trusted_spendable; + + u64 total; +}; + +dictionary LocalUtxo { + OutPoint outpoint; + TxOut txout; + KeychainKind keychain; + boolean is_spent; +}; + +dictionary TxOut { + u64 value; + Script script_pubkey; +}; + // ------------------------------------------------------------------------ // bdk crate - wallet module // ------------------------------------------------------------------------ @@ -49,33 +88,6 @@ enum ChangeSpendPolicy { "ChangeForbidden" }; -dictionary Balance { - u64 immature; - - u64 trusted_pending; - - u64 untrusted_pending; - - u64 confirmed; - - u64 trusted_spendable; - - u64 total; -}; - -dictionary AddressInfo { - u32 index; - Address address; - KeychainKind keychain; -}; - -[Enum] -interface AddressIndex { - New(); - LastUnused(); - Peek(u32 index); -}; - interface Wallet { [Name=new_no_persist, Throws=BdkError] constructor(Descriptor descriptor, Descriptor? change_descriptor, Network network); diff --git a/bdk-ffi/src/bitcoin.rs b/bdk-ffi/src/bitcoin.rs index 72b41ceb..c5e521a0 100644 --- a/bdk-ffi/src/bitcoin.rs +++ b/bdk-ffi/src/bitcoin.rs @@ -1,5 +1,6 @@ use bdk::bitcoin::address::{NetworkChecked, NetworkUnchecked}; use bdk::bitcoin::blockdata::script::ScriptBuf as BdkScriptBuf; +use bdk::bitcoin::blockdata::transaction::TxOut as BdkTxOut; use bdk::bitcoin::consensus::Decodable; use bdk::bitcoin::network::constants::Network as BdkNetwork; use bdk::bitcoin::psbt::PartiallySignedTransaction as BdkPartiallySignedTransaction; @@ -309,3 +310,21 @@ impl From<&OutPoint> for BdkOutPoint { } } } + +/// A transaction output, which defines new coins to be created from old ones. +#[derive(Debug, Clone)] +pub struct TxOut { + /// The value of the output, in satoshis. + pub value: u64, + /// The address of the output. + pub script_pubkey: Arc