pchain_runtime/contract/context.rs
1/*
2 Copyright © 2023, ParallelChain Lab
3 Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0
4*/
5
6//! Defines a struct containing context for a Smart Contract Execution such as cache for storing
7//! smart contract module and VM memory limit for contract execution.
8
9use crate::{wasmer::wasmer_store, Cache};
10
11/// Smart Contract Context stores useful information for contract execution.
12#[derive(Clone)]
13pub(crate) struct SmartContractContext {
14 /// smart contract cache for storing compiled wasmer module to save transition time
15 pub cache: Option<Cache>,
16 /// smart contract VM memory limit
17 pub memory_limit: Option<usize>,
18}
19
20impl SmartContractContext {
21 /// Instantiate [wasmer::Store] from this context.
22 pub fn instantiate_store(&self) -> wasmer::Store {
23 wasmer_store::instantiate_store(u64::MAX, self.memory_limit)
24 }
25}