use borsh::{BorshDeserialize, BorshSerialize};
use unc_primitives_core::hash::CryptoHash;
use std::fmt;
use types::AccountId;
mod alt_bn128;
mod context;
mod dependencies;
pub mod errors;
pub mod gas_counter;
mod logic;
pub mod mocks;
pub mod test_utils;
#[cfg(test)]
mod tests;
pub mod types;
mod utils;
mod vmstate;
pub use context::VMContext;
pub use dependencies::{External, MemSlice, MemoryLike, ValuePtr};
pub use errors::{HostError, VMLogicError};
pub use gas_counter::with_ext_cost_counter;
pub use logic::{VMLogic, VMOutcome};
pub use unc_parameters::vm::{Config, ContractPrepareVersion, LimitConfig, StorageGetMode};
pub use unc_primitives_core::types::ProtocolVersion;
pub use types::ReturnData;
#[derive(Debug, Clone, PartialEq, BorshDeserialize, BorshSerialize)]
pub enum CompiledContract {
CompileModuleError(errors::CompilationError),
Code(Vec<u8>),
}
pub trait CompiledContractCache: Send + Sync {
fn put(&self, key: &CryptoHash, value: CompiledContract) -> std::io::Result<()>;
fn get(&self, key: &CryptoHash) -> std::io::Result<Option<CompiledContract>>;
fn has(&self, key: &CryptoHash) -> std::io::Result<bool> {
self.get(key).map(|entry| entry.is_some())
}
}
impl fmt::Debug for dyn CompiledContractCache {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Compiled contracts cache")
}
}
#[derive(Debug, PartialEq)]
pub struct TrieNodesCount {
pub db_reads: u64,
pub mem_reads: u64,
}
impl TrieNodesCount {
pub fn checked_sub(self, other: &Self) -> Option<Self> {
Some(Self {
db_reads: self.db_reads.checked_sub(other.db_reads)?,
mem_reads: self.mem_reads.checked_sub(other.mem_reads)?,
})
}
}
#[derive(
BorshSerialize,
BorshDeserialize,
Hash,
Clone,
Debug,
PartialEq,
Eq,
serde::Serialize,
serde::Deserialize,
)]
pub struct DataReceiver {
pub data_id: CryptoHash,
pub receiver_id: AccountId,
}