2016-01-09 21:39:38 +01:00
|
|
|
//! Interface for Evm externalities.
|
2015-12-30 12:46:10 +01:00
|
|
|
|
2015-12-23 13:02:01 +01:00
|
|
|
use util::hash::*;
|
2015-12-29 12:04:03 +01:00
|
|
|
use util::uint::*;
|
2016-01-06 13:00:14 +01:00
|
|
|
use util::bytes::*;
|
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-14 19:52:40 +01:00
|
|
|
pub struct CallResult {
|
|
|
|
pub gas_left: U256,
|
|
|
|
pub success: bool
|
|
|
|
}
|
|
|
|
|
|
|
|
impl CallResult {
|
|
|
|
pub fn new(gas_left: U256, success: bool) -> Self {
|
|
|
|
CallResult {
|
|
|
|
gas_left: gas_left,
|
|
|
|
success: success
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
fn sload(&self, key: &H256) -> H256;
|
|
|
|
|
|
|
|
/// Stores a value for given key.
|
|
|
|
fn sstore(&mut self, key: H256, value: H256);
|
|
|
|
|
|
|
|
/// 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-01-11 14:08:03 +01:00
|
|
|
///
|
2016-01-14 17:40:38 +01:00
|
|
|
/// Return gas_left and contract address if contract creation was succesfull.
|
|
|
|
fn create(&mut self, gas: &U256, value: &U256, code: &[u8]) -> (U256, Option<Address>);
|
2016-01-09 23:24:01 +01:00
|
|
|
|
|
|
|
/// Message call.
|
2016-01-11 14:08:03 +01:00
|
|
|
///
|
2016-01-14 19:52:40 +01:00
|
|
|
/// Returns None, if we run out of gas.
|
|
|
|
/// Otherwise returns call_result which contains gas left
|
|
|
|
/// and true if subcall was successfull.
|
2016-01-11 14:08:03 +01:00
|
|
|
fn call(&mut self,
|
2016-01-13 22:36:59 +01:00
|
|
|
gas: &U256,
|
|
|
|
call_gas: &U256,
|
2016-01-11 14:08:03 +01:00
|
|
|
receive_address: &Address,
|
|
|
|
value: &U256,
|
|
|
|
data: &[u8],
|
|
|
|
code_address: &Address,
|
2016-01-14 19:52:40 +01:00
|
|
|
output: &mut [u8]) -> Option<CallResult>;
|
2016-01-07 23:33:54 +01:00
|
|
|
|
|
|
|
/// Returns code at given address
|
|
|
|
fn extcode(&self, address: &Address) -> Vec<u8>;
|
|
|
|
|
|
|
|
/// Creates log entry with given topics and data
|
|
|
|
fn log(&mut self, topics: Vec<H256>, data: Bytes);
|
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-07 23:33:54 +01:00
|
|
|
}
|