Struct sc_client_api::in_mem::Blockchain
source · pub struct Blockchain<Block: BlockT> { /* private fields */ }
Expand description
In-memory blockchain. Supports concurrent reads.
Implementations§
source§impl<Block: BlockT> Blockchain<Block>
impl<Block: BlockT> Blockchain<Block>
sourcepub fn new() -> Blockchain<Block>
pub fn new() -> Blockchain<Block>
Create new in-memory blockchain storage.
sourcepub fn insert(
&self,
hash: Block::Hash,
header: <Block as BlockT>::Header,
justifications: Option<Justifications>,
body: Option<Vec<<Block as BlockT>::Extrinsic>>,
new_state: NewBlockState
) -> Result<()>
pub fn insert( &self, hash: Block::Hash, header: <Block as BlockT>::Header, justifications: Option<Justifications>, body: Option<Vec<<Block as BlockT>::Extrinsic>>, new_state: NewBlockState ) -> Result<()>
Insert a block header and associated data.
sourcepub fn blocks_count(&self) -> usize
pub fn blocks_count(&self) -> usize
Get total number of blocks.
sourcepub fn equals_to(&self, other: &Self) -> bool
pub fn equals_to(&self, other: &Self) -> bool
Compare this blockchain with another in-mem blockchain
sourcepub fn canon_equals_to(&self, other: &Self) -> bool
pub fn canon_equals_to(&self, other: &Self) -> bool
Compare canonical chain to other canonical chain.
sourcepub fn insert_cht_root(&self, block: NumberFor<Block>, cht_root: Block::Hash)
pub fn insert_cht_root(&self, block: NumberFor<Block>, cht_root: Block::Hash)
Insert header CHT root.
Trait Implementations§
source§impl<Block: BlockT> AuxStore for Blockchain<Block>
impl<Block: BlockT> AuxStore for Blockchain<Block>
source§fn insert_aux<'a, 'b: 'a, 'c: 'a, I: IntoIterator<Item = &'a (&'c [u8], &'c [u8])>, D: IntoIterator<Item = &'a &'b [u8]>>(
&self,
insert: I,
delete: D
) -> Result<()>
fn insert_aux<'a, 'b: 'a, 'c: 'a, I: IntoIterator<Item = &'a (&'c [u8], &'c [u8])>, D: IntoIterator<Item = &'a &'b [u8]>>( &self, insert: I, delete: D ) -> Result<()>
Insert auxiliary data into key-value store. Read more
source§impl<Block: BlockT> Backend<Block> for Blockchain<Block>
impl<Block: BlockT> Backend<Block> for Blockchain<Block>
source§fn body(
&self,
hash: Block::Hash
) -> Result<Option<Vec<<Block as BlockT>::Extrinsic>>>
fn body( &self, hash: Block::Hash ) -> Result<Option<Vec<<Block as BlockT>::Extrinsic>>>
Get block body. Returns
None
if block is not found.source§fn justifications(&self, hash: Block::Hash) -> Result<Option<Justifications>>
fn justifications(&self, hash: Block::Hash) -> Result<Option<Justifications>>
Get block justifications. Returns
None
if no justification exists.source§fn last_finalized(&self) -> Result<Block::Hash>
fn last_finalized(&self) -> Result<Block::Hash>
Get last finalized block hash.
source§fn leaves(&self) -> Result<Vec<Block::Hash>>
fn leaves(&self) -> Result<Vec<Block::Hash>>
Returns hashes of all blocks that are leaves of the block tree.
in other words, that have no children, are chain heads.
Results must be ordered best (longest, highest) chain first.
source§fn displaced_leaves_after_finalizing(
&self,
block_number: NumberFor<Block>
) -> Result<Vec<Block::Hash>>
fn displaced_leaves_after_finalizing( &self, block_number: NumberFor<Block> ) -> Result<Vec<Block::Hash>>
Returns displaced leaves after the given block would be finalized. Read more
source§fn children(&self, _parent_hash: Block::Hash) -> Result<Vec<Block::Hash>>
fn children(&self, _parent_hash: Block::Hash) -> Result<Vec<Block::Hash>>
Return hashes of all blocks that are children of the block with
parent_hash
.source§fn indexed_transaction(&self, _hash: Block::Hash) -> Result<Option<Vec<u8>>>
fn indexed_transaction(&self, _hash: Block::Hash) -> Result<Option<Vec<u8>>>
Get single indexed transaction by content hash. Note that this will only fetch transactions
that are indexed by the runtime with
storage_index_transaction
.fn block_indexed_body(&self, _hash: Block::Hash) -> Result<Option<Vec<Vec<u8>>>>
source§impl<Block: BlockT> Default for Blockchain<Block>
impl<Block: BlockT> Default for Blockchain<Block>
source§impl<Block: BlockT> HeaderBackend<Block> for Blockchain<Block>
impl<Block: BlockT> HeaderBackend<Block> for Blockchain<Block>
source§fn header(&self, hash: Block::Hash) -> Result<Option<<Block as BlockT>::Header>>
fn header(&self, hash: Block::Hash) -> Result<Option<<Block as BlockT>::Header>>
Get block header. Returns
None
if block is not found.source§fn number(&self, hash: Block::Hash) -> Result<Option<NumberFor<Block>>>
fn number(&self, hash: Block::Hash) -> Result<Option<NumberFor<Block>>>
Get block number by hash. Returns
None
if the header is not in the chain.source§fn hash(
&self,
number: <<Block as BlockT>::Header as HeaderT>::Number
) -> Result<Option<Block::Hash>>
fn hash( &self, number: <<Block as BlockT>::Header as HeaderT>::Number ) -> Result<Option<Block::Hash>>
Get block hash by number. Returns
None
if the header is not in the chain.source§fn block_hash_from_id(
&self,
id: &BlockId<Block>
) -> Result<Option<<Block as Block>::Hash>, Error>
fn block_hash_from_id( &self, id: &BlockId<Block> ) -> Result<Option<<Block as Block>::Hash>, Error>
Convert an arbitrary block ID into a block hash.
source§fn block_number_from_id(
&self,
id: &BlockId<Block>
) -> Result<Option<<<Block as Block>::Header as Header>::Number>, Error>
fn block_number_from_id( &self, id: &BlockId<Block> ) -> Result<Option<<<Block as Block>::Header as Header>::Number>, Error>
Convert an arbitrary block ID into a block hash.
source§fn expect_header(
&self,
hash: <Block as Block>::Hash
) -> Result<<Block as Block>::Header, Error>
fn expect_header( &self, hash: <Block as Block>::Hash ) -> Result<<Block as Block>::Header, Error>
Get block header. Returns
UnknownBlock
error if block is not found.source§impl<Block: BlockT> HeaderMetadata<Block> for Blockchain<Block>
impl<Block: BlockT> HeaderMetadata<Block> for Blockchain<Block>
fn header_metadata( &self, hash: Block::Hash ) -> Result<CachedHeaderMetadata<Block>, Self::Error>
fn insert_header_metadata( &self, _hash: Block::Hash, _metadata: CachedHeaderMetadata<Block> )
fn remove_header_metadata(&self, _hash: Block::Hash)
Auto Trait Implementations§
impl<Block> !RefUnwindSafe for Blockchain<Block>
impl<Block> Send for Blockchain<Block>
impl<Block> Sync for Blockchain<Block>
impl<Block> Unpin for Blockchain<Block>
impl<Block> !UnwindSafe for Blockchain<Block>
Blanket Implementations§
source§impl<T> CheckedConversion for T
impl<T> CheckedConversion for T
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere T: Any,
§fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
Convert
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
Convert
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.source§impl<Block, T> ForkBackend<Block> for Twhere
Block: Block,
T: HeaderMetadata<Block> + HeaderBackend<Block> + Send + Sync,
impl<Block, T> ForkBackend<Block> for Twhere Block: Block, T: HeaderMetadata<Block> + HeaderBackend<Block> + Send + Sync,
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T, Outer> IsWrappedBy<Outer> for Twhere
Outer: AsRef<T> + AsMut<T> + From<T>,
T: From<Outer>,
impl<T, Outer> IsWrappedBy<Outer> for Twhere Outer: AsRef<T> + AsMut<T> + From<T>, T: From<Outer>,
§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> SaturatedConversion for T
impl<T> SaturatedConversion for T
§fn saturated_from<T>(t: T) -> Selfwhere
Self: UniqueSaturatedFrom<T>,
fn saturated_from<T>(t: T) -> Selfwhere Self: UniqueSaturatedFrom<T>,
§fn saturated_into<T>(self) -> Twhere
Self: UniqueSaturatedInto<T>,
fn saturated_into<T>(self) -> Twhere Self: UniqueSaturatedInto<T>,
Consume self to return an equivalent value of
T
. Read moresource§impl<S, T> UncheckedInto<T> for Swhere
T: UncheckedFrom<S>,
impl<S, T> UncheckedInto<T> for Swhere T: UncheckedFrom<S>,
source§fn unchecked_into(self) -> T
fn unchecked_into(self) -> T
The counterpart to
unchecked_from
.§impl<T, S> UniqueSaturatedInto<T> for Swhere
T: Bounded,
S: TryInto<T>,
impl<T, S> UniqueSaturatedInto<T> for Swhere T: Bounded, S: TryInto<T>,
§fn unique_saturated_into(self) -> T
fn unique_saturated_into(self) -> T
Consume self to return an equivalent value of
T
.