pub struct BlockStore {
    permanent: PermanentStore,
    root_id: Value,
    id_length: usize,
    blocks_tree: Tree,
    info_tree: Tree,
    chain_length_index_tree: Tree,
    branches_tips_tree: Tree,
    tags_tree: Tree,
    _db: Db,
}

Fields§

§permanent: PermanentStore§root_id: Value§id_length: usize§blocks_tree: Tree§info_tree: Tree§chain_length_index_tree: Tree§branches_tips_tree: Tree§tags_tree: Tree§_db: Db

Implementations§

source§

impl BlockStore

source

pub fn file<P: AsRef<Path>, I: Into<Value> + Clone>( path: P, root_id: I ) -> Result<Self, Error>

Create a new storage handle. The path must not exist or should be a directory. The directory will be created if it does not exist.

Arguments
  • path - a path to the storage directory.
  • root_id - the ID of the root block which the first block in this block chain should refer to as a parent.
source

pub fn memory<I: Into<Value> + Clone>(root_id: I) -> Result<Self, Error>

Open a temporary in-memory database.

Arguments
  • root_id - the ID of the root block which the first block in this block chain should refer to as a parent.
source

fn new<I: Into<Value>>( root_id: I, volatile: Db, permanent: PermanentStore ) -> Result<Self, Error>

source

pub fn put_block( &self, block: &[u8], block_info: BlockInfo ) -> Result<(), Error>

Write a block to the store. The parent of the block must exist (unless it’s the root id).

Arguments
  • block - a serialized representation of a block.
  • block_info - block metadata for internal needs (indexing, linking between blocks, etc)
source

pub fn get_block(&self, block_id: &[u8]) -> Result<Value, Error>

Get a block from the storage.

Arguments
  • block_id - the serialized block identifier.
source

pub fn get_block_info(&self, block_id: &[u8]) -> Result<BlockInfo, Error>

Get the BlockInfo instance for the requested block.

Arguments
  • block_id - the serialized block identifier.
source

fn get_block_info_volatile(&self, block_id: &[u8]) -> Result<BlockInfo, Error>

source

pub fn get_blocks_by_chain_length( &self, chain_length: u32 ) -> Result<Vec<Value>, Error>

Get multiple serialized blocks from the given chain length. This will return block contents, not their IDs. If there is a block at the given chain length in the permanent storage, only this block is returned. Other branches are considered to be ready of removal if there are any.

source

pub fn put_tag(&self, tag_name: &str, block_id: &[u8]) -> Result<(), Error>

Add a tag for a given block. The block id can be later retrieved by this tag.

source

pub fn get_tag(&self, tag_name: &str) -> Result<Option<Value>, Error>

Get the block ID for the given tag.

source

pub fn get_tips_ids(&self) -> Result<Vec<Value>, Error>

Get identifier of all branches tips.

source

pub fn prune_branch(&self, tip_id: &[u8]) -> Result<(), Error>

Prune a branch with the given tip id from the storage.

source

pub fn block_exists(&self, block_id: &[u8]) -> Result<bool, Error>

Check if the block with the given id exists.

source

fn block_exists_volatile(&self, block_id: &[u8]) -> Result<bool, Error>

source

pub fn is_ancestor( &self, ancestor_id: &[u8], descendant_id: &[u8] ) -> Result<Option<u32>, Error>

Determine whether block identified by ancestor_id is an ancestor of block identified by descendant_id.

Returned values:

  • Ok(Some(dist)) - ancestor is ancestor of descendant and there are dist blocks between them
  • Ok(None) - ancestor is not ancestor of descendant
  • Err(error) - ancestor or descendant was not found
source

pub fn get_nth_ancestor( &self, block_id: &[u8], distance: u32 ) -> Result<BlockInfo, Error>

Get n-th (n = distance) ancestor of the block, identified by block_id.

source

pub fn find_lowest_common_ancestor( &self, block1: &[u8], block2: &[u8] ) -> Result<Option<BlockInfo>, Error>

Find the lowest common ancestor block (commonly referred to as lca) of two blocks in the chain

In case there are more than one common ancestor, pick the one with the biggest chain length.

source

pub fn flush_to_permanent_store( &self, to_block: &[u8], min_number: usize ) -> Result<usize, Error>

Move all blocks up to the provided block ID to the permanent block storage.

Arguments
  • to_block - the ID of the block until which we want to flush blocks to the permanent storage.
  • min_number - the minimum number of blocks to be flushed. If less than this number of blocks is available for flushing the function will not trigger.
Panics

If min_number is less than 1.

Returns

The number of blocks that were flushed.

source

pub fn iter( &self, to_block: &[u8], distance: u32 ) -> Result<impl Iterator<Item = Result<Value, Error>>, Error>

Iterate to the given block starting from the block at the given distance - 1. distance == 1 means that only to_block will be iterated. distance == 0 means empty iterator.

Trait Implementations§

source§

impl Clone for BlockStore

source§

fn clone(&self) -> BlockStore

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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.

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere 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 Twhere 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.