2016-02-05 13:40:41 +01:00
|
|
|
// Copyright 2015, 2016 Ethcore (UK) Ltd.
|
|
|
|
// This file is part of Parity.
|
|
|
|
|
|
|
|
// Parity is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
|
|
|
// Parity is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2016-01-09 21:39:38 +01:00
|
|
|
//! Interface for Evm externalities.
|
2015-12-30 12:46:10 +01:00
|
|
|
|
2016-02-29 22:21:15 +01:00
|
|
|
use util::common::*;
|
2016-01-11 22:32:01 +01:00
|
|
|
use evm::{Schedule, Error};
|
|
|
|
use env_info::*;
|
2016-01-06 13:00:14 +01:00
|
|
|
|
2016-01-16 20:11:12 +01:00
|
|
|
/// Result of externalities create function.
|
|
|
|
pub enum ContractCreateResult {
|
|
|
|
/// Returned when creation was successfull.
|
|
|
|
/// Contains an address of newly created contract and gas left.
|
|
|
|
Created(Address, U256),
|
|
|
|
/// Returned when contract creation failed.
|
|
|
|
/// VM doesn't have to know the reason.
|
|
|
|
Failed
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Result of externalities call function.
|
|
|
|
pub enum MessageCallResult {
|
|
|
|
/// Returned when message call was successfull.
|
|
|
|
/// Contains gas left.
|
|
|
|
Success(U256),
|
|
|
|
/// Returned when message call failed.
|
|
|
|
/// VM doesn't have to know the reason.
|
|
|
|
Failed
|
|
|
|
}
|
|
|
|
|
2016-01-20 16:52:22 +01:00
|
|
|
/// Externalities interface for EVMs
|
2016-01-09 00:51:09 +01:00
|
|
|
pub trait Ext {
|
2016-01-07 23:33:54 +01:00
|
|
|
/// Returns a value for given key.
|
2016-01-15 18:56:28 +01:00
|
|
|
fn storage_at(&self, key: &H256) -> H256;
|
2016-01-07 23:33:54 +01:00
|
|
|
|
|
|
|
/// Stores a value for given key.
|
2016-01-16 20:11:12 +01:00
|
|
|
fn set_storage(&mut self, key: H256, value: H256);
|
|
|
|
|
|
|
|
/// Determine whether an account exists.
|
|
|
|
fn exists(&self, address: &Address) -> bool;
|
2016-01-07 23:33:54 +01:00
|
|
|
|
|
|
|
/// Returns address balance.
|
|
|
|
fn balance(&self, address: &Address) -> U256;
|
|
|
|
|
|
|
|
/// Returns the hash of one of the 256 most recent complete blocks.
|
|
|
|
fn blockhash(&self, number: &U256) -> H256;
|
|
|
|
|
|
|
|
/// Creates new contract.
|
2016-02-29 22:21:15 +01:00
|
|
|
///
|
2016-01-14 21:21:46 +01:00
|
|
|
/// Returns gas_left and contract address if contract creation was succesfull.
|
2016-01-16 20:11:12 +01:00
|
|
|
fn create(&mut self, gas: &U256, value: &U256, code: &[u8]) -> ContractCreateResult;
|
2016-01-09 23:24:01 +01:00
|
|
|
|
|
|
|
/// Message call.
|
2016-02-29 22:21:15 +01:00
|
|
|
///
|
2016-01-14 21:21:46 +01:00
|
|
|
/// Returns Err, if we run out of gas.
|
2016-02-29 22:21:15 +01:00
|
|
|
/// Otherwise returns call_result which contains gas left
|
2016-01-14 19:52:40 +01:00
|
|
|
/// and true if subcall was successfull.
|
2016-03-18 10:14:19 +01:00
|
|
|
#[cfg_attr(feature="dev", allow(too_many_arguments))]
|
2016-02-29 22:21:15 +01:00
|
|
|
fn call(&mut self,
|
|
|
|
gas: &U256,
|
|
|
|
sender_address: &Address,
|
|
|
|
receive_address: &Address,
|
2016-01-25 23:59:50 +01:00
|
|
|
value: Option<U256>,
|
2016-02-29 22:21:15 +01:00
|
|
|
data: &[u8],
|
|
|
|
code_address: &Address,
|
2016-01-16 20:11:12 +01:00
|
|
|
output: &mut [u8]) -> MessageCallResult;
|
2016-01-07 23:33:54 +01:00
|
|
|
|
|
|
|
/// Returns code at given address
|
2016-01-16 17:17:43 +01:00
|
|
|
fn extcode(&self, address: &Address) -> Bytes;
|
2016-01-07 23:33:54 +01:00
|
|
|
|
|
|
|
/// Creates log entry with given topics and data
|
2016-01-16 17:17:43 +01:00
|
|
|
fn log(&mut self, topics: Vec<H256>, data: &[u8]);
|
2016-01-11 02:17:29 +01:00
|
|
|
|
|
|
|
/// Should be called when transaction calls `RETURN` opcode.
|
|
|
|
/// Returns gas_left if cost of returning the data is not too high.
|
2016-01-13 22:16:24 +01:00
|
|
|
fn ret(&mut self, gas: &U256, data: &[u8]) -> Result<U256, Error>;
|
2016-01-11 02:17:29 +01:00
|
|
|
|
|
|
|
/// Should be called when contract commits suicide.
|
2016-01-13 16:16:21 +01:00
|
|
|
/// Address to which funds should be refunded.
|
|
|
|
fn suicide(&mut self, refund_address: &Address);
|
2016-01-11 02:17:29 +01:00
|
|
|
|
|
|
|
/// Returns schedule.
|
2016-01-11 16:28:30 +01:00
|
|
|
fn schedule(&self) -> &Schedule;
|
2016-01-11 22:32:01 +01:00
|
|
|
|
|
|
|
/// Returns environment info.
|
|
|
|
fn env_info(&self) -> &EnvInfo;
|
2016-01-16 20:11:12 +01:00
|
|
|
|
|
|
|
/// Returns current depth of execution.
|
2016-02-29 22:21:15 +01:00
|
|
|
///
|
2016-01-16 20:11:12 +01:00
|
|
|
/// If contract A calls contract B, and contract B calls C,
|
|
|
|
/// then A depth is 0, B is 1, C is 2 and so on.
|
|
|
|
fn depth(&self) -> usize;
|
|
|
|
|
|
|
|
/// Increments sstore refunds count by 1.
|
|
|
|
fn inc_sstore_clears(&mut self);
|
2016-01-07 23:33:54 +01:00
|
|
|
}
|