diff --git a/bdk-ffi/src/bdk.udl b/bdk-ffi/src/bdk.udl index 78315e7b..946bca89 100644 --- a/bdk-ffi/src/bdk.udl +++ b/bdk-ffi/src/bdk.udl @@ -431,46 +431,6 @@ interface Wallet { boolean persist(Connection connection); }; -interface WalletNoPersist { - [Throws=DescriptorError] - constructor(Descriptor descriptor, Descriptor change_descriptor, Network network); - - AddressInfo reveal_next_address(KeychainKind keychain); - - Network network(); - - Balance balance(); - - [Throws=CannotConnectError] - void apply_update(Update update); - - boolean is_mine(Script script); - - [Throws=SignerError] - boolean sign(Psbt psbt); - - SentAndReceivedValues sent_and_received([ByRef] Transaction tx); - - sequence transactions(); - - [Throws=TxidParseError] - CanonicalTx? get_tx(string txid); - - [Throws=CalculateFeeError] - Amount calculate_fee([ByRef] Transaction tx); - - [Throws=CalculateFeeError] - FeeRate calculate_fee_rate([ByRef] Transaction tx); - - sequence list_unspent(); - - sequence list_output(); - - FullScanRequest start_full_scan(); - - SyncRequest start_sync_with_revealed_spks(); -}; - interface Update {}; interface TxBuilder { @@ -508,9 +468,6 @@ interface TxBuilder { [Throws=CreateTxError] Psbt finish([ByRef] Wallet wallet); - - [Throws=CreateTxError] - Psbt finish_no_persist([ByRef] WalletNoPersist wallet); }; interface BumpFeeTxBuilder { @@ -522,9 +479,6 @@ interface BumpFeeTxBuilder { [Throws=CreateTxError] Psbt finish([ByRef] Wallet wallet); - - [Throws=CreateTxError] - Psbt finish_no_persist([ByRef] WalletNoPersist wallet); }; // ------------------------------------------------------------------------ @@ -534,6 +488,9 @@ interface BumpFeeTxBuilder { interface Connection { [Throws=SqliteError] constructor(string path); + + [Name=new_in_memory, Throws=SqliteError] + constructor(); }; // ------------------------------------------------------------------------ diff --git a/bdk-ffi/src/lib.rs b/bdk-ffi/src/lib.rs index 546e045f..321b7662 100644 --- a/bdk-ffi/src/lib.rs +++ b/bdk-ffi/src/lib.rs @@ -66,7 +66,6 @@ use crate::wallet::SentAndReceivedValues; use crate::types::SyncRequest; use crate::types::SyncScriptInspector; use crate::wallet::Wallet; -use crate::wallet::WalletNoPersist; use crate::error::LoadWithPersistError; use bdk_wallet::bitcoin::Network; diff --git a/bdk-ffi/src/store.rs b/bdk-ffi/src/store.rs index 2ec25f6f..7ae2bb2b 100644 --- a/bdk-ffi/src/store.rs +++ b/bdk-ffi/src/store.rs @@ -13,6 +13,11 @@ impl Connection { Ok(Self(Mutex::new(connection))) } + pub fn new_in_memory() -> Result { + let connection = BdkConnection::open_in_memory()?; + Ok(Self(Mutex::new(connection))) + } + pub(crate) fn get_store(&self) -> MutexGuard { self.0.lock().expect("must lock") } diff --git a/bdk-ffi/src/wallet.rs b/bdk-ffi/src/wallet.rs index b34a817b..5568a7b0 100644 --- a/bdk-ffi/src/wallet.rs +++ b/bdk-ffi/src/wallet.rs @@ -2,7 +2,7 @@ use crate::bitcoin::{Amount, FeeRate, OutPoint, Psbt, Script, Transaction}; use crate::descriptor::Descriptor; use crate::error::{ CalculateFeeError, CannotConnectError, CreateTxError, SignerError, - TxidParseError, CreateWithPersistError, DescriptorError, LoadWithPersistError, + TxidParseError, CreateWithPersistError, LoadWithPersistError, }; use crate::store::Connection; use crate::types::{ @@ -31,10 +31,6 @@ pub struct Wallet { inner_mutex: Mutex>, } -pub struct WalletNoPersist { - inner_mutex: Mutex, -} - impl Wallet { pub fn new( descriptor: Arc, @@ -80,140 +76,109 @@ impl Wallet { self.inner_mutex.lock().expect("wallet") } - // pub fn persist(&self, connection: Connection) -> Result { - pub fn persist(&self, connection: Arc) -> bool { - let mut binding = connection.get_store(); - let db: &mut BdkConnection = binding.borrow_mut(); - self.get_wallet().persist(db).expect("persist failed") + pub fn reveal_next_address(&self, keychain_kind: KeychainKind) -> AddressInfo { + self.get_wallet().reveal_next_address(keychain_kind).into() } -} - -impl WalletNoPersist { - pub fn new( - descriptor: Arc, - change_descriptor: Arc, - network: Network, - ) -> Result { - let descriptor = descriptor.to_string_with_secret(); - let change_descriptor = change_descriptor.to_string_with_secret(); - - let wallet: BdkWallet = BdkWallet::create(descriptor, change_descriptor) - .network(network) - .create_wallet_no_persist()?; - Ok(WalletNoPersist { - inner_mutex: Mutex::new(wallet), - }) + pub fn apply_update(&self, update: Arc) -> Result<(), CannotConnectError> { + self.get_wallet() + .apply_update(update.0.clone()) + .map_err(CannotConnectError::from) } - pub(crate) fn get_wallet(&self) -> MutexGuard { - self.inner_mutex.lock().expect("wallet") + pub fn network(&self) -> Network { + self.get_wallet().network() } -} - -macro_rules! impl_wallet { - ($w:ident) => { - impl $w { - pub fn reveal_next_address(&self, keychain_kind: KeychainKind) -> AddressInfo { - self.get_wallet().reveal_next_address(keychain_kind).into() - } - pub fn apply_update(&self, update: Arc) -> Result<(), CannotConnectError> { - self.get_wallet() - .apply_update(update.0.clone()) - .map_err(CannotConnectError::from) - } + pub fn balance(&self) -> Balance { + let bdk_balance = self.get_wallet().balance(); + Balance::from(bdk_balance) + } - pub fn network(&self) -> Network { - self.get_wallet().network() - } + pub fn is_mine(&self, script: Arc