Struct locutus_runtime::prelude::ContractStore
source · pub struct ContractStore { /* private fields */ }Expand description
Handle contract blob storage on the file system.
Implementations§
source§impl ContractStore
impl ContractStore
sourcepub fn new(contracts_dir: PathBuf, max_size: i64) -> RuntimeResult<Self>
pub fn new(contracts_dir: PathBuf, max_size: i64) -> RuntimeResult<Self>
Arguments
- max_size: max size in bytes of the contracts being cached
sourcepub fn fetch_contract(
&self,
key: &ContractKey,
params: &Parameters<'_>
) -> Option<ContractContainer>
pub fn fetch_contract(
&self,
key: &ContractKey,
params: &Parameters<'_>
) -> Option<ContractContainer>
Returns a copy of the contract bytes if available, none otherwise.
Examples found in repository?
src/runtime.rs (line 131)
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
pub(crate) fn prepare_contract_call(
&mut self,
key: &ContractKey,
parameters: &Parameters,
req_bytes: usize,
) -> RuntimeResult<Instance> {
let module = if let Some(module) = self.contract_modules.get(key) {
module
} else {
let contract = self
.contract_store
.fetch_contract(key, parameters)
.ok_or_else(|| RuntimeInnerError::ContractNotFound(key.clone()))?;
let module = match contract {
ContractContainer::Wasm(WasmAPIVersion::V1(contract_v1)) => {
Module::new(&self.wasm_store, contract_v1.code().data())?
}
};
self.contract_modules.insert(key.clone(), module);
self.contract_modules.get(key).unwrap()
}
.clone();
let instance = self.prepare_instance(&module)?;
self.set_instance_mem(req_bytes, &instance)?;
Ok(instance)
}sourcepub fn store_contract(
&mut self,
contract: ContractContainer
) -> RuntimeResult<()>
pub fn store_contract(
&mut self,
contract: ContractContainer
) -> RuntimeResult<()>
Store a copy of the contract in the local store, in case it hasn’t been stored previously.
pub fn get_contract_path(&mut self, key: &ContractKey) -> RuntimeResult<PathBuf>
sourcepub fn code_hash_from_key(&self, key: &ContractKey) -> Option<[u8; 32]>
pub fn code_hash_from_key(&self, key: &ContractKey) -> Option<[u8; 32]>
Examples found in repository?
src/contract_store.rs (line 211)
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
pub fn get_contract_path(&mut self, key: &ContractKey) -> RuntimeResult<PathBuf> {
let contract_hash = match key.code_hash() {
Some(k) => *k,
None => self.code_hash_from_key(key).ok_or_else(|| {
tracing::warn!("trying to store partially unspecified contract `{key}`");
RuntimeInnerError::UnwrapContract
})?,
};
let key_path = bs58::encode(contract_hash)
.with_alphabet(bs58::Alphabet::BITCOIN)
.into_string()
.to_lowercase();
Ok(self.contracts_dir.join(key_path).with_extension("wasm"))
}Auto Trait Implementations§
impl !RefUnwindSafe for ContractStore
impl Send for ContractStore
impl Sync for ContractStore
impl Unpin for ContractStore
impl !UnwindSafe for ContractStore
Blanket Implementations§
§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
§type ArchivedMetadata = ()
type ArchivedMetadata = ()
The archived version of the pointer metadata for this type.
§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata
) -> <T as Pointee>::Metadata
fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata
) -> <T as Pointee>::Metadata
Converts some archived metadata to the pointer metadata for itself.
§impl<F, W, T, D> Deserialize<With<T, W>, D> for Fwhere
W: DeserializeWith<F, T, D>,
D: Fallible + ?Sized,
F: ?Sized,
impl<F, W, T, D> Deserialize<With<T, W>, D> for Fwhere
W: DeserializeWith<F, T, D>,
D: Fallible + ?Sized,
F: ?Sized,
§fn deserialize(
&self,
deserializer: &mut D
) -> Result<With<T, W>, <D as Fallible>::Error>
fn deserialize(
&self,
deserializer: &mut D
) -> Result<With<T, W>, <D as Fallible>::Error>
Deserializes using the given deserializer
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> ⓘ
§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> Upcastable for Twhere
T: 'static + Any + Send + Sync,
impl<T> Upcastable for Twhere
T: 'static + Any + Send + Sync,
§fn upcast_any_ref(&self) -> &(dyn Any + 'static)
fn upcast_any_ref(&self) -> &(dyn Any + 'static)
upcast ref
§fn upcast_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn upcast_any_mut(&mut self) -> &mut (dyn Any + 'static)
upcast mut ref