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§
Required Methods§
sourcefn initialize(persister: &mut Self) -> Result<ChangeSet, Self::Error>
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 initialize
d may error. However, some
persister implementations may NOT require initialization at all (and not error).