Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add wallet apis #601

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions bdk-ffi/src/bdk.udl
Original file line number Diff line number Diff line change
Expand Up @@ -375,8 +375,14 @@ interface Wallet {
[Name=load, Throws=LoadWithPersistError]
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 @@ -629,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,
}
25 changes: 22 additions & 3 deletions bdk-ffi/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ 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, Script};
use bitcoin_ffi::{Amount, FeeRate, OutPoint, Script};

use bdk_wallet::bitcoin::{Network, Txid};
use bdk_wallet::rusqlite::Connection as BdkConnection;
Expand Down Expand Up @@ -72,6 +72,25 @@ 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())
}

pub fn get_utxo(&self, op: OutPoint) -> Option<LocalOutput> {
self.get_wallet()
.get_utxo(op)
.map(|local_output| local_output.into())
}

pub fn reveal_next_address(&self, keychain: KeychainKind) -> AddressInfo {
self.get_wallet().reveal_next_address(keychain).into()
}
Expand Down
Loading