Skip to content

Commit

Permalink
feat: expose Wallet::policies method
Browse files Browse the repository at this point in the history
  • Loading branch information
BitcoinZavior committed Oct 19, 2024
1 parent b25d48f commit 61104c6
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
5 changes: 5 additions & 0 deletions bdk-ffi/src/bdk.udl
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,9 @@ interface Wallet {

string descriptor_checksum(KeychainKind keychain);

[Throws=DescriptorError]
Policy? policies(KeychainKind keychain);

Balance balance();

[Throws=CannotConnectError]
Expand Down Expand Up @@ -441,6 +444,8 @@ interface Wallet {

interface Update {};

interface Policy {};

interface TxBuilder {
constructor();

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 @@ -57,6 +57,7 @@ use crate::types::FullScanRequestBuilder;
use crate::types::FullScanScriptInspector;
use crate::types::KeychainAndIndex;
use crate::types::LocalOutput;
use crate::types::Policy;
use crate::types::ScriptAmount;
use crate::types::SentAndReceivedValues;
use crate::types::SyncRequest;
Expand Down
16 changes: 15 additions & 1 deletion bdk-ffi/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ use bdk_wallet::chain::tx_graph::CanonicalTx as BdkCanonicalTx;
use bdk_wallet::chain::{
ChainPosition as BdkChainPosition, ConfirmationBlockTime as BdkConfirmationBlockTime,
};
use bdk_wallet::descriptor::Policy as BdkPolicy;
use bdk_wallet::AddressInfo as BdkAddressInfo;
use bdk_wallet::Balance as BdkBalance;
use bdk_wallet::KeychainKind;
use bdk_wallet::LocalOutput as BdkLocalOutput;
use bdk_wallet::Update as BdkUpdate;

use std::sync::{Arc, Mutex};

#[derive(Debug)]
Expand Down Expand Up @@ -237,3 +237,17 @@ pub struct KeychainAndIndex {
pub keychain: KeychainKind,
pub index: u32,
}

/// Descriptor spending policy
#[derive(Debug, PartialEq, Eq, Clone)]
pub struct Policy(BdkPolicy);
impl From<BdkPolicy> for Policy {
fn from(value: BdkPolicy) -> Self {
Policy(value)
}
}
impl From<Policy> for BdkPolicy {
fn from(value: Policy) -> Self {
value.0
}
}
16 changes: 11 additions & 5 deletions bdk-ffi/src/wallet.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use crate::bitcoin::{Psbt, Transaction};
use crate::descriptor::Descriptor;
use crate::error::{
CalculateFeeError, CannotConnectError, CreateWithPersistError, LoadWithPersistError,
SignerError, SqliteError, TxidParseError,
CalculateFeeError, CannotConnectError, CreateWithPersistError, DescriptorError,
LoadWithPersistError, SignerError, SqliteError, TxidParseError,
};
use crate::store::Connection;
use crate::types::{
AddressInfo, Balance, CanonicalTx, FullScanRequestBuilder, KeychainAndIndex, LocalOutput,
SentAndReceivedValues, SyncRequestBuilder, Update,
Policy, SentAndReceivedValues, SyncRequestBuilder, Update,
};

use bitcoin_ffi::{Amount, FeeRate, OutPoint, Script};
Expand Down Expand Up @@ -139,6 +139,13 @@ impl Wallet {
self.get_wallet().descriptor_checksum(keychain)
}

pub fn policies(&self, keychain: KeychainKind) -> Result<Option<Arc<Policy>>, DescriptorError> {
self.get_wallet()
.policies(keychain)
.map_err(DescriptorError::from)
.map(|e| e.map(|p| Arc::new(p.into())))
}

pub fn network(&self) -> Network {
self.get_wallet().network()
}
Expand All @@ -154,8 +161,7 @@ impl Wallet {

pub(crate) fn sign(
&self,
psbt: Arc<Psbt>,
// sign_options: Option<SignOptions>,
psbt: Arc<Psbt>, // sign_options: Option<SignOptions>,
) -> Result<bool, SignerError> {
let mut psbt = psbt.0.lock().unwrap();
self.get_wallet()
Expand Down

0 comments on commit 61104c6

Please sign in to comment.