Skip to content

Commit

Permalink
feat: expose Wallet::derivation_of_spk method
Browse files Browse the repository at this point in the history
  • Loading branch information
thunderbiscuit committed Oct 9, 2024
1 parent f6a0b36 commit c8a8983
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
11 changes: 9 additions & 2 deletions bdk-ffi/src/bdk.udl
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -633,6 +635,11 @@ dictionary SentAndReceivedValues {
Amount received;
};

dictionary KeychainAndIndex {
KeychainKind keychain;
u32 index;
};

// ------------------------------------------------------------------------
// bdk_wallet crate - bitcoin re-exports
// ------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions bdk-ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions bdk-ffi/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,3 +232,8 @@ pub struct SentAndReceivedValues {
pub sent: Arc<Amount>,
pub received: Arc<Amount>,
}

pub struct KeychainAndIndex {
pub keychain: KeychainKind,
pub index: u32,
}
13 changes: 11 additions & 2 deletions bdk-ffi/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -72,6 +72,15 @@ impl Wallet {
self.inner_mutex.lock().expect("wallet")
}

pub fn derivation_of_spk(&self, spk: Arc<Script>) -> Option<KeychainAndIndex> {
self.get_wallet()
.derivation_of_spk(spk.0.clone())
.map(|(k, i)| KeychainAndIndex {
keychain: k,
index: i,
})
}

pub fn cancel_tx(&self, tx: &Transaction) {
self.get_wallet().cancel_tx(&tx.into())
}
Expand Down

0 comments on commit c8a8983

Please sign in to comment.