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 std::collections::HashMap;
// to instantiate without any default subgraphs
let mut store = Store::new();
// to instantiate with default rain subgraphs included
let mut store = Store::default();
// or to instantiate with initial values
let mut store = Store::create(
&vec!["sg-url-1".to_string()],
&HashMap::new(),
&HashMap::new(),
&HashMap::new(),
true,
);
// 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::default());
// updates the meta store with a new meta hash and bytes
let hash = vec![0u8, 1u8, 2u8];
store.update_with(&hash, &vec![0u8, 1u8]);
// `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 it is recommended to use create() instead with initial values
Sourcepub fn create(
subgraphs: &Vec<String>,
cache: &HashMap<Vec<u8>, Vec<u8>>,
deployer_cache: &HashMap<Vec<u8>, NPE2Deployer>,
dotrain_cache: &HashMap<String, Vec<u8>>,
include_rain_subgraphs: bool,
) -> Store
pub fn create( subgraphs: &Vec<String>, cache: &HashMap<Vec<u8>, Vec<u8>>, deployer_cache: &HashMap<Vec<u8>, NPE2Deployer>, dotrain_cache: &HashMap<String, Vec<u8>>, include_rain_subgraphs: bool, ) -> 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) -> &HashMap<Vec<u8>, NPE2Deployer>
pub fn deployer_cache(&self) -> &HashMap<Vec<u8>, NPE2Deployer>
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]) -> Option<&NPE2Deployer>
pub async fn search_deployer(&mut self, hash: &[u8]) -> Option<&NPE2Deployer>
searches for DeployerNPRecord in the subgraphs given the deployer hash
Sourcepub async fn search_deployer_check(
&mut self,
hash: &[u8],
) -> Option<&NPE2Deployer>
pub async fn search_deployer_check( &mut self, hash: &[u8], ) -> Option<&NPE2Deployer>
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,
) -> NPE2Deployer
pub fn set_deployer_from_query_response( &mut self, deployer_query_response: DeployerResponse, ) -> NPE2Deployer
sets deployer record from the deployer query response
Sourcepub fn set_deployer(
&mut self,
hash: &[u8],
npe2_deployer: &NPE2Deployer,
tx_hash: Option<&[u8]>,
)
pub fn set_deployer( &mut self, hash: &[u8], npe2_deployer: &NPE2Deployer, tx_hash: Option<&[u8]>, )
sets NPE2Deployer record skips if the given hash is invalid
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
Sourcepub async fn update(&mut self, hash: &[u8]) -> Option<&Vec<u8>>
pub async fn update(&mut self, hash: &[u8]) -> Option<&Vec<u8>>
updates the meta cache by searching through all subgraphs for the given hash returns the reference to the meta bytes in the cache if it was found
Sourcepub async fn update_check(&mut self, hash: &[u8]) -> Option<&Vec<u8>>
pub async fn update_check(&mut self, hash: &[u8]) -> Option<&Vec<u8>>
first checks if the meta is stored, if not will perform update()
Sourcepub fn update_with(&mut self, hash: &[u8], bytes: &[u8]) -> Option<&Vec<u8>>
pub fn update_with(&mut self, hash: &[u8], bytes: &[u8]) -> Option<&Vec<u8>>
updates the meta cache by the given hash and meta bytes, checks the hash to bytes validity returns the reference to the bytes if the updated meta bytes contained any
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