refactor(chain,wallet)!: move rusqlite things into it's own file
Also fix imports and rename `sqlite` module to `rusqlite_impl`.
This commit is contained in:
@@ -32,10 +32,10 @@ mod types;
|
||||
mod wallet;
|
||||
|
||||
pub(crate) use bdk_chain::collections;
|
||||
#[cfg(feature = "sqlite")]
|
||||
#[cfg(feature = "rusqlite")]
|
||||
pub use bdk_chain::rusqlite;
|
||||
#[cfg(feature = "sqlite")]
|
||||
pub use bdk_chain::sqlite;
|
||||
#[cfg(feature = "rusqlite")]
|
||||
pub use bdk_chain::rusqlite_impl;
|
||||
pub use descriptor::template;
|
||||
pub use descriptor::HdKeyPaths;
|
||||
pub use signer;
|
||||
|
||||
@@ -64,7 +64,7 @@ impl Merge for ChangeSet {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "sqlite")]
|
||||
#[cfg(feature = "rusqlite")]
|
||||
impl ChangeSet {
|
||||
/// Schema name for wallet.
|
||||
pub const WALLET_SCHEMA_NAME: &'static str = "bdk_wallet";
|
||||
@@ -84,14 +84,14 @@ impl ChangeSet {
|
||||
) STRICT;",
|
||||
Self::WALLET_TABLE_NAME,
|
||||
)];
|
||||
crate::sqlite::migrate_schema(db_tx, Self::WALLET_SCHEMA_NAME, &[schema_v0])
|
||||
crate::rusqlite_impl::migrate_schema(db_tx, Self::WALLET_SCHEMA_NAME, &[schema_v0])
|
||||
}
|
||||
|
||||
/// Recover a [`ChangeSet`] from sqlite database.
|
||||
pub fn from_sqlite(db_tx: &chain::rusqlite::Transaction) -> chain::rusqlite::Result<Self> {
|
||||
Self::init_wallet_sqlite_tables(db_tx)?;
|
||||
use crate::sqlite::Sql;
|
||||
use chain::rusqlite::OptionalExtension;
|
||||
use chain::Impl;
|
||||
use miniscript::{Descriptor, DescriptorPublicKey};
|
||||
|
||||
let mut changeset = Self::default();
|
||||
@@ -103,13 +103,13 @@ impl ChangeSet {
|
||||
let row = wallet_statement
|
||||
.query_row([], |row| {
|
||||
Ok((
|
||||
row.get::<_, Sql<Descriptor<DescriptorPublicKey>>>("descriptor")?,
|
||||
row.get::<_, Sql<Descriptor<DescriptorPublicKey>>>("change_descriptor")?,
|
||||
row.get::<_, Sql<bitcoin::Network>>("network")?,
|
||||
row.get::<_, Impl<Descriptor<DescriptorPublicKey>>>("descriptor")?,
|
||||
row.get::<_, Impl<Descriptor<DescriptorPublicKey>>>("change_descriptor")?,
|
||||
row.get::<_, Impl<bitcoin::Network>>("network")?,
|
||||
))
|
||||
})
|
||||
.optional()?;
|
||||
if let Some((Sql(desc), Sql(change_desc), Sql(network))) = row {
|
||||
if let Some((Impl(desc), Impl(change_desc), Impl(network))) = row {
|
||||
changeset.descriptor = Some(desc);
|
||||
changeset.change_descriptor = Some(change_desc);
|
||||
changeset.network = Some(network);
|
||||
@@ -129,7 +129,7 @@ impl ChangeSet {
|
||||
) -> chain::rusqlite::Result<()> {
|
||||
Self::init_wallet_sqlite_tables(db_tx)?;
|
||||
use chain::rusqlite::named_params;
|
||||
use chain::sqlite::Sql;
|
||||
use chain::Impl;
|
||||
|
||||
let mut descriptor_statement = db_tx.prepare_cached(&format!(
|
||||
"INSERT INTO {}(id, descriptor) VALUES(:id, :descriptor) ON CONFLICT(id) DO UPDATE SET descriptor=:descriptor",
|
||||
@@ -138,7 +138,7 @@ impl ChangeSet {
|
||||
if let Some(descriptor) = &self.descriptor {
|
||||
descriptor_statement.execute(named_params! {
|
||||
":id": 0,
|
||||
":descriptor": Sql(descriptor.clone()),
|
||||
":descriptor": Impl(descriptor.clone()),
|
||||
})?;
|
||||
}
|
||||
|
||||
@@ -149,7 +149,7 @@ impl ChangeSet {
|
||||
if let Some(change_descriptor) = &self.change_descriptor {
|
||||
change_descriptor_statement.execute(named_params! {
|
||||
":id": 0,
|
||||
":change_descriptor": Sql(change_descriptor.clone()),
|
||||
":change_descriptor": Impl(change_descriptor.clone()),
|
||||
})?;
|
||||
}
|
||||
|
||||
@@ -160,7 +160,7 @@ impl ChangeSet {
|
||||
if let Some(network) = self.network {
|
||||
network_statement.execute(named_params! {
|
||||
":id": 0,
|
||||
":network": Sql(network),
|
||||
":network": Impl(network),
|
||||
})?;
|
||||
}
|
||||
|
||||
|
||||
@@ -586,7 +586,7 @@ impl Wallet {
|
||||
///
|
||||
/// ```rust,no_run
|
||||
/// # use bdk_wallet::{LoadParams, ChangeSet, KeychainKind};
|
||||
/// use bdk_chain::sqlite::Connection;
|
||||
/// use bdk_chain::rusqlite::Connection;
|
||||
/// let mut conn = Connection::open_in_memory().expect("must open connection");
|
||||
/// let mut wallet = LoadParams::new()
|
||||
/// .load_wallet(&mut conn)
|
||||
|
||||
@@ -5,8 +5,8 @@ use crate::{descriptor::DescriptorError, Wallet};
|
||||
/// Represents a persisted wallet.
|
||||
pub type PersistedWallet = bdk_chain::Persisted<Wallet>;
|
||||
|
||||
#[cfg(feature = "sqlite")]
|
||||
impl<'c> chain::PersistWith<bdk_chain::sqlite::Transaction<'c>> for Wallet {
|
||||
#[cfg(feature = "rusqlite")]
|
||||
impl<'c> chain::PersistWith<bdk_chain::rusqlite::Transaction<'c>> for Wallet {
|
||||
type CreateParams = crate::CreateParams;
|
||||
type LoadParams = crate::LoadParams;
|
||||
|
||||
@@ -15,7 +15,7 @@ impl<'c> chain::PersistWith<bdk_chain::sqlite::Transaction<'c>> for Wallet {
|
||||
type PersistError = bdk_chain::rusqlite::Error;
|
||||
|
||||
fn create(
|
||||
db: &mut bdk_chain::sqlite::Transaction<'c>,
|
||||
db: &mut bdk_chain::rusqlite::Transaction<'c>,
|
||||
params: Self::CreateParams,
|
||||
) -> Result<Self, Self::CreateError> {
|
||||
let mut wallet =
|
||||
@@ -29,7 +29,7 @@ impl<'c> chain::PersistWith<bdk_chain::sqlite::Transaction<'c>> for Wallet {
|
||||
}
|
||||
|
||||
fn load(
|
||||
conn: &mut bdk_chain::sqlite::Transaction<'c>,
|
||||
conn: &mut bdk_chain::rusqlite::Transaction<'c>,
|
||||
params: Self::LoadParams,
|
||||
) -> Result<Option<Self>, Self::LoadError> {
|
||||
let changeset =
|
||||
@@ -41,15 +41,15 @@ impl<'c> chain::PersistWith<bdk_chain::sqlite::Transaction<'c>> for Wallet {
|
||||
}
|
||||
|
||||
fn persist(
|
||||
db: &mut bdk_chain::sqlite::Transaction<'c>,
|
||||
db: &mut bdk_chain::rusqlite::Transaction<'c>,
|
||||
changeset: &<Self as chain::Staged>::ChangeSet,
|
||||
) -> Result<(), Self::PersistError> {
|
||||
changeset.persist_to_sqlite(db)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "sqlite")]
|
||||
impl chain::PersistWith<bdk_chain::sqlite::Connection> for Wallet {
|
||||
#[cfg(feature = "rusqlite")]
|
||||
impl chain::PersistWith<bdk_chain::rusqlite::Connection> for Wallet {
|
||||
type CreateParams = crate::CreateParams;
|
||||
type LoadParams = crate::LoadParams;
|
||||
|
||||
@@ -58,7 +58,7 @@ impl chain::PersistWith<bdk_chain::sqlite::Connection> for Wallet {
|
||||
type PersistError = bdk_chain::rusqlite::Error;
|
||||
|
||||
fn create(
|
||||
db: &mut bdk_chain::sqlite::Connection,
|
||||
db: &mut bdk_chain::rusqlite::Connection,
|
||||
params: Self::CreateParams,
|
||||
) -> Result<Self, Self::CreateError> {
|
||||
let mut db_tx = db.transaction().map_err(CreateWithPersistError::Persist)?;
|
||||
@@ -68,7 +68,7 @@ impl chain::PersistWith<bdk_chain::sqlite::Connection> for Wallet {
|
||||
}
|
||||
|
||||
fn load(
|
||||
db: &mut bdk_chain::sqlite::Connection,
|
||||
db: &mut bdk_chain::rusqlite::Connection,
|
||||
params: Self::LoadParams,
|
||||
) -> Result<Option<Self>, Self::LoadError> {
|
||||
let mut db_tx = db.transaction().map_err(LoadWithPersistError::Persist)?;
|
||||
@@ -78,7 +78,7 @@ impl chain::PersistWith<bdk_chain::sqlite::Connection> for Wallet {
|
||||
}
|
||||
|
||||
fn persist(
|
||||
db: &mut bdk_chain::sqlite::Connection,
|
||||
db: &mut bdk_chain::rusqlite::Connection,
|
||||
changeset: &<Self as chain::Staged>::ChangeSet,
|
||||
) -> Result<(), Self::PersistError> {
|
||||
let db_tx = db.transaction()?;
|
||||
|
||||
Reference in New Issue
Block a user