Skip to content

Commit 8a02dce

Browse files
committed
feat: update cli to latest bdk_redb commit
1 parent bd6ca85 commit 8a02dce

File tree

4 files changed

+51
-51
lines changed

4 files changed

+51
-51
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ bdk_bitcoind_rpc = { version = "0.20.0", optional = true }
2727
bdk_electrum = { version = "0.23.0", optional = true }
2828
bdk_esplora = { version = "0.22.0", features = ["async-https", "tokio"], optional = true }
2929
bdk_kyoto = { version = "0.11.0", optional = true }
30-
bdk_redb = { git = "https://github.com/110CodingP/bdk_redb", optional = true }
30+
bdk_redb = { git = "https://github.com/110CodingP/bdk_redb", features = ["wallet"], optional = true }
3131
shlex = { version = "1.3.0", optional = true }
3232
tracing = "0.1.41"
3333
tracing-subscriber = "0.3.19"

src/handlers.rs

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -765,19 +765,25 @@ pub(crate) async fn handle_command(cli_opts: CliOpts) -> Result<String, Error> {
765765
let database_path = prepare_wallet_db_dir(wallet_name, &home_dir)?;
766766
#[cfg(any(feature = "sqlite", feature = "redb"))]
767767
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)?;
768773
let mut persister: Persister = match &wallet_opts.database_type {
769774
#[cfg(feature = "sqlite")]
770775
DatabaseType::Sqlite => {
776+
use std::marker::PhantomData;
777+
771778
let db_file = database_path.join("wallet.sqlite");
772779
let connection = Connection::open(db_file).map_err(PersisterError::from)?;
773780
log::debug!("Sqlite database opened successfully");
774-
Persister::Connection(connection)
781+
Persister::Connection(connection, PhantomData)
775782
}
776783
#[cfg(feature = "redb")]
777784
DatabaseType::Redb => {
778-
let db_file = database_path.join("wallet.redb");
779785
let store = RedbStore::new(
780-
db_file,
786+
&db,
781787
wallet_name.clone().unwrap_or("wallet1".to_string()),
782788
)
783789
.map_err(PersisterError::from)?;
@@ -820,19 +826,25 @@ pub(crate) async fn handle_command(cli_opts: CliOpts) -> Result<String, Error> {
820826
let home_dir = prepare_home_dir(cli_opts.datadir)?;
821827
let wallet_name = &wallet_opts.wallet;
822828
let database_path = prepare_wallet_db_dir(wallet_name, &home_dir)?;
829+
#[cfg(feature = "redb")]
830+
let db = bdk_redb::redb::Database::create(database_path.join("wallet.redb"))
831+
.map_err(bdk_redb::redb::Error::from)
832+
.map_err(bdk_redb::error::StoreError::from)
833+
.map_err(PersisterError::from)?;
823834
let mut persister: Persister = match &wallet_opts.database_type {
824835
#[cfg(feature = "sqlite")]
825836
DatabaseType::Sqlite => {
837+
use std::marker::PhantomData;
838+
826839
let db_file = database_path.join("wallet.sqlite");
827840
let connection = Connection::open(db_file).map_err(PersisterError::from)?;
828841
log::debug!("Sqlite database opened successfully");
829-
Persister::Connection(connection)
842+
Persister::Connection(connection, PhantomData)
830843
}
831844
#[cfg(feature = "redb")]
832845
DatabaseType::Redb => {
833-
let db_file = database_path.join("wallet.redb");
834846
let store = bdk_redb::Store::new(
835-
db_file,
847+
&db,
836848
wallet_name.clone().unwrap_or("wallet1".to_string()),
837849
)
838850
.map_err(PersisterError::from)?;
@@ -874,27 +886,37 @@ pub(crate) async fn handle_command(cli_opts: CliOpts) -> Result<String, Error> {
874886
#[cfg(feature = "repl")]
875887
CliSubCommand::Repl { wallet_opts } => {
876888
let network = cli_opts.network;
889+
#[cfg(feature = "redb")]
890+
let db = bdk_redb::redb::Database::create(
891+
prepare_wallet_db_dir(
892+
&wallet_opts.wallet,
893+
&prepare_home_dir(cli_opts.datadir.clone())?,
894+
)?
895+
.join("wallet.redb"),
896+
)
897+
.map_err(bdk_redb::redb::Error::from)
898+
.map_err(bdk_redb::error::StoreError::from)
899+
.map_err(PersisterError::from)?;
877900
#[cfg(any(feature = "sqlite", feature = "redb"))]
878901
let (mut wallet, mut persister) = {
879902
let wallet_name = &wallet_opts.wallet;
880-
881-
let home_dir = prepare_home_dir(cli_opts.datadir.clone())?;
882-
883-
let database_path = prepare_wallet_db_dir(wallet_name, &home_dir)?;
884-
885903
let mut persister: Persister = match &wallet_opts.database_type {
886904
#[cfg(feature = "sqlite")]
887905
DatabaseType::Sqlite => {
906+
use std::marker::PhantomData;
907+
908+
let home_dir = prepare_home_dir(cli_opts.datadir.clone())?;
909+
910+
let database_path = prepare_wallet_db_dir(wallet_name, &home_dir)?;
888911
let db_file = database_path.join("wallet.sqlite");
889912
let connection = Connection::open(db_file).map_err(PersisterError::from)?;
890913
log::debug!("Sqlite database opened successfully");
891-
Persister::Connection(connection)
914+
Persister::Connection(connection, PhantomData)
892915
}
893916
#[cfg(feature = "redb")]
894917
DatabaseType::Redb => {
895-
let db_file = database_path.join("wallet.redb");
896918
let store = bdk_redb::Store::new(
897-
db_file,
919+
&db,
898920
wallet_name.clone().unwrap_or("wallet1".to_string()),
899921
)
900922
.map_err(PersisterError::from)?;

src/persister.rs

Lines changed: 12 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,31 @@
1-
use std::fmt::Display;
2-
31
use bdk_wallet::WalletPersister;
2+
#[cfg(feature = "sqlite")]
3+
use std::marker::PhantomData;
44

5-
pub enum Persister {
5+
pub enum Persister<'a> {
66
#[cfg(feature = "sqlite")]
7-
Connection(bdk_wallet::rusqlite::Connection),
7+
Connection(bdk_wallet::rusqlite::Connection, PhantomData<&'a ()>),
88
#[cfg(feature = "redb")]
9-
RedbStore(bdk_redb::Store),
9+
RedbStore(bdk_redb::Store<'a>),
1010
}
1111

1212
#[derive(Debug, thiserror::Error)]
1313
pub enum PersisterError {
1414
#[cfg(feature = "sqlite")]
15-
SqliteError(bdk_wallet::rusqlite::Error),
15+
#[error("Sqlite error: {0}")]
16+
SqliteError(#[from] bdk_wallet::rusqlite::Error),
1617
#[cfg(feature = "redb")]
17-
RedbError(bdk_redb::error::BdkRedbError),
18-
}
19-
20-
#[cfg(feature = "sqlite")]
21-
impl From<bdk_wallet::rusqlite::Error> for PersisterError {
22-
fn from(value: bdk_wallet::rusqlite::Error) -> Self {
23-
PersisterError::SqliteError(value)
24-
}
25-
}
26-
27-
#[cfg(feature = "redb")]
28-
impl From<bdk_redb::error::BdkRedbError> for PersisterError {
29-
fn from(value: bdk_redb::error::BdkRedbError) -> Self {
30-
PersisterError::RedbError(value)
31-
}
32-
}
33-
34-
impl Display for PersisterError {
35-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
36-
match self {
37-
#[cfg(feature = "sqlite")]
38-
PersisterError::SqliteError(err) => err.fmt(f),
39-
#[cfg(feature = "redb")]
40-
PersisterError::RedbError(err) => err.fmt(f),
41-
}
42-
}
18+
#[error("Redb error: {0}")]
19+
RedbError(#[from] bdk_redb::error::StoreError),
4320
}
4421

45-
impl WalletPersister for Persister {
22+
impl WalletPersister for Persister<'_> {
4623
type Error = PersisterError;
4724

4825
fn initialize(persister: &mut Self) -> Result<bdk_wallet::ChangeSet, Self::Error> {
4926
match persister {
5027
#[cfg(feature = "sqlite")]
51-
Persister::Connection(connection) => {
28+
Persister::Connection(connection, PhantomData) => {
5229
WalletPersister::initialize(connection).map_err(PersisterError::from)
5330
}
5431
#[cfg(feature = "redb")]
@@ -61,7 +38,7 @@ impl WalletPersister for Persister {
6138
fn persist(persister: &mut Self, changeset: &bdk_wallet::ChangeSet) -> Result<(), Self::Error> {
6239
match persister {
6340
#[cfg(feature = "sqlite")]
64-
Persister::Connection(connection) => {
41+
Persister::Connection(connection, PhantomData) => {
6542
WalletPersister::persist(connection, changeset).map_err(PersisterError::from)
6643
}
6744
#[cfg(feature = "redb")]

0 commit comments

Comments
 (0)