pub struct Store { /* private fields */ }Expand description
An asynchronous store for BDK wallet changesets backed by a local Turso database.
Use Store::new for a database with default settings, or Store::new_with_options to opt
into Turso experimental features. Call Store::migrate before using the low-level read/write
methods; initialization through AsyncWalletPersister performs migration automatically.
Implementations§
Source§impl Store
impl Store
Sourcepub async fn new_memory() -> Result<Self, Error>
pub async fn new_memory() -> Result<Self, Error>
Create an in-memory database with all experimental options disabled.
The database exists for the lifetime of the returned store and is not persisted to a file.
Use Store::new_memory_with_options when an in-memory database needs experimental
features.
Sourcepub async fn new_memory_with_options(options: Options) -> Result<Self, Error>
pub async fn new_memory_with_options(options: Options) -> Result<Self, Error>
Create an in-memory database using the supplied experimental options.
The options are applied while Turso opens the database. The database remains in memory for the lifetime of the store and is not persisted to disk.
Sourcepub async fn new(path: &str) -> Result<Self, Error>
pub async fn new(path: &str) -> Result<Self, Error>
Create or open a local database using default options.
This constructor leaves all experimental options disabled. It does not create the BDK
schema; call Store::migrate before using the persistence methods, unless the store is
initialized through AsyncWalletPersister.
Sourcepub async fn new_with_options(
path: &str,
options: Options,
) -> Result<Self, Error>
pub async fn new_with_options( path: &str, options: Options, ) -> Result<Self, Error>
Create or open a local database with the supplied Turso options.
The options are applied only while opening the database. All experimental features remain
disabled unless explicitly enabled on options. This constructor does not run the BDK
schema migration; call Store::migrate before using the persistence methods.
§Examples
use bdk_turso::{Options, Store};
let options = Options::new().with_attach().with_generated_columns();
let store = Store::new_with_options("wallet.sqlite", options).await?;
store.migrate().await?;Sourcepub fn from_database(database: Database) -> Self
pub fn from_database(database: Database) -> Self
Wrap an already-open Turso database in a Store.
This does not open a path or run the BDK schema migration. Call Store::migrate before
using persistence methods. Because the database was created externally, its opening options
are not inferred by the store.
Sourcepub fn options(&self) -> &Options
pub fn options(&self) -> &Options
Return the options retained by this store.
For stores created with Store::new_with_options or
Store::new_memory_with_options, this is the configuration passed to Turso. For stores
wrapped with Store::from_database, the original database settings are unknown and the
store retains default options.
Sourcepub async fn migrate(&self) -> Result<(), Error>
pub async fn migrate(&self) -> Result<(), Error>
Apply the bundled BDK persistence schema in a transaction.
This migration is safe to run repeatedly. It must be run before calling the low-level
changeset read/write methods directly; AsyncWalletPersister::initialize runs it for you.
Sourcepub async fn write_tx_graph(
conn: &DatabaseTransaction<'_>,
tx_graph: &ChangeSet<ConfirmationBlockTime>,
) -> Result<(), Error>
pub async fn write_tx_graph( conn: &DatabaseTransaction<'_>, tx_graph: &ChangeSet<ConfirmationBlockTime>, ) -> Result<(), Error>
Write transaction-graph records using an existing database transaction.
Persists transaction bytes, seen/evicted timestamps, transaction outputs, and confirmation
anchors. Existing transaction and output records are updated; duplicate anchors are
ignored. This helper does not commit conn, so the caller controls transaction completion.
Sourcepub async fn write_local_chain(
conn: &DatabaseTransaction<'_>,
local_chain: &ChangeSet,
) -> Result<(), Error>
pub async fn write_local_chain( conn: &DatabaseTransaction<'_>, local_chain: &ChangeSet, ) -> Result<(), Error>
Apply local-chain block changes using an existing database transaction.
A block with a hash is inserted at its height if that height is not already present; a
block with no hash removes the row at that height. This helper does not commit conn.
Sourcepub async fn write_keychain_txout(
conn: &DatabaseTransaction<'_>,
keychain_txout: &ChangeSet,
) -> Result<(), Error>
pub async fn write_keychain_txout( conn: &DatabaseTransaction<'_>, keychain_txout: &ChangeSet, ) -> Result<(), Error>
Persist keychain reveal indices and cached scripts using an existing transaction.
Reveal indices are updated when present in the changeset, while cached scripts are inserted
only if they do not already exist. This helper does not commit conn.
Sourcepub async fn read_tx_graph(
conn: &DatabaseTransaction<'_>,
) -> Result<ChangeSet<ConfirmationBlockTime>, Error>
pub async fn read_tx_graph( conn: &DatabaseTransaction<'_>, ) -> Result<ChangeSet<ConfirmationBlockTime>, Error>
Reconstruct transaction-graph changes from the database.
Reads transactions, timestamps, outputs, and confirmation anchors visible through conn.
The caller owns the transaction and controls when it is completed.
Sourcepub async fn read_local_chain(
conn: &DatabaseTransaction<'_>,
) -> Result<ChangeSet, Error>
pub async fn read_local_chain( conn: &DatabaseTransaction<'_>, ) -> Result<ChangeSet, Error>
Read all persisted local-chain blocks into a chain changeset.
Each stored height and hash is returned as a block entry with a hash. The caller owns conn
and controls the surrounding transaction.
Sourcepub async fn read_keychain_txout(
conn: &DatabaseTransaction<'_>,
) -> Result<ChangeSet, Error>
pub async fn read_keychain_txout( conn: &DatabaseTransaction<'_>, ) -> Result<ChangeSet, Error>
Read persisted reveal indices and cached scripts into a keychain changeset.
The returned changeset includes entries present in the database; an empty database yields
empty maps. The caller owns conn and controls the surrounding transaction.
Source§impl Store
impl Store
Sourcepub async fn write_changeset(&self, changeset: &ChangeSet) -> Result<(), Error>
pub async fn write_changeset(&self, changeset: &ChangeSet) -> Result<(), Error>
Persist every component of a wallet changeset in one transaction.
Network, descriptors, local-chain blocks, transaction-graph data, keychain scripts, and
locked outpoints are committed together. Run Store::migrate first, or initialize the
store through the async wallet persister, which migrates automatically.
Sourcepub async fn write_network(
conn: &DatabaseTransaction<'_>,
network: Network,
) -> Result<(), Error>
pub async fn write_network( conn: &DatabaseTransaction<'_>, network: Network, ) -> Result<(), Error>
Insert the wallet network if the database does not already contain one.
Existing network values are left unchanged. The caller owns conn and decides when to
commit or roll back the surrounding transaction.
Sourcepub async fn write_keychain_descriptors(
conn: &DatabaseTransaction<'_>,
descriptors: &BTreeMap<KeychainKind, Descriptor<DescriptorPublicKey>>,
) -> Result<(), Error>
pub async fn write_keychain_descriptors( conn: &DatabaseTransaction<'_>, descriptors: &BTreeMap<KeychainKind, Descriptor<DescriptorPublicKey>>, ) -> Result<(), Error>
Insert descriptors for the external and internal keychains when they are absent.
Existing descriptor rows are not replaced. The caller owns conn and decides when to
commit or roll back the surrounding transaction.
Sourcepub async fn read_changeset(&self) -> Result<ChangeSet, Error>
pub async fn read_changeset(&self) -> Result<ChangeSet, Error>
Read the complete persisted wallet state as a ChangeSet.
The read is performed in a transaction so its components are read from a consistent database view. Empty tables produce empty changeset components; the schema must already be migrated.
Sourcepub async fn read_network(
conn: &DatabaseTransaction<'_>,
) -> Result<Option<Network>, Error>
pub async fn read_network( conn: &DatabaseTransaction<'_>, ) -> Result<Option<Network>, Error>
Read the stored wallet network, if one has been persisted.
Returns Ok(None) when the network table is empty. The caller owns conn and controls the
surrounding transaction.
Sourcepub async fn read_keychain_descriptors(
conn: &DatabaseTransaction<'_>,
) -> Result<BTreeMap<KeychainKind, Descriptor<DescriptorPublicKey>>, Error>
pub async fn read_keychain_descriptors( conn: &DatabaseTransaction<'_>, ) -> Result<BTreeMap<KeychainKind, Descriptor<DescriptorPublicKey>>, Error>
Read the persisted external and internal descriptors into a keychain-indexed map.
An empty table produces an empty map. The caller owns conn and controls the surrounding
transaction.
Sourcepub async fn write_locked_outpoints(
conn: &DatabaseTransaction<'_>,
locked_outpoints: &ChangeSet,
) -> Result<(), Error>
pub async fn write_locked_outpoints( conn: &DatabaseTransaction<'_>, locked_outpoints: &ChangeSet, ) -> Result<(), Error>
Apply locked-outpoint changes to the database.
Entries marked true are inserted; entries marked false are removed. The caller owns
conn and decides when to commit or roll back the surrounding transaction.
Sourcepub async fn read_locked_outpoints(
conn: &DatabaseTransaction<'_>,
) -> Result<ChangeSet, Error>
pub async fn read_locked_outpoints( conn: &DatabaseTransaction<'_>, ) -> Result<ChangeSet, Error>
Read the outpoints currently recorded as locked.
The returned changeset contains each stored outpoint with its value set to true; unlocked
outpoints are represented by their absence. The caller owns conn and controls the
surrounding transaction.
Trait Implementations§
Source§impl AsyncWalletPersister for Store
impl AsyncWalletPersister for Store
Auto Trait Implementations§
impl !RefUnwindSafe for Store
impl !UnwindSafe for Store
impl Freeze for Store
impl Send for Store
impl Sync for Store
impl Unpin for Store
impl UnsafeUnpin for Store
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more