mep_vm/lib.rs
1// Copyright 2015-2020 Parity Technologies (UK) Ltd.
2// This file is part of Parity Ethereum.
3
4// Parity Ethereum is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8
9// Parity Ethereum is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License
15// along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>.
16
17//! Virtual machines support library
18
19extern crate ethereum_types;
20extern crate parity_bytes as bytes;
21extern crate ethjson;
22extern crate rlp;
23extern crate keccak_hash as hash;
24extern crate patricia_trie_ethereum as ethtrie;
25
26mod action_params;
27mod action_type;
28mod env_info;
29mod schedule;
30mod ext;
31mod return_data;
32mod error;
33
34pub mod tests;
35
36pub use action_params::{ActionParams, ActionValue, ParamsType};
37pub use action_type::ActionType;
38pub use env_info::{EnvInfo, LastHashes};
39pub use schedule::{Schedule, VersionedSchedule, CleanDustMode, WasmCosts};
40pub use ext::{Ext, MessageCallResult, ContractCreateResult, CreateContractAddress};
41pub use return_data::{ReturnData, GasLeft};
42pub use error::{Error, Result, TrapResult, TrapError, TrapKind, ExecTrapResult, ExecTrapError};
43
44/// Virtual Machine interface
45pub trait Exec: Send {
46 /// This function should be used to execute transaction.
47 /// It returns either an error, a known amount of gas left, or parameters to be used
48 /// to compute the final gas left.
49 fn exec(self: Box<Self>, ext: &mut dyn Ext) -> ExecTrapResult<GasLeft>;
50}
51
52/// Resume call interface
53pub trait ResumeCall: Send {
54 /// Resume an execution for call, returns back the Vm interface.
55 fn resume_call(self: Box<Self>, result: MessageCallResult) -> Box<dyn Exec>;
56}
57
58/// Resume create interface
59pub trait ResumeCreate: Send {
60 /// Resume an execution from create, returns back the Vm interface.
61 fn resume_create(self: Box<Self>, result: ContractCreateResult) -> Box<dyn Exec>;
62}