Struct sc_client_api::in_mem::Blockchain
source · [−]pub struct Blockchain<Block: BlockT> { /* private fields */ }
Expand description
In-memory blockchain. Supports concurrent reads.
Implementations
sourceimpl<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,
justification: Option<Justification>,
body: Option<Vec<<Block as BlockT>::Extrinsic>>,
new_state: NewBlockState
) -> Result<()>
pub fn insert(
&self,
hash: Block::Hash,
header: <Block as BlockT>::Header,
justification: Option<Justification>,
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
sourceimpl<Block: BlockT> AuxStore for Blockchain<Block>
impl<Block: BlockT> AuxStore for Blockchain<Block>
sourceimpl<Block: BlockT> Backend<Block> for Blockchain<Block>
impl<Block: BlockT> Backend<Block> for Blockchain<Block>
sourcefn body(
&self,
id: BlockId<Block>
) -> Result<Option<Vec<<Block as BlockT>::Extrinsic>>>
fn body(
&self,
id: BlockId<Block>
) -> Result<Option<Vec<<Block as BlockT>::Extrinsic>>>
Get block body. Returns None
if block is not found.
sourcefn justification(&self, id: BlockId<Block>) -> Result<Option<Justification>>
fn justification(&self, id: BlockId<Block>) -> Result<Option<Justification>>
Get block justification. Returns None
if justification does not exist.
sourcefn last_finalized(&self) -> Result<Block::Hash>
fn last_finalized(&self) -> Result<Block::Hash>
Get last finalized block hash.
sourcefn cache(&self) -> Option<Arc<dyn Cache<Block>>>
fn cache(&self) -> Option<Arc<dyn Cache<Block>>>
Returns data cache reference, if it is enabled on this backend.
sourcefn 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. Read more
sourcefn 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
.
sourcefn extrinsic(
&self,
_hash: &Block::Hash
) -> Result<Option<<Block as BlockT>::Extrinsic>>
fn extrinsic(
&self,
_hash: &Block::Hash
) -> Result<Option<<Block as BlockT>::Extrinsic>>
Get single extrinsic by hash.
sourcefn best_containing(
&self,
target_hash: <Block as Block>::Hash,
maybe_max_number: Option<<<Block as Block>::Header as Header>::Number>,
import_lock: &RwLock<RawRwLock, ()>
) -> Result<Option<<Block as Block>::Hash>, Error>
fn best_containing(
&self,
target_hash: <Block as Block>::Hash,
maybe_max_number: Option<<<Block as Block>::Header as Header>::Number>,
import_lock: &RwLock<RawRwLock, ()>
) -> Result<Option<<Block as Block>::Hash>, Error>
Get the most recent block hash of the best (longest) chains
that contain block with the given target_hash
. Read more
sourceimpl<Block: BlockT + Clone> Clone for Blockchain<Block>
impl<Block: BlockT + Clone> Clone for Blockchain<Block>
sourceimpl<Block: BlockT> Default for Blockchain<Block>
impl<Block: BlockT> Default for Blockchain<Block>
sourceimpl<Block: BlockT> HeaderBackend<Block> for Blockchain<Block>
impl<Block: BlockT> HeaderBackend<Block> for Blockchain<Block>
sourcefn header(
&self,
id: BlockId<Block>
) -> Result<Option<<Block as BlockT>::Header>>
fn header(
&self,
id: BlockId<Block>
) -> Result<Option<<Block as BlockT>::Header>>
Get block header. Returns None
if block is not found.
sourcefn status(&self, id: BlockId<Block>) -> Result<BlockStatus>
fn status(&self, id: BlockId<Block>) -> Result<BlockStatus>
Get block status.
sourcefn 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.
sourcefn 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.
sourcefn 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.
sourcefn 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.
sourcefn expect_header(
&self,
id: BlockId<Block>
) -> Result<<Block as Block>::Header, Error>
fn expect_header(
&self,
id: BlockId<Block>
) -> Result<<Block as Block>::Header, Error>
Get block header. Returns UnknownBlock
error if block is not found.
sourceimpl<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)
sourceimpl<Block: BlockT> ProvideCache<Block> for Blockchain<Block>
impl<Block: BlockT> ProvideCache<Block> for Blockchain<Block>
sourceimpl<Block: BlockT> ProvideChtRoots<Block> for Blockchain<Block>
impl<Block: BlockT> ProvideChtRoots<Block> for Blockchain<Block>
sourceimpl<Block: BlockT> Storage<Block> for Blockchain<Block> where
Block::Hash: From<[u8; 32]>,
impl<Block: BlockT> Storage<Block> for Blockchain<Block> where
Block::Hash: From<[u8; 32]>,
sourcefn import_header(
&self,
header: Block::Header,
_cache: HashMap<CacheKeyId, Vec<u8>>,
state: NewBlockState,
aux_ops: Vec<(Vec<u8>, Option<Vec<u8>>)>
) -> Result<()>
fn import_header(
&self,
header: Block::Header,
_cache: HashMap<CacheKeyId, Vec<u8>>,
state: NewBlockState,
aux_ops: Vec<(Vec<u8>, Option<Vec<u8>>)>
) -> Result<()>
Store new header. Should refuse to revert any finalized blocks. Read more
sourcefn last_finalized(&self) -> Result<Block::Hash>
fn last_finalized(&self) -> Result<Block::Hash>
Get last finalized header.
sourcefn finalize_header(&self, id: BlockId<Block>) -> Result<()>
fn finalize_header(&self, id: BlockId<Block>) -> Result<()>
Mark historic header as finalized.
sourcefn usage_info(&self) -> Option<UsageInfo>
fn usage_info(&self) -> Option<UsageInfo>
Get storage usage statistics.
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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> CheckedConversion for T
impl<T> CheckedConversion for T
sourcefn checked_from<T>(t: T) -> Option<Self> where
Self: TryFrom<T>,
fn checked_from<T>(t: T) -> Option<Self> where
Self: TryFrom<T>,
Convert from a value of T
into an equivalent instance of Option<Self>
. Read more
sourcefn checked_into<T>(self) -> Option<T> where
Self: TryInto<T>,
fn checked_into<T>(self) -> Option<T> where
Self: TryInto<T>,
Consume self to return Some
equivalent value of Option<T>
. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T, Outer> IsWrappedBy<Outer> for T where
Outer: AsRef<T> + AsMut<T> + From<T>,
T: From<Outer>,
impl<T, Outer> IsWrappedBy<Outer> for T where
Outer: AsRef<T> + AsMut<T> + From<T>,
T: From<Outer>,
sourceimpl<T> Pointable for T
impl<T> Pointable for T
sourceimpl<T> SaturatedConversion for T
impl<T> SaturatedConversion for T
sourcefn saturated_from<T>(t: T) -> Self where
Self: UniqueSaturatedFrom<T>,
fn saturated_from<T>(t: T) -> Self where
Self: UniqueSaturatedFrom<T>,
Convert from a value of T
into an equivalent instance of Self
. Read more
sourcefn saturated_into<T>(self) -> T where
Self: UniqueSaturatedInto<T>,
fn saturated_into<T>(self) -> T where
Self: UniqueSaturatedInto<T>,
Consume self to return an equivalent value of T
. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more
sourceimpl<S, T> UncheckedInto<T> for S where
T: UncheckedFrom<S>,
impl<S, T> UncheckedInto<T> for S where
T: UncheckedFrom<S>,
sourcepub fn unchecked_into(self) -> T
pub fn unchecked_into(self) -> T
The counterpart to unchecked_from
.
sourceimpl<T, S> UniqueSaturatedInto<T> for S where
T: Bounded,
S: TryInto<T>,
impl<T, S> UniqueSaturatedInto<T> for S where
T: Bounded,
S: TryInto<T>,
sourcepub fn unique_saturated_into(self) -> T
pub fn unique_saturated_into(self) -> T
Consume self to return an equivalent value of T
.
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more