Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 7 additions & 16 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ members = [".", "migration"]
base64 = { version = "0.22.1", default-features = false, features = [
"std",
] }
bdk_sqlite = { version = "0.6.0", default-features = false, features = [
"wallet",
] }
bdk_wallet = { version = "=3.0.0", default-features = false, features = [
"file_store",
"keys-bip39",
"std",
] }
Expand Down
42 changes: 12 additions & 30 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -856,32 +856,24 @@ impl From<rgbinvoice::TransportParseError> for Error {
}
}

impl From<bdk_wallet::file_store::StoreErrorWithDump<ChangeSet>> for Error {
fn from(e: bdk_wallet::file_store::StoreErrorWithDump<ChangeSet>) -> Self {
impl From<bdk_sqlite::Error> for Error {
fn from(e: bdk_sqlite::Error) -> Self {
Error::IO {
details: e.to_string(),
}
}
}

impl From<bdk_wallet::FileStoreError> for Error {
fn from(e: bdk_wallet::FileStoreError) -> Self {
impl From<bdk_wallet::CreateWithPersistError<bdk_sqlite::Error>> for Error {
fn from(e: bdk_wallet::CreateWithPersistError<bdk_sqlite::Error>) -> Self {
Error::IO {
details: e.to_string(),
}
}
}

impl From<bdk_wallet::CreateWithPersistError<bdk_wallet::FileStoreError>> for Error {
fn from(e: bdk_wallet::CreateWithPersistError<bdk_wallet::FileStoreError>) -> Self {
Error::IO {
details: e.to_string(),
}
}
}

impl From<bdk_wallet::LoadWithPersistError<bdk_wallet::FileStoreError>> for Error {
fn from(e: bdk_wallet::LoadWithPersistError<bdk_wallet::FileStoreError>) -> Self {
impl From<bdk_wallet::LoadWithPersistError<bdk_sqlite::Error>> for Error {
fn from(e: bdk_wallet::LoadWithPersistError<bdk_sqlite::Error>) -> Self {
match e {
bdk_wallet::LoadWithPersistError::InvalidChangeSet(
bdk_wallet::LoadError::Mismatch(bdk_wallet::LoadMismatch::Genesis { .. }),
Expand Down Expand Up @@ -959,31 +951,21 @@ mod tests {
assert_matches!(err, Error::Internal { details } if !details.is_empty());

// LoadWithPersistError error
let err = bdk_wallet::LoadWithPersistError::Persist(bdk_wallet::FileStoreError::Write(
std::io::Error::new(std::io::ErrorKind::PermissionDenied, "no access"),
let err = bdk_wallet::LoadWithPersistError::Persist(bdk_sqlite::Error::FromInt(
u8::try_from(300u32).unwrap_err(),
));
let err = Error::from(err);
assert_matches!(err, Error::IO { details } if !details.is_empty());

// CreateWithPersistError error
let err = bdk_wallet::CreateWithPersistError::Persist(bdk_wallet::FileStoreError::Write(
std::io::Error::new(std::io::ErrorKind::PermissionDenied, "no access"),
let err = bdk_wallet::CreateWithPersistError::Persist(bdk_sqlite::Error::FromInt(
u8::try_from(300u32).unwrap_err(),
));
let err = Error::from(err);
assert_matches!(err, Error::IO { details } if !details.is_empty());

// FileStoreError error
let err = bdk_wallet::FileStoreError::Write(std::io::Error::new(
std::io::ErrorKind::PermissionDenied,
"no access",
));
let err = Error::from(err);
assert_matches!(err, Error::IO { details } if !details.is_empty());

// StoreErrorWithDump error
let err = bdk_wallet::file_store::StoreErrorWithDump::<ChangeSet>::from(
std::io::Error::new(std::io::ErrorKind::PermissionDenied, "no access"),
);
// bdk_sqlite::Error error
let err = bdk_sqlite::Error::FromInt(u8::try_from(300u32).unwrap_err());
let err = Error::from(err);
assert_matches!(err, Error::IO { details } if !details.is_empty());

Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,11 @@ use bdk_esplora::{
BlockingClient as EsploraClient, Builder as EsploraBuilder, Error as EsploraError,
},
};
use bdk_sqlite::Store as BdkStore;
#[cfg(feature = "esplora")]
use bdk_wallet::bitcoin::Txid;
use bdk_wallet::{
ChangeSet, KeychainKind, LocalOutput, PersistedWallet, SignOptions, Wallet as BdkWallet,
KeychainKind, LocalOutput, PersistedWallet, SignOptions, Wallet as BdkWallet,
bitcoin::{
Address as BdkAddress, Amount as BdkAmount, BlockHash, Network as BdkNetwork, NetworkKind,
OutPoint, OutPoint as BdkOutPoint, ScriptBuf, TxOut,
Expand All @@ -140,7 +141,6 @@ use bdk_wallet::{
},
chain::{CanonicalizationParams, ChainPosition},
descriptor::Segwitv0,
file_store::Store,
keys::{
DerivableKey, DescriptorKey,
DescriptorKey::{Public, Secret},
Expand Down
36 changes: 17 additions & 19 deletions src/wallet/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use super::*;

const BDK_DB_NAME: &str = "bdk_db";
const BDK_DB_NAME: &str = "bdk_db_sqlite";

pub(crate) const NUM_KNOWN_SCHEMAS: usize = 4;

Expand Down Expand Up @@ -67,8 +67,8 @@ pub struct WalletInternals {
pub(crate) _logger_guard: AsyncGuard,
pub(crate) database: Arc<RgbLibDatabase>,
pub(crate) wallet_dir: PathBuf,
pub(crate) bdk_wallet: PersistedWallet<Store<ChangeSet>>,
pub(crate) bdk_database: Store<ChangeSet>,
pub(crate) bdk_wallet: PersistedWallet<BdkStore>,
pub(crate) bdk_database: BdkStore,
#[cfg(any(feature = "electrum", feature = "esplora"))]
pub(crate) online_data: Option<OnlineData>,
}
Expand Down Expand Up @@ -120,7 +120,7 @@ pub(crate) fn setup_bdk<P: AsRef<Path>>(
desc_vanilla: String,
watch_only: bool,
bdk_network: BdkNetwork,
) -> Result<(PersistedWallet<Store<ChangeSet>>, Store<ChangeSet>), Error> {
) -> Result<(PersistedWallet<BdkStore>, BdkStore), Error> {
let chain_net: ChainNet = wallet_data.bitcoin_network.into();
let mut wallet_params = BdkWallet::load()
.descriptor(KeychainKind::External, Some(desc_colored.clone()))
Expand All @@ -135,13 +135,16 @@ pub(crate) fn setup_bdk<P: AsRef<Path>>(
BDK_DB_NAME.to_string()
};
let bdk_db_path = wallet_dir.as_ref().join(bdk_db_name);
let (mut bdk_database, _) =
Store::<ChangeSet>::load_or_create(BDK_DB_NAME.as_bytes(), bdk_db_path)?;
let bdk_wallet = match wallet_params.load_wallet(&mut bdk_database)? {
let bdk_db_url = format!("sqlite:{}", adjust_canonicalization(bdk_db_path));
let mut bdk_database = block_on(BdkStore::new(&bdk_db_url))?;
// schema migrations are applied automatically when the wallet is loaded
let bdk_wallet = match block_on(wallet_params.load_wallet_async(&mut bdk_database))? {
Some(wallet) => wallet,
None => BdkWallet::create(desc_colored, desc_vanilla)
.network(bdk_network)
.create_wallet(&mut bdk_database)?,
None => block_on(
BdkWallet::create(desc_colored, desc_vanilla)
.network(bdk_network)
.create_wallet_async(&mut bdk_database),
)?,
};
Ok((bdk_wallet, bdk_database))
}
Expand Down Expand Up @@ -180,20 +183,15 @@ pub trait WalletCore {

fn internals_mut(&mut self) -> &mut WalletInternals;

fn bdk_wallet(&self) -> &PersistedWallet<Store<ChangeSet>> {
fn bdk_wallet(&self) -> &PersistedWallet<BdkStore> {
&self.internals().bdk_wallet
}

fn bdk_wallet_mut(&mut self) -> &mut PersistedWallet<Store<ChangeSet>> {
fn bdk_wallet_mut(&mut self) -> &mut PersistedWallet<BdkStore> {
&mut self.internals_mut().bdk_wallet
}

fn bdk_wallet_db_mut(
&mut self,
) -> (
&mut PersistedWallet<Store<ChangeSet>>,
&mut Store<ChangeSet>,
) {
fn bdk_wallet_db_mut(&mut self) -> (&mut PersistedWallet<BdkStore>, &mut BdkStore) {
let internals_mut = self.internals_mut();
(
&mut internals_mut.bdk_wallet,
Expand Down Expand Up @@ -354,7 +352,7 @@ pub trait WalletCore {
.map_err(|e| Error::FailedBdkSync {
details: e.to_string(),
})?;
bdk_wallet.persist(bdk_db)?;
block_on(bdk_wallet.persist_async(bdk_db))?;

if matches!(options.keychain, SyncKeychain::Colored) {
self.update_db_colored_txos_from_bdk(txn, include_spent)?;
Expand Down
4 changes: 1 addition & 3 deletions src/wallet/indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,7 @@ impl Indexer {

pub(crate) fn populate_tx_cache(
&self,
#[cfg_attr(feature = "esplora", allow(unused))] bdk_wallet: &PersistedWallet<
Store<ChangeSet>,
>,
#[cfg_attr(feature = "esplora", allow(unused))] bdk_wallet: &PersistedWallet<BdkStore>,
) {
match self {
#[cfg(feature = "electrum")]
Expand Down
4 changes: 2 additions & 2 deletions src/wallet/multisig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ impl WalletCore for MultisigWallet {
reveal(KeychainKind::Internal, response.internal);
reveal(KeychainKind::External, response.external);
if persist {
bdk_wallet.persist(bdk_database)?;
block_on(bdk_wallet.persist_async(bdk_database))?;
}
// sync UTXOs
self.sync_bdk_and_db_txos(txn, options, include_spent)
Expand All @@ -267,7 +267,7 @@ impl WalletOffline for MultisigWallet {
bdk_wallet.reveal_next_address(keychain);
}
let first_address = bdk_wallet.peek_address(keychain, start_index).address;
bdk_wallet.persist(bdk_database)?;
block_on(bdk_wallet.persist_async(bdk_database))?;
Ok(first_address)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/wallet/offline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1243,7 +1243,7 @@ pub trait WalletOffline: WalletBackup {
) -> Result<BdkAddress, Error> {
let (bdk_wallet, bdk_db) = self.bdk_wallet_db_mut();
let address = bdk_wallet.reveal_next_address(keychain).address;
bdk_wallet.persist(bdk_db)?;
block_on(bdk_wallet.persist_async(bdk_db))?;
Ok(address)
}

Expand Down
2 changes: 1 addition & 1 deletion src/wallet/online.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ pub trait WalletOnline: WalletOffline {
let seen_at = now().unix_timestamp() as u64;
let (bdk_wallet, bdk_db) = self.bdk_wallet_db_mut();
bdk_wallet.apply_unconfirmed_txs([(tx.clone(), seen_at)]);
bdk_wallet.persist(bdk_db)?;
block_on(bdk_wallet.persist_async(bdk_db))?;

// promote any newly-known colored UTXOs (e.g. the change output) from
// exists=false to exists=true in the rgb_lib DB
Expand Down
4 changes: 2 additions & 2 deletions src/wallet/test/go_online.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ fn consistency_check_fail_bitcoins() {
.unwrap();
{
let (bdk_wallet, bdk_database) = party_empty.wallet.bdk_wallet_db_mut();
bdk_wallet.persist(bdk_database).unwrap();
block_on(bdk_wallet.persist_async(bdk_database)).unwrap();
}
let mut rcv_party = get_funded_party!();
party_empty.drain_to(&rcv_party.get_address());
Expand Down Expand Up @@ -267,7 +267,7 @@ fn consistency_check_fail_utxos() {
.unwrap();
{
let (bdk_wallet, bdk_database) = party_empty.wallet.bdk_wallet_db_mut();
bdk_wallet.persist(bdk_database).unwrap();
block_on(bdk_wallet.persist_async(bdk_database)).unwrap();
}
let mut rcv_party = get_funded_party!();
party_empty.drain_to(&rcv_party.get_address());
Expand Down
Loading