Struct rain_metadata::Store

source ·
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_meta::Store;
use std::collections::HashMap;


// to instantiate with including default subgraphs
let mut store = Store::new();

// to instatiate 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()]);

// update the store with another Store (merges the stores)
store.merge(&Store::default());

// hash of a meta to search and store
let hash = vec![0u8, 1u8, 2u8];

// updates the meta store with a new meta by searching through subgraphs
store.update(&hash);

// updates the meta store with a new meta hash and bytes
store.update_with(&hash, &vec![0u8, 1u8]);

// to get a record from store
let meta = store.get_meta(&hash);

// to get a deployer record from store
let deployer_record = store.get_deployer(&hash);

// path to a .rain file
let dotrain_uri = "path/to/file.rain";

// reading the dotrain content as an example,
// 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, so obtaining and passing the correct
// content is up to the implementer
let dotrain_content = std::fs::read_to_string(&dotrain_uri).unwrap_or(String::new());

// updates the dotrain cache for a dotrain text and uri
let (new_hash, old_hash) = store.set_dotrain(&dotrain_content, &dotrain_uri.to_string(), false).unwrap();

// to get dotrain meta bytes given a uri
let dotrain_meta_bytes = store.get_dotrain_meta(&dotrain_uri.to_string());

Implementations§

source§

impl Store

source

pub fn new() -> Store

lazily creates a new instance it is recommended to use create() instead with initial values

source

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

source

pub fn subgraphs(&self) -> &Vec<String>

all subgraph endpoints in this instance

source

pub fn add_subgraphs(&mut self, subgraphs: &Vec<String>)

add new subgraph endpoints

source

pub fn cache(&self) -> &HashMap<Vec<u8>, Vec<u8>>

getter method for the whole meta cache

source

pub fn get_meta(&self, hash: &[u8]) -> Option<&Vec<u8>>

get the corresponding meta bytes of the given hash if it exists

source

pub fn deployer_cache(&self) -> &HashMap<Vec<u8>, NPE2Deployer>

getter method for the whole authoring meta cache

source

pub fn get_deployer(&self, hash: &[u8]) -> Option<&NPE2Deployer>

get the corresponding DeployerNPRecord of the given deployer hash if it exists

source

pub async fn search_deployer(&mut self, hash: &[u8]) -> Option<&NPE2Deployer>

searches for DeployerNPRecord in the subgraphs given the deployer hash

source

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

source

pub fn set_deployer_from_query_response( &mut self, deployer_query_response: DeployerResponse ) -> NPE2Deployer

sets deployer record from the deployer query response

source

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

source

pub fn dotrain_cache(&self) -> &HashMap<String, Vec<u8>>

getter method for the whole dotrain cache

source

pub fn get_dotrain_hash(&self, uri: &str) -> Option<&Vec<u8>>

get the corresponding dotrain hash of the given dotrain uri if it exists

source

pub fn get_dotrain_uri(&self, hash: &[u8]) -> Option<&String>

get the corresponding uri of the given dotrain hash if it exists

source

pub fn get_dotrain_meta(&self, uri: &str) -> Option<&Vec<u8>>

get the corresponding meta bytes of the given dotrain uri if it exists

source

pub fn delete_dotrain(&mut self, uri: &str, keep_meta: bool)

deletes a dotrain record given a uri

source

pub fn merge(&mut self, other: &Store)

lazilly merges another Store to the current one, avoids duplicates

source

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

source

pub async fn update_check(&mut self, hash: &[u8]) -> Option<&Vec<u8>>

first checks if the meta is stored, if not will perform update()

source

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

source

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 Clone for Store

source§

fn clone(&self) -> Store

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Store

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Store

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<'de> Deserialize<'de> for Store

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl PartialEq for Store

source§

fn eq(&self, other: &Store) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for Store

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl StructuralPartialEq for Store

Auto Trait Implementations§

§

impl RefUnwindSafe for Store

§

impl Send for Store

§

impl Sync for Store

§

impl Unpin for Store

§

impl UnwindSafe for Store

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> DynClone for T
where T: Clone,

source§

fn __clone_box(&self, _: Private) -> *mut ()

source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,