From 61104c6519542ebc26db7b07476308e5393ca7be Mon Sep 17 00:00:00 2001 From: BitcoinZavior Date: Sat, 19 Oct 2024 16:51:33 -0400 Subject: [PATCH] feat: expose Wallet::policies method --- bdk-ffi/src/bdk.udl | 5 +++++ bdk-ffi/src/lib.rs | 1 + bdk-ffi/src/types.rs | 16 +++++++++++++++- bdk-ffi/src/wallet.rs | 16 +++++++++++----- 4 files changed, 32 insertions(+), 6 deletions(-) diff --git a/bdk-ffi/src/bdk.udl b/bdk-ffi/src/bdk.udl index 1c716777..2eb41a3f 100644 --- a/bdk-ffi/src/bdk.udl +++ b/bdk-ffi/src/bdk.udl @@ -401,6 +401,9 @@ interface Wallet { string descriptor_checksum(KeychainKind keychain); + [Throws=DescriptorError] + Policy? policies(KeychainKind keychain); + Balance balance(); [Throws=CannotConnectError] @@ -441,6 +444,8 @@ interface Wallet { interface Update {}; +interface Policy {}; + interface TxBuilder { constructor(); diff --git a/bdk-ffi/src/lib.rs b/bdk-ffi/src/lib.rs index b8db0d78..8ed81e3c 100644 --- a/bdk-ffi/src/lib.rs +++ b/bdk-ffi/src/lib.rs @@ -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; diff --git a/bdk-ffi/src/types.rs b/bdk-ffi/src/types.rs index eaf3a2ac..392d4539 100644 --- a/bdk-ffi/src/types.rs +++ b/bdk-ffi/src/types.rs @@ -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)] @@ -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 for Policy { + fn from(value: BdkPolicy) -> Self { + Policy(value) + } +} +impl From for BdkPolicy { + fn from(value: Policy) -> Self { + value.0 + } +} diff --git a/bdk-ffi/src/wallet.rs b/bdk-ffi/src/wallet.rs index fd8d4b75..f89ac4fe 100644 --- a/bdk-ffi/src/wallet.rs +++ b/bdk-ffi/src/wallet.rs @@ -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}; @@ -139,6 +139,13 @@ impl Wallet { self.get_wallet().descriptor_checksum(keychain) } + pub fn policies(&self, keychain: KeychainKind) -> Result>, 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() } @@ -154,8 +161,7 @@ impl Wallet { pub(crate) fn sign( &self, - psbt: Arc, - // sign_options: Option, + psbt: Arc, // sign_options: Option, ) -> Result { let mut psbt = psbt.0.lock().unwrap(); self.get_wallet()