cfx_vm_types/
lib.rs

1// Copyright 2019 Conflux Foundation. All rights reserved.
2// Conflux is free software and distributed under GNU General Public License.
3// See http://www.gnu.org/licenses/
4
5mod action_params;
6mod call_create_type;
7mod context;
8mod env;
9mod error;
10mod instruction_result;
11mod interpreter_info;
12mod return_data;
13mod spec;
14
15#[cfg(any(test, feature = "testonly_code"))]
16pub mod tests;
17
18pub use self::{
19    action_params::{ActionParams, ActionValue, ParamsType},
20    call_create_type::{CallType, CreateType},
21    context::{
22        BlockHashSource, Context, ContractCreateResult, MessageCallResult,
23    },
24    env::Env,
25    error::{
26        separate_out_db_error, Error, ExecTrapError, ExecTrapResult, Result,
27        TrapError, TrapKind, TrapResult,
28    },
29    instruction_result::InstructionResult,
30    interpreter_info::InterpreterInfo,
31    return_data::{GasLeft, ReturnData},
32    spec::{CIP645Spec, ConsensusGasSpec, Spec},
33};
34
35/// Virtual Machine interface
36pub trait Exec: Send {
37    /// This function should be used to execute transaction.
38    /// It returns either an error, a known amount of gas left, or parameters
39    /// to be used to compute the final gas left.
40    fn exec(
41        self: Box<Self>, context: &mut dyn Context,
42    ) -> ExecTrapResult<GasLeft>;
43}
44
45/// Resume call interface
46pub trait ResumeCall: Send {
47    /// Resume an execution for call, returns back the Vm interface.
48    fn resume_call(self: Box<Self>, result: MessageCallResult)
49        -> Box<dyn Exec>;
50}
51
52/// Resume create interface
53pub trait ResumeCreate: Send {
54    /// Resume an execution from create, returns back the Vm interface.
55    fn resume_create(
56        self: Box<Self>, result: ContractCreateResult,
57    ) -> Box<dyn Exec>;
58}