bdk_file_store

Struct 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.

⚠ This is a development/testing database. It does not natively support backwards compatible BDK version upgrades so should not be used in production.

Implementations§

Source§

impl<C> Store<C>
where C: Merge + Serialize + DeserializeOwned + Send + Sync,

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

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>,

Source§

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>,

Source§

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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V