bdk_wallet

Trait WalletPersister

Source
pub trait WalletPersister {
    type Error;

    // Required methods
    fn initialize(persister: &mut Self) -> Result<ChangeSet, Self::Error>;
    fn persist(
        persister: &mut Self,
        changeset: &ChangeSet,
    ) -> Result<(), Self::Error>;
}
Expand description

Trait that persists PersistedWallet.

For an async version, use AsyncWalletPersister.

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!). WalletPersister 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(persister: &mut Self) -> Result<ChangeSet, Self::Error>

Initialize the persister and load all data.

This is called by PersistedWallet::create and PersistedWallet::load to ensure the WalletPersister 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( persister: &mut Self, changeset: &ChangeSet, ) -> Result<(), Self::Error>

Persist the given changeset to the persister.

This method can fail if the persister is not initialized.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl WalletPersister for Connection

Source§

type Error = Error

Source§

fn initialize(persister: &mut Self) -> Result<ChangeSet, Self::Error>

Source§

fn persist( persister: &mut Self, changeset: &ChangeSet, ) -> Result<(), Self::Error>

Source§

impl WalletPersister for Store<ChangeSet>

Source§

type Error = FileStoreError

Source§

fn initialize(persister: &mut Self) -> Result<ChangeSet, Self::Error>

Source§

fn persist( persister: &mut Self, changeset: &ChangeSet, ) -> Result<(), Self::Error>

Source§

impl WalletPersister for Transaction<'_>

Source§

type Error = Error

Source§

fn initialize(persister: &mut Self) -> Result<ChangeSet, Self::Error>

Source§

fn persist( persister: &mut Self, changeset: &ChangeSet, ) -> Result<(), Self::Error>

Implementors§