Trait bdk_wallet::AsyncWalletPersister

source ·
pub trait AsyncWalletPersister {
    type Error;

    // Required methods
    fn initialize<'a>(
        persister: &'a mut Self
    ) -> Pin<Box<dyn Future<Output = Result<ChangeSet, Self::Error>> + Send + 'a>>
       where Self: 'a;
    fn persist<'a>(
        persister: &'a mut Self,
        changeset: &'a ChangeSet
    ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'a>>
       where Self: 'a;
}
Expand description

Async trait that persists PersistedWallet.

For a blocking version, use WalletPersister.

Associated functions of this trait should not be called directly, and the trait is designed so that associated functions are hard to find (since they are not methods!). AsyncWalletPersister is used by PersistedWallet (a light wrapper around Wallet) which enforces some level of safety. Refer to PersistedWallet for more about the safety checks.

Required Associated Types§

source

type Error

Error type of the persister.

Required Methods§

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.

This is called by PersistedWallet::create_async and PersistedWallet::load_async to ensure the AsyncWalletPersister is initialized and returns all data in the persister.

§Implementation Details

The database schema of the persister (if any), should be initialized and migrated here.

The implementation must return all data currently stored in the persister. If there is no data, return an empty changeset (using ChangeSet::default()).

Error should only occur on database failure. Multiple calls to initialize should not error. Calling initialize inbetween calls to persist should not error.

Calling persist before the persister is initialized may error. However, some persister implementations may NOT require initialization at all (and not error).

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.

This method can fail if the persister is not initialized.

Object Safety§

This trait is not object safe.

Implementors§