feat: add memory wallet

This commit is contained in:
thunderbiscuit 2024-05-08 16:49:04 -04:00
parent f169b1a52f
commit 79e7ab73ea
No known key found for this signature in database
GPG Key ID: 88253696EB836462
2 changed files with 21 additions and 2 deletions

View File

@ -271,6 +271,9 @@ interface Wallet {
[Throws=WalletCreationError]
constructor(Descriptor descriptor, Descriptor? change_descriptor, string persistence_backend_path, Network network);
[Name=new_no_persist, Throws=DescriptorError]
constructor(Descriptor descriptor, Descriptor? change_descriptor, Network network);
[Throws=PersistenceError]
AddressInfo reveal_next_address(KeychainKind keychain);

View File

@ -2,8 +2,8 @@ use crate::bitcoin::Amount;
use crate::bitcoin::{FeeRate, OutPoint, Psbt, Script, Transaction};
use crate::descriptor::Descriptor;
use crate::error::{
CalculateFeeError, CannotConnectError, CreateTxError, PersistenceError, SignerError,
TxidParseError, WalletCreationError,
CalculateFeeError, CannotConnectError, CreateTxError, DescriptorError, PersistenceError,
SignerError, TxidParseError, WalletCreationError,
};
use crate::types::{
AddressInfo, Balance, CanonicalTx, FullScanRequest, LocalOutput, ScriptAmount, SyncRequest,
@ -49,6 +49,22 @@ impl Wallet {
})
}
pub fn new_no_persist(
descriptor: Arc<Descriptor>,
change_descriptor: Option<Arc<Descriptor>>,
network: Network,
) -> Result<Self, DescriptorError> {
let descriptor = descriptor.as_string_private();
let change_descriptor = change_descriptor.map(|d| d.as_string_private());
let wallet: BdkWallet =
BdkWallet::new_no_persist(&descriptor, change_descriptor.as_ref(), network)?;
Ok(Wallet {
inner_mutex: Mutex::new(wallet),
})
}
pub(crate) fn get_wallet(&self) -> MutexGuard<BdkWallet> {
self.inner_mutex.lock().expect("wallet")
}