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        contract_address, BlockHashSource, Context, ContractCreateResult,
23        CreateContractAddress, MessageCallResult,
24    },
25    env::Env,
26    error::{
27        separate_out_db_error, Error, ExecTrapError, ExecTrapResult, Result,
28        TrapError, TrapKind, TrapResult,
29    },
30    instruction_result::InstructionResult,
31    interpreter_info::InterpreterInfo,
32    return_data::{GasLeft, ReturnData},
33    spec::{
34        extract_7702_payload, CIP645Spec, ConsensusGasSpec, Spec,
35        CODE_PREFIX_7702,
36    },
37};
38
39/// Virtual Machine interface
40pub trait Exec: Send {
41    /// This function should be used to execute transaction.
42    /// It returns either an error, a known amount of gas left, or parameters
43    /// to be used to compute the final gas left.
44    fn exec(
45        self: Box<Self>, context: &mut dyn Context,
46    ) -> ExecTrapResult<GasLeft>;
47}
48
49/// Resume call interface
50pub trait ResumeCall: Send {
51    /// Resume an execution for call, returns back the Vm interface.
52    fn resume_call(self: Box<Self>, result: MessageCallResult)
53        -> Box<dyn Exec>;
54}
55
56/// Resume create interface
57pub trait ResumeCreate: Send {
58    /// Resume an execution from create, returns back the Vm interface.
59    fn resume_create(
60        self: Box<Self>, result: ContractCreateResult,
61    ) -> Box<dyn Exec>;
62}