Skip to content
Snippets Groups Projects
Commit bac71feb authored by Amar Singh's avatar Amar Singh Committed by GitHub
Browse files

Make functionality to read relay state proof entries public (#1135)


* add read entry and read optional entry to RelayChainStateProof pub methods

* rm toolchain

* docs

* Update pallets/parachain-system/src/relay_state_snapshot.rs

Co-authored-by: default avatarBastian Köcher <bkchr@users.noreply.github.com>
parent 81c7c25b
No related merge requests found
......@@ -63,6 +63,10 @@ pub struct MessagingStateSnapshot {
pub enum Error {
/// The provided proof was created against unexpected storage root.
RootMismatch,
/// The entry cannot be read.
ReadEntry(ReadEntryErr),
/// The optional entry cannot be read.
ReadOptionalEntry(ReadEntryErr),
/// The slot cannot be extracted.
Slot(ReadEntryErr),
/// The upgrade go-ahead signal cannot be read.
......@@ -273,4 +277,28 @@ impl RelayChainStateProof {
)
.map_err(Error::UpgradeRestriction)
}
/// Read an entry given by the key and try to decode it. If the value specified by the key according
/// to the proof is empty, the `fallback` value will be returned.
///
/// Returns `Err` in case the backend can't return the value under the specific key (likely due to
/// a malformed proof), in case the decoding fails, or in case where the value is empty in the relay
/// chain state and no fallback was provided.
pub fn read_entry<T>(&self, key: &[u8], fallback: Option<T>) -> Result<T, Error>
where
T: Decode,
{
read_entry(&self.trie_backend, key, fallback).map_err(Error::ReadEntry)
}
/// Read an optional entry given by the key and try to decode it.
///
/// Returns `Err` in case the backend can't return the value under the specific key (likely due to
/// a malformed proof) or if the value couldn't be decoded.
pub fn read_optional_entry<T>(&self, key: &[u8]) -> Result<Option<T>, Error>
where
T: Decode,
{
read_optional_entry(&self.trie_backend, key).map_err(Error::ReadOptionalEntry)
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment