unc_vm_runner/logic/
mod.rs1use borsh::{BorshDeserialize, BorshSerialize};
2use std::fmt;
3use types::AccountId;
4use unc_primitives_core::hash::CryptoHash;
5
6mod alt_bn128;
7mod context;
8mod dependencies;
9pub mod errors;
10pub mod gas_counter;
11mod logic;
12pub mod mocks;
13pub mod test_utils;
14#[cfg(test)]
15mod tests;
16pub mod types;
17mod utils;
18mod vmstate;
19
20pub use context::VMContext;
21pub use dependencies::{External, MemSlice, MemoryLike, ValuePtr};
22pub use errors::{HostError, VMLogicError};
23pub use gas_counter::with_ext_cost_counter;
24pub use logic::{VMLogic, VMOutcome};
25pub use types::ReturnData;
26pub use unc_parameters::vm::{Config, ContractPrepareVersion, LimitConfig, StorageGetMode};
27pub use unc_primitives_core::types::ProtocolVersion;
28
29#[derive(Debug, Clone, PartialEq, BorshDeserialize, BorshSerialize)]
30pub enum CompiledContract {
31 CompileModuleError(errors::CompilationError),
32 Code(Vec<u8>),
33}
34
35pub trait CompiledContractCache: Send + Sync {
37 fn put(&self, key: &CryptoHash, value: CompiledContract) -> std::io::Result<()>;
38 fn get(&self, key: &CryptoHash) -> std::io::Result<Option<CompiledContract>>;
39 fn has(&self, key: &CryptoHash) -> std::io::Result<bool> {
40 self.get(key).map(|entry| entry.is_some())
41 }
42}
43
44impl fmt::Debug for dyn CompiledContractCache {
45 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
46 write!(f, "Compiled contracts cache")
47 }
48}
49
50#[derive(Debug, PartialEq)]
52pub struct TrieNodesCount {
53 pub db_reads: u64,
55 pub mem_reads: u64,
57}
58
59impl TrieNodesCount {
60 pub fn checked_sub(self, other: &Self) -> Option<Self> {
62 Some(Self {
63 db_reads: self.db_reads.checked_sub(other.db_reads)?,
64 mem_reads: self.mem_reads.checked_sub(other.mem_reads)?,
65 })
66 }
67}
68
69#[derive(
72 BorshSerialize,
73 BorshDeserialize,
74 Hash,
75 Clone,
76 Debug,
77 PartialEq,
78 Eq,
79 serde::Serialize,
80 serde::Deserialize,
81)]
82pub struct DataReceiver {
83 pub data_id: CryptoHash,
84 pub receiver_id: AccountId,
85}