From c8a8983ee401894c3247869df5f57818f8702ead Mon Sep 17 00:00:00 2001 From: thunderbiscuit Date: Tue, 8 Oct 2024 15:40:36 -0400 Subject: [PATCH] feat: expose Wallet::derivation_of_spk method --- bdk-ffi/src/bdk.udl | 11 +++++++++-- bdk-ffi/src/lib.rs | 1 + bdk-ffi/src/types.rs | 5 +++++ bdk-ffi/src/wallet.rs | 13 +++++++++++-- 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/bdk-ffi/src/bdk.udl b/bdk-ffi/src/bdk.udl index 29d0a136..1c716777 100644 --- a/bdk-ffi/src/bdk.udl +++ b/bdk-ffi/src/bdk.udl @@ -376,11 +376,13 @@ interface Wallet { constructor(Descriptor descriptor, Descriptor change_descriptor, Connection connection); void cancel_tx([ByRef] Transaction tx); - + u32? derivation_index(KeychainKind keychain); LocalOutput? get_utxo(OutPoint op); - + + KeychainAndIndex? derivation_of_spk(Script spk); + AddressInfo reveal_next_address(KeychainKind keychain); AddressInfo peek_address(KeychainKind keychain, u32 index); @@ -633,6 +635,11 @@ dictionary SentAndReceivedValues { Amount received; }; +dictionary KeychainAndIndex { + KeychainKind keychain; + u32 index; +}; + // ------------------------------------------------------------------------ // bdk_wallet crate - bitcoin re-exports // ------------------------------------------------------------------------ diff --git a/bdk-ffi/src/lib.rs b/bdk-ffi/src/lib.rs index 110b21cc..b8db0d78 100644 --- a/bdk-ffi/src/lib.rs +++ b/bdk-ffi/src/lib.rs @@ -55,6 +55,7 @@ use crate::types::ConfirmationBlockTime; use crate::types::FullScanRequest; use crate::types::FullScanRequestBuilder; use crate::types::FullScanScriptInspector; +use crate::types::KeychainAndIndex; use crate::types::LocalOutput; use crate::types::ScriptAmount; use crate::types::SentAndReceivedValues; diff --git a/bdk-ffi/src/types.rs b/bdk-ffi/src/types.rs index 9191c930..eaf3a2ac 100644 --- a/bdk-ffi/src/types.rs +++ b/bdk-ffi/src/types.rs @@ -232,3 +232,8 @@ pub struct SentAndReceivedValues { pub sent: Arc, pub received: Arc, } + +pub struct KeychainAndIndex { + pub keychain: KeychainKind, + pub index: u32, +} diff --git a/bdk-ffi/src/wallet.rs b/bdk-ffi/src/wallet.rs index 060bb747..fd8d4b75 100644 --- a/bdk-ffi/src/wallet.rs +++ b/bdk-ffi/src/wallet.rs @@ -6,8 +6,8 @@ use crate::error::{ }; use crate::store::Connection; use crate::types::{ - AddressInfo, Balance, CanonicalTx, FullScanRequestBuilder, LocalOutput, SentAndReceivedValues, - SyncRequestBuilder, Update, + AddressInfo, Balance, CanonicalTx, FullScanRequestBuilder, KeychainAndIndex, LocalOutput, + SentAndReceivedValues, SyncRequestBuilder, Update, }; use bitcoin_ffi::{Amount, FeeRate, OutPoint, Script}; @@ -72,6 +72,15 @@ impl Wallet { self.inner_mutex.lock().expect("wallet") } + pub fn derivation_of_spk(&self, spk: Arc