pub struct Store { /* private fields */ }Expand description
§Meta Storage(CAS)
In-memory CAS (content addressed storage) for Rain metadata which basically stores k/v pairs of meta hash, meta bytes and ExpressionDeployer reproducible data as well as providing functionalities to easliy read/write to the CAS.
Hashes are normal bytes and meta bytes are valid cbor encoded as data bytes. ExpressionDeployers data are in form of a struct mapped to deployedBytecode meta hash and deploy transaction hash.
§Examples
use rain_metadata::Store;
use rain_metadata::meta::cache::{DeployerCache, MetaCache};
use std::collections::HashMap;
// to instantiate with an empty subgraph list
let mut store = Store::new();
// or to instantiate with initial values
let mut store = Store::create(
&vec!["sg-url-1".to_string()],
&MetaCache::default(),
&DeployerCache::default(),
&HashMap::new(),
);
// add a new subgraph endpoint url to the subgraph list
store.add_subgraphs(&vec!["sg-url-2".to_string()]);
// merge another Store into this one
store.merge(&Store::new());
// updates the meta store with some bytes and the hash they hash to - a
// pair that does not is refused, so the hash is derived rather than picked
let bytes = vec![0u8, 1u8];
let hash = alloy::primitives::keccak256(&bytes).0.to_vec();
store.update_with(&hash, &bytes).unwrap();
// `Store::update(&hash)` is async; it searches each subgraph for `hash` and
// populates the cache with the result. Call it from an async context with `.await`.
// to get a record from the store
let _meta = store.get_meta(&hash);
// to get a deployer record from the store
let _deployer_record = store.get_deployer(&hash);
// Store is agnostic to dotrain contents — it just maps the hash of the content
// to the given uri and puts it as a new meta into the meta cache.
let dotrain_uri = "path/to/file.rain";
let dotrain_content = "/* some dotrain source */";
let (_new_hash, _old_hash) = store
.set_dotrain(dotrain_content, dotrain_uri, false)
.unwrap();
// to get dotrain meta bytes given a uri
let _dotrain_meta_bytes = store.get_dotrain_meta(dotrain_uri);Implementations§
Source§impl Store
impl Store
Sourcepub fn new() -> Store
pub fn new() -> Store
lazily creates a new instance with no subgraphs it is recommended to use create() instead with initial values
Sourcepub fn create(
subgraphs: &Vec<String>,
cache: &MetaCache,
deployer_cache: &DeployerCache,
dotrain_cache: &HashMap<String, Vec<u8>>,
) -> Store
pub fn create( subgraphs: &Vec<String>, cache: &MetaCache, deployer_cache: &DeployerCache, dotrain_cache: &HashMap<String, Vec<u8>>, ) -> Store
creates new instance of Store with given initial values it checks the validity of each item of the provided values and only stores those that are valid
Sourcepub fn add_subgraphs(&mut self, subgraphs: &Vec<String>)
pub fn add_subgraphs(&mut self, subgraphs: &Vec<String>)
add new subgraph endpoints
Sourcepub fn get_meta(&self, hash: &[u8]) -> Option<&Vec<u8>>
pub fn get_meta(&self, hash: &[u8]) -> Option<&Vec<u8>>
get the corresponding meta bytes of the given hash if it exists
Sourcepub fn deployer_cache(&self) -> &DeployerCache
pub fn deployer_cache(&self) -> &DeployerCache
getter method for the whole authoring meta cache
Sourcepub fn get_deployer(&self, hash: &[u8]) -> Option<&NPE2Deployer>
pub fn get_deployer(&self, hash: &[u8]) -> Option<&NPE2Deployer>
get the corresponding DeployerNPRecord of the given deployer hash if it exists
Sourcepub async fn search_deployer(
&mut self,
hash: &[u8],
) -> Result<&NPE2Deployer, Error>
pub async fn search_deployer( &mut self, hash: &[u8], ) -> Result<&NPE2Deployer, Error>
searches for DeployerNPRecord in the subgraphs given the deployer hash. The meta bytes it carries go through Self::insert_verified like every other write to the meta cache, so a deployer record cannot smuggle in bytes that do not hash to the meta hash it claims for them.
Sourcepub async fn search_deployer_check(
&mut self,
hash: &[u8],
) -> Result<&NPE2Deployer, Error>
pub async fn search_deployer_check( &mut self, hash: &[u8], ) -> Result<&NPE2Deployer, Error>
if the NPE2Deployer record already is cached it returns it immediately else searches for NPE2Deployer in the subgraphs given the deployer hash
Sourcepub fn set_deployer_from_query_response(
&mut self,
deployer_query_response: DeployerResponse,
) -> Result<NPE2Deployer, Error>
pub fn set_deployer_from_query_response( &mut self, deployer_query_response: DeployerResponse, ) -> Result<NPE2Deployer, Error>
sets deployer record from the deployer query response
Sourcepub fn set_deployer(
&mut self,
hash: &[u8],
npe2_deployer: &NPE2Deployer,
tx_hash: Option<&[u8]>,
) -> Result<(), Error>
pub fn set_deployer( &mut self, hash: &[u8], npe2_deployer: &NPE2Deployer, tx_hash: Option<&[u8]>, ) -> Result<(), Error>
sets NPE2Deployer record, and its constructor meta in the meta cache
Errors without writing anything if hash is not a 32 byte hash, the
record is missing a field needed to reproduce the deployer, or its meta
bytes do not hash to the meta hash it claims for them.
Sourcepub fn dotrain_cache(&self) -> &HashMap<String, Vec<u8>>
pub fn dotrain_cache(&self) -> &HashMap<String, Vec<u8>>
getter method for the whole dotrain cache
Sourcepub fn get_dotrain_hash(&self, uri: &str) -> Option<&Vec<u8>>
pub fn get_dotrain_hash(&self, uri: &str) -> Option<&Vec<u8>>
get the corresponding dotrain hash of the given dotrain uri if it exists
Sourcepub fn get_dotrain_uri(&self, hash: &[u8]) -> Option<&String>
pub fn get_dotrain_uri(&self, hash: &[u8]) -> Option<&String>
get the corresponding uri of the given dotrain hash if it exists
Sourcepub fn get_dotrain_meta(&self, uri: &str) -> Option<&Vec<u8>>
pub fn get_dotrain_meta(&self, uri: &str) -> Option<&Vec<u8>>
get the corresponding meta bytes of the given dotrain uri if it exists
Sourcepub fn delete_dotrain(&mut self, uri: &str, keep_meta: bool)
pub fn delete_dotrain(&mut self, uri: &str, keep_meta: bool)
deletes a dotrain record given a uri
Sourcepub fn merge(&mut self, other: &Store)
pub fn merge(&mut self, other: &Store)
lazilly merges another Store to the current one, avoids duplicates every map keeps the entry this Store already has on a key collision
Sourcepub async fn update(&mut self, hash: &[u8]) -> Result<&Vec<u8>, Error>
pub async fn update(&mut self, hash: &[u8]) -> Result<&Vec<u8>, Error>
updates the meta cache by searching through all subgraphs for the given hash, and returns the reference to the meta bytes in the cache if it was found. Refreshes unconditionally; Self::update_check is the variant that leaves an already cached hash alone.
Sourcepub async fn update_check(&mut self, hash: &[u8]) -> Result<&Vec<u8>, Error>
pub async fn update_check(&mut self, hash: &[u8]) -> Result<&Vec<u8>, Error>
first checks if the meta is stored, if not will perform update()
Sourcepub fn update_with(
&mut self,
hash: &[u8],
bytes: &[u8],
) -> Result<&Vec<u8>, Error>
pub fn update_with( &mut self, hash: &[u8], bytes: &[u8], ) -> Result<&Vec<u8>, Error>
updates the meta cache with the given hash and meta bytes, and returns the reference to the bytes if they were accepted. Leaves an already cached hash alone, as Self::update_check does for the subgraph path.
Sourcepub fn set_dotrain(
&mut self,
text: &str,
uri: &str,
keep_old: bool,
) -> Result<(Vec<u8>, Vec<u8>), Error>
pub fn set_dotrain( &mut self, text: &str, uri: &str, keep_old: bool, ) -> Result<(Vec<u8>, Vec<u8>), Error>
stores (or updates in case the URI already exists) the given dotrain text as meta into the store cache and maps it to the given uri (path), it should be noted that reading the content of the dotrain is not in the scope of Store and handling and passing on a correct URI (path) for the given text must be handled externally by the implementer
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Store
impl<'de> Deserialize<'de> for Store
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl StructuralPartialEq for Store
Auto Trait Implementations§
impl Freeze for Store
impl RefUnwindSafe for Store
impl Send for Store
impl Sync for Store
impl Unpin for Store
impl UnsafeUnpin for Store
impl UnwindSafe for Store
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
impl<'de, T> BorrowedRpcObject<'de> for T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
impl<T> ErasedDestructor for Twhere
T: 'static,
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> 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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more