pub struct Hypercore { /* private fields */ }
Expand description
Hypercore is an append-only log structure.
Implementations§
Source§impl Hypercore
impl Hypercore
Sourcepub async fn append(
&mut self,
data: &[u8],
) -> Result<AppendOutcome, HypercoreError>
pub async fn append( &mut self, data: &[u8], ) -> Result<AppendOutcome, HypercoreError>
Appends a data slice to the hypercore.
Sourcepub async fn append_batch<A: AsRef<[u8]>, B: AsRef<[A]>>(
&mut self,
batch: B,
) -> Result<AppendOutcome, HypercoreError>
pub async fn append_batch<A: AsRef<[u8]>, B: AsRef<[A]>>( &mut self, batch: B, ) -> Result<AppendOutcome, HypercoreError>
Appends a given batch of data slices to the hypercore.
Sourcepub fn event_subscribe(&self) -> Receiver<Event>
pub fn event_subscribe(&self) -> Receiver<Event>
Subscribe to core events relevant to replication
Sourcepub async fn get(
&mut self,
index: u64,
) -> Result<Option<Vec<u8>>, HypercoreError>
pub async fn get( &mut self, index: u64, ) -> Result<Option<Vec<u8>>, HypercoreError>
Read value at given index, if any.
Sourcepub async fn clear(
&mut self,
start: u64,
end: u64,
) -> Result<(), HypercoreError>
pub async fn clear( &mut self, start: u64, end: u64, ) -> Result<(), HypercoreError>
Clear data for entries between start and end (exclusive) indexes.
Sourcepub fn key_pair(&self) -> &PartialKeypair
pub fn key_pair(&self) -> &PartialKeypair
Access the key pair.
Sourcepub async fn create_proof(
&mut self,
block: Option<RequestBlock>,
hash: Option<RequestBlock>,
seek: Option<RequestSeek>,
upgrade: Option<RequestUpgrade>,
) -> Result<Option<Proof>, HypercoreError>
pub async fn create_proof( &mut self, block: Option<RequestBlock>, hash: Option<RequestBlock>, seek: Option<RequestSeek>, upgrade: Option<RequestUpgrade>, ) -> Result<Option<Proof>, HypercoreError>
Create a proof for given request
Sourcepub async fn verify_and_apply_proof(
&mut self,
proof: &Proof,
) -> Result<bool, HypercoreError>
pub async fn verify_and_apply_proof( &mut self, proof: &Proof, ) -> Result<bool, HypercoreError>
Verify and apply proof received from peer, returns true if changed, false if not possible to apply.
Sourcepub async fn missing_nodes(&mut self, index: u64) -> Result<u64, HypercoreError>
pub async fn missing_nodes(&mut self, index: u64) -> Result<u64, HypercoreError>
Used to fill the nodes field of a RequestBlock
during
synchronization.
Sourcepub async fn missing_nodes_from_merkle_tree_index(
&mut self,
merkle_tree_index: u64,
) -> Result<u64, HypercoreError>
pub async fn missing_nodes_from_merkle_tree_index( &mut self, merkle_tree_index: u64, ) -> Result<u64, HypercoreError>
Get missing nodes using a merkle tree index. Advanced variant of missing_nodex that allow for special cases of searching directly from the merkle tree.
Sourcepub async fn make_read_only(&mut self) -> Result<bool, HypercoreError>
pub async fn make_read_only(&mut self) -> Result<bool, HypercoreError>
Makes the hypercore read-only by deleting the secret key. Returns true if the hypercore was changed, false if the hypercore was already read-only. This is useful in scenarios where a hypercore should be made immutable after initial values have been stored.