Skip to main content

Store

Struct Store 

Source
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

Source

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.

Source

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.

Source

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.

Source

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?;
Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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

Source§

type Error = Error

Error type of the persister.
Source§

fn initialize<'a>( persister: &'a mut Self, ) -> Pin<Box<dyn Future<Output = Result<ChangeSet, Self::Error>> + Send + 'a>>
where Self: 'a,

Initialize the persister and load all data. Read more
Source§

fn persist<'a>( persister: &'a mut Self, changeset: &'a ChangeSet, ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'a>>
where Self: 'a,

Persist the given changeset to the persister. Read more
Source§

impl Clone for Store

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Store

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more