forked from bitcoindevkit/bdk-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpersister.rs
More file actions
40 lines (36 loc) · 1.34 KB
/
persister.rs
File metadata and controls
40 lines (36 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
use crate::error::BDKCliError;
use bdk_wallet::WalletPersister;
// Types of Persistence backends supported by bdk-cli
pub(crate) enum Persister {
#[cfg(feature = "sqlite")]
Connection(bdk_wallet::rusqlite::Connection),
#[cfg(feature = "redb")]
RedbStore(bdk_redb::Store),
}
impl WalletPersister for Persister {
type Error = BDKCliError;
fn initialize(persister: &mut Self) -> Result<bdk_wallet::ChangeSet, Self::Error> {
match persister {
#[cfg(feature = "sqlite")]
Persister::Connection(connection) => {
WalletPersister::initialize(connection).map_err(BDKCliError::from)
}
#[cfg(feature = "redb")]
Persister::RedbStore(store) => {
WalletPersister::initialize(store).map_err(BDKCliError::from)
}
}
}
fn persist(persister: &mut Self, changeset: &bdk_wallet::ChangeSet) -> Result<(), Self::Error> {
match persister {
#[cfg(feature = "sqlite")]
Persister::Connection(connection) => {
WalletPersister::persist(connection, changeset).map_err(BDKCliError::from)
}
#[cfg(feature = "redb")]
Persister::RedbStore(store) => {
WalletPersister::persist(store, changeset).map_err(BDKCliError::from)
}
}
}
}