Skip to content

Commit

Permalink
feat: add public_descriptor method to wallet
Browse files Browse the repository at this point in the history
  • Loading branch information
reez committed Oct 20, 2024
1 parent ed2aadf commit 1635dbf
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
8 changes: 8 additions & 0 deletions bdk-ffi/src/bdk.udl
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,8 @@ interface Wallet {

[Throws=SqliteError]
boolean persist(Connection connection);

ExtendedDescriptor public_descriptor(KeychainKind keychain);
};

interface Update {};
Expand Down Expand Up @@ -581,6 +583,12 @@ interface Descriptor {
constructor([ByRef] DescriptorPublicKey public_key, string fingerprint, KeychainKind keychain, Network network);

string to_string_with_secret();

ExtendedDescriptor to_extended_descriptor();
};

interface ExtendedDescriptor {
string to_string();
};

// ------------------------------------------------------------------------
Expand Down
5 changes: 5 additions & 0 deletions bdk-ffi/src/descriptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use bdk_wallet::KeychainKind;

use std::fmt::Display;
use std::str::FromStr;
use std::sync::Arc;

#[derive(Debug)]
pub struct Descriptor {
Expand Down Expand Up @@ -266,6 +267,10 @@ impl Descriptor {
let key_map = &self.key_map;
descriptor.to_string_with_secret(key_map)
}

pub(crate) fn to_extended_descriptor(&self) -> Arc<ExtendedDescriptor> {
self.extended_descriptor.clone().into()
}
}

impl Display for Descriptor {
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 @@ -71,6 +71,7 @@ use bitcoin_ffi::Network;
use bitcoin_ffi::OutPoint;
use bitcoin_ffi::Script;

use bdk_wallet::descriptor::ExtendedDescriptor;
use bdk_wallet::keys::bip39::WordCount;
use bdk_wallet::tx_builder::ChangeSpendPolicy;
use bdk_wallet::ChangeSet;
Expand Down
6 changes: 6 additions & 0 deletions bdk-ffi/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use bdk_wallet::bitcoin::{Network, Txid};
use bdk_wallet::rusqlite::Connection as BdkConnection;
use bdk_wallet::{KeychainKind, PersistedWallet, SignOptions, Wallet as BdkWallet};

use bdk_wallet::descriptor::ExtendedDescriptor;
use std::borrow::BorrowMut;
use std::str::FromStr;
use std::sync::{Arc, Mutex, MutexGuard};
Expand Down Expand Up @@ -234,4 +235,9 @@ impl Wallet {
rusqlite_error: e.to_string(),
})
}

pub fn public_descriptor(&self, keychain: KeychainKind) -> Arc<ExtendedDescriptor> {
let extended_descriptor = self.get_wallet().public_descriptor(keychain).clone();
Arc::new(extended_descriptor)
}
}

0 comments on commit 1635dbf

Please sign in to comment.