Trait bdk_wallet::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.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl WalletPersister for Connection

§

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>

§

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<'c> WalletPersister for Transaction<'c>

§

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§