Skip to content

Commit 7d76444

Browse files
committed
feat: update to recent bdk_redb commit
1 parent 8a02dce commit 7d76444

File tree

4 files changed

+60
-60
lines changed

4 files changed

+60
-60
lines changed

Cargo.lock

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/error.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ pub enum BDKCliError {
9797
#[cfg(feature = "cbf")]
9898
#[error("BDK-Kyoto update error: {0}")]
9999
KyotoUpdateError(#[from] bdk_kyoto::UpdateError),
100+
101+
#[error("Could not Join threads: {0}")]
102+
JoinError(#[from] tokio::task::JoinError),
100103
}
101104

102105
impl From<ExtractTxError> for BDKCliError {

src/handlers.rs

Lines changed: 46 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,7 @@ use crate::persister::{Persister, PersisterError};
1818
#[cfg(feature = "cbf")]
1919
use crate::utils::BlockchainClient::KyotoClient;
2020
use crate::utils::*;
21-
#[cfg(all(
22-
feature = "redb",
23-
any(
24-
feature = "electrum",
25-
feature = "esplora",
26-
feature = "cbf",
27-
feature = "rpc"
28-
)
29-
))]
21+
#[cfg(all(feature = "redb",))]
3022
use bdk_redb::Store as RedbStore;
3123
use bdk_wallet::bip39::{Language, Mnemonic};
3224
use bdk_wallet::bitcoin::bip32::{DerivationPath, KeySource};
@@ -63,6 +55,8 @@ use crate::utils::BlockchainClient::Electrum;
6355
#[cfg(feature = "cbf")]
6456
use bdk_kyoto::{Info, LightClient};
6557
use bdk_wallet::bitcoin::base64::prelude::*;
58+
#[cfg(feature = "redb")]
59+
use std::sync::Arc;
6660
#[cfg(feature = "cbf")]
6761
use tokio::select;
6862
#[cfg(any(
@@ -763,32 +757,34 @@ pub(crate) async fn handle_command(cli_opts: CliOpts) -> Result<String, Error> {
763757
let home_dir = prepare_home_dir(cli_opts.datadir)?;
764758
let wallet_name = &wallet_opts.wallet;
765759
let database_path = prepare_wallet_db_dir(wallet_name, &home_dir)?;
760+
#[cfg(feature = "redb")]
761+
let db = bdk_redb::redb::Database::create(database_path.join("wallet.redb"))
762+
.map_err(bdk_redb::redb::Error::from)
763+
.map_err(bdk_redb::error::StoreError::from)
764+
.map_err(PersisterError::from)?;
766765
#[cfg(any(feature = "sqlite", feature = "redb"))]
767766
let result = {
768-
#[cfg(feature = "redb")]
769-
let db = bdk_redb::redb::Database::create(database_path.join("wallet.redb"))
770-
.map_err(bdk_redb::redb::Error::from)
771-
.map_err(bdk_redb::error::StoreError::from)
772-
.map_err(PersisterError::from)?;
773767
let mut persister: Persister = match &wallet_opts.database_type {
774768
#[cfg(feature = "sqlite")]
775769
DatabaseType::Sqlite => {
776-
use std::marker::PhantomData;
777-
778770
let db_file = database_path.join("wallet.sqlite");
779771
let connection = Connection::open(db_file).map_err(PersisterError::from)?;
780772
log::debug!("Sqlite database opened successfully");
781-
Persister::Connection(connection, PhantomData)
773+
Persister::Connection(connection)
782774
}
783775
#[cfg(feature = "redb")]
784776
DatabaseType::Redb => {
785-
let store = RedbStore::new(
786-
&db,
787-
wallet_name.clone().unwrap_or("wallet1".to_string()),
788-
)
789-
.map_err(PersisterError::from)?;
790-
log::debug!("Redb database opened successfully");
791-
Persister::RedbStore(store)
777+
let wallet_name = wallet_opts.clone().wallet;
778+
tokio::task::spawn_blocking(move || {
779+
let store = RedbStore::new(
780+
Arc::new(db),
781+
wallet_name.clone().unwrap_or("wallet1".to_string()),
782+
)
783+
.map_err(PersisterError::from)?;
784+
log::debug!("Redb database opened successfully");
785+
Ok::<Persister, PersisterError>(Persister::RedbStore(store))
786+
})
787+
.await??
792788
}
793789
};
794790

@@ -824,8 +820,7 @@ pub(crate) async fn handle_command(cli_opts: CliOpts) -> Result<String, Error> {
824820
#[cfg(any(feature = "sqlite", feature = "redb"))]
825821
let result = {
826822
let home_dir = prepare_home_dir(cli_opts.datadir)?;
827-
let wallet_name = &wallet_opts.wallet;
828-
let database_path = prepare_wallet_db_dir(wallet_name, &home_dir)?;
823+
let database_path = prepare_wallet_db_dir(&wallet_opts.wallet, &home_dir)?;
829824
#[cfg(feature = "redb")]
830825
let db = bdk_redb::redb::Database::create(database_path.join("wallet.redb"))
831826
.map_err(bdk_redb::redb::Error::from)
@@ -834,22 +829,24 @@ pub(crate) async fn handle_command(cli_opts: CliOpts) -> Result<String, Error> {
834829
let mut persister: Persister = match &wallet_opts.database_type {
835830
#[cfg(feature = "sqlite")]
836831
DatabaseType::Sqlite => {
837-
use std::marker::PhantomData;
838-
839832
let db_file = database_path.join("wallet.sqlite");
840833
let connection = Connection::open(db_file).map_err(PersisterError::from)?;
841834
log::debug!("Sqlite database opened successfully");
842-
Persister::Connection(connection, PhantomData)
835+
Persister::Connection(connection)
843836
}
844837
#[cfg(feature = "redb")]
845838
DatabaseType::Redb => {
846-
let store = bdk_redb::Store::new(
847-
&db,
848-
wallet_name.clone().unwrap_or("wallet1".to_string()),
849-
)
850-
.map_err(PersisterError::from)?;
851-
log::debug!("Redb database opened successfully");
852-
Persister::RedbStore(store)
839+
let wallet_name = wallet_opts.clone().wallet;
840+
tokio::task::spawn_blocking(move || {
841+
let store = RedbStore::new(
842+
Arc::new(db),
843+
wallet_name.clone().unwrap_or("wallet1".to_string()),
844+
)
845+
.map_err(PersisterError::from)?;
846+
log::debug!("Redb database opened successfully");
847+
Ok::<Persister, PersisterError>(Persister::RedbStore(store))
848+
})
849+
.await??
853850
}
854851
};
855852

@@ -899,29 +896,31 @@ pub(crate) async fn handle_command(cli_opts: CliOpts) -> Result<String, Error> {
899896
.map_err(PersisterError::from)?;
900897
#[cfg(any(feature = "sqlite", feature = "redb"))]
901898
let (mut wallet, mut persister) = {
902-
let wallet_name = &wallet_opts.wallet;
903899
let mut persister: Persister = match &wallet_opts.database_type {
904900
#[cfg(feature = "sqlite")]
905901
DatabaseType::Sqlite => {
906-
use std::marker::PhantomData;
907-
902+
let wallet_name = &wallet_opts.wallet;
908903
let home_dir = prepare_home_dir(cli_opts.datadir.clone())?;
909904

910905
let database_path = prepare_wallet_db_dir(wallet_name, &home_dir)?;
911906
let db_file = database_path.join("wallet.sqlite");
912907
let connection = Connection::open(db_file).map_err(PersisterError::from)?;
913908
log::debug!("Sqlite database opened successfully");
914-
Persister::Connection(connection, PhantomData)
909+
Persister::Connection(connection)
915910
}
916911
#[cfg(feature = "redb")]
917912
DatabaseType::Redb => {
918-
let store = bdk_redb::Store::new(
919-
&db,
920-
wallet_name.clone().unwrap_or("wallet1".to_string()),
921-
)
922-
.map_err(PersisterError::from)?;
923-
log::debug!("Redb database opened successfully");
924-
Persister::RedbStore(store)
913+
let wallet_name = wallet_opts.clone().wallet;
914+
tokio::task::spawn_blocking(move || {
915+
let store = RedbStore::new(
916+
Arc::new(db),
917+
wallet_name.clone().unwrap_or("wallet1".to_string()),
918+
)
919+
.map_err(PersisterError::from)?;
920+
log::debug!("Redb database opened successfully");
921+
Ok::<Persister, PersisterError>(Persister::RedbStore(store))
922+
})
923+
.await??
925924
}
926925
};
927926
let wallet = new_persisted_wallet(network, &mut persister, &wallet_opts)?;

src/persister.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
use bdk_wallet::WalletPersister;
2-
#[cfg(feature = "sqlite")]
3-
use std::marker::PhantomData;
42

5-
pub enum Persister<'a> {
3+
pub enum Persister {
64
#[cfg(feature = "sqlite")]
7-
Connection(bdk_wallet::rusqlite::Connection, PhantomData<&'a ()>),
5+
Connection(bdk_wallet::rusqlite::Connection),
86
#[cfg(feature = "redb")]
9-
RedbStore(bdk_redb::Store<'a>),
7+
RedbStore(bdk_redb::Store),
108
}
119

1210
#[derive(Debug, thiserror::Error)]
@@ -19,13 +17,13 @@ pub enum PersisterError {
1917
RedbError(#[from] bdk_redb::error::StoreError),
2018
}
2119

22-
impl WalletPersister for Persister<'_> {
20+
impl WalletPersister for Persister {
2321
type Error = PersisterError;
2422

2523
fn initialize(persister: &mut Self) -> Result<bdk_wallet::ChangeSet, Self::Error> {
2624
match persister {
2725
#[cfg(feature = "sqlite")]
28-
Persister::Connection(connection, PhantomData) => {
26+
Persister::Connection(connection) => {
2927
WalletPersister::initialize(connection).map_err(PersisterError::from)
3028
}
3129
#[cfg(feature = "redb")]
@@ -38,7 +36,7 @@ impl WalletPersister for Persister<'_> {
3836
fn persist(persister: &mut Self, changeset: &bdk_wallet::ChangeSet) -> Result<(), Self::Error> {
3937
match persister {
4038
#[cfg(feature = "sqlite")]
41-
Persister::Connection(connection, PhantomData) => {
39+
Persister::Connection(connection) => {
4240
WalletPersister::persist(connection, changeset).map_err(PersisterError::from)
4341
}
4442
#[cfg(feature = "redb")]

0 commit comments

Comments
 (0)