Struct bdk_file_store::Store

source ·
pub struct Store<C>
where C: Sync + Send,
{ /* private fields */ }
Expand description

Persists an append-only list of changesets (C) to a single file.

Implementations§

source§

impl<C> Store<C>

source

pub fn create_new<P>(magic: &[u8], file_path: P) -> Result<Self, FileError>
where P: AsRef<Path>,

Create a new Store file in write-only mode; error if the file exists.

magic is the prefixed bytes to write to the new file. This will be checked when opening the Store in the future with open.

source

pub fn open<P>(magic: &[u8], file_path: P) -> Result<Self, FileError>
where P: AsRef<Path>,

Open an existing Store.

Use create_new to create a new Store.

§Errors

If the prefixed bytes of the opened file does not match the provided magic, the FileError::InvalidMagicBytes error variant will be returned.

source

pub fn open_or_create_new<P>( magic: &[u8], file_path: P ) -> Result<Self, FileError>
where P: AsRef<Path>,

Attempt to open existing Store file; create it if the file is non-existent.

Internally, this calls either open or create_new.

source

pub fn iter_changesets(&mut self) -> EntryIter<'_, C>

Iterates over the stored changeset from first to last, changing the seek position at each iteration.

The iterator may fail to read an entry and therefore return an error. However, the first time it returns an error will be the last. After doing so, the iterator will always yield None.

WARNING: This method changes the write position in the underlying file. You should always iterate over all entries until None is returned if you want your next write to go at the end; otherwise, you will write over existing entries.

source

pub fn aggregate_changesets( &mut self ) -> Result<Option<C>, AggregateChangesetsError<C>>

Loads all the changesets that have been stored as one giant changeset.

This function returns the aggregate changeset, or None if nothing was persisted. If reading or deserializing any of the entries fails, an error is returned that consists of all those it was able to read.

You should usually check the error. In many applications, it may make sense to do a full wallet scan with a stop-gap after getting an error, since it is likely that one of the changesets was unable to read changes of the derivation indices of a keychain.

WARNING: This method changes the write position of the underlying file. The next changeset will be written over the erroring entry (or the end of the file if none existed).

source

pub fn append_changeset(&mut self, changeset: &C) -> Result<(), Error>

Append a new changeset to the file and truncate the file to the end of the appended changeset.

The truncation is to avoid the possibility of having a valid but inconsistent changeset directly after the appended changeset.

Trait Implementations§

source§

impl<C> Debug for Store<C>
where C: Sync + Send + Debug,

source§

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

Formats the value using the given formatter. Read more
source§

impl<C> PersistBackend<C> for Store<C>

source§

fn write_changes(&mut self, changeset: &C) -> Result<()>

Writes a changeset to the persistence backend. Read more
source§

fn load_from_persistence(&mut self) -> Result<Option<C>>

Return the aggregate changeset C from persistence.

Auto Trait Implementations§

§

impl<C> Freeze for Store<C>

§

impl<C> RefUnwindSafe for Store<C>
where C: RefUnwindSafe,

§

impl<C> Send for Store<C>

§

impl<C> Sync for Store<C>

§

impl<C> Unpin for Store<C>
where C: Unpin,

§

impl<C> UnwindSafe for Store<C>
where C: UnwindSafe,

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<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

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, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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.