Struct jormungandr::blockchain::Storage
source · pub struct Storage {
storage: BlockStore,
span: Span,
}
Fields§
§storage: BlockStore
§span: Span
Implementations§
source§impl Storage
impl Storage
pub fn file<P: AsRef<Path>>(path: P, span: Span) -> Result<Self, Error>
pub fn memory(span: Span) -> Result<Self, Error>
pub fn get_tag(&self, tag: &str) -> Result<Option<HeaderHash>, Error>
pub fn put_tag(&self, tag: &str, header_hash: HeaderHash) -> Result<(), Error>
pub fn get(&self, header_hash: HeaderHash) -> Result<Option<Block>, Error>
pub fn block_exists(&self, header_hash: HeaderHash) -> Result<bool, Error>
pub fn get_branches(&self) -> Result<Vec<HeaderHash>, Error>
pub fn get_blocks_by_chain_length( &self, chain_length: u32 ) -> Result<Vec<Block>, Error>
pub fn get_nth_ancestor( &self, header_hash: HeaderHash, distance: u32 ) -> Result<Option<Block>, Error>
pub fn put_block(&self, block: &Block) -> Result<(), Error>
pub fn get_parent( &self, header_hash: HeaderHash ) -> Result<Option<HeaderHash>, Error>
pub fn is_ancestor(&self, a: HeaderHash, b: HeaderHash) -> bool
pub fn get_chain_length(&self, block_id: HeaderHash) -> Option<u32>
sourcepub fn stream_from_to(
&self,
from: HeaderHash,
to: HeaderHash
) -> Result<impl Stream<Item = Result<Block, Error>>, Error>
pub fn stream_from_to( &self, from: HeaderHash, to: HeaderHash ) -> Result<impl Stream<Item = Result<Block, Error>>, Error>
Return values:
Ok(stream)
-from
is ancestor ofto
, returns blocks between themErr(CannotIterate)
-from
is not ancestor ofto
Err(BlockNotFound)
-from
orto
was not foundErr(_)
- some other storage error
sourcepub async fn send_branch(
&self,
to: HeaderHash,
depth: Option<u32>,
handle: ReplyStreamHandle<Block>
) -> Result<(), ReplySendError>
pub async fn send_branch( &self, to: HeaderHash, depth: Option<u32>, handle: ReplyStreamHandle<Block> ) -> Result<(), ReplySendError>
Stream a branch ending at to
and starting from the ancestor
at depth
or at the first ancestor since genesis block
if depth
is given as None
.
This function uses buffering in the in-memory channel to reduce synchronization overhead.
sourcepub async fn send_branch_with<T, F>(
&self,
to: HeaderHash,
depth: Option<u32>,
handle: ReplyStreamHandle<T>,
transform: F
) -> Result<(), ReplySendError>where
F: FnMut(Block) -> T + Send + 'static,
T: Send + 'static,
pub async fn send_branch_with<T, F>( &self, to: HeaderHash, depth: Option<u32>, handle: ReplyStreamHandle<T>, transform: F ) -> Result<(), ReplySendError>where F: FnMut(Block) -> T + Send + 'static, T: Send + 'static,
Like send_branch
, but with a transformation function applied
to the block content before sending to the in-memory channel.
pub fn find_closest_ancestor( &self, checkpoints: Vec<HeaderHash>, descendant: HeaderHash ) -> Result<Option<Ancestor>, Error>
pub fn find_common_ancestor( &self, tip_1: HeaderHash, tip_2: HeaderHash ) -> Result<HeaderHash, Error>
pub fn gc( &self, threshold_depth: u32, main_branch_tip: &[u8] ) -> Result<(), Error>
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Storage
impl Send for Storage
impl Sync for Storage
impl Unpin for Storage
impl !UnwindSafe for Storage
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T
in a tonic::Request
source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T
in a tonic::Request