Skip to content
This repository was archived by the owner on Nov 6, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ impl Account {
}

/// Create a new account with the given balance.
pub fn new_basic(balance: U256) -> Account {
pub fn new_basic(balance: U256, nonce: U256) -> Account {
Account {
balance: balance,
nonce: U256::from(0u8),
nonce: nonce,
storage_root: SHA3_NULL_RLP,
storage_overlay: RefCell::new(HashMap::new()),
code_hash: Some(SHA3_EMPTY),
Expand Down
109 changes: 109 additions & 0 deletions src/engine.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
use util::uint::*;
use util::hash::*;
use util::bytes::*;
use util::semantic_version::*;
use header::Header;
use std::collections::hash_map::*;
use util::error::*;

/// Definition of the cost schedule and other parameterisations for the EVM.
pub struct EvmSchedule {
pub exceptional_failed_code_deposit: bool,
pub have_delegate_call: bool,
pub stack_limit: U256,
pub tier_step_gas: [U256; 8],
pub exp_gas: U256,
pub exp_byte_gas: U256,
pub sha3_gas: U256,
pub sha3_word_gas: U256,
pub sload_gas: U256,
pub sstore_set_gas: U256,
pub sstore_reset_gas: U256,
pub sstore_refund_gas: U256,
pub jumpdest_gas: U256,
pub log_gas: U256,
pub log_data_gas: U256,
pub log_topic_gas: U256,
pub create_gas: U256,
pub call_gas: U256,
pub call_stipend: U256,
pub call_value_transfer_gas: U256,
pub call_new_account_gas: U256,
pub suicide_refund_gas: U256,
pub memory_gas: U256,
pub quad_coeff_div: U256,
pub create_data_gas: U256,
pub tx_gas: U256,
pub tx_create_gas: U256,
pub tx_data_zero_gas: U256,
pub tx_data_non_zero_gas: U256,
pub copy_gas: U256,
}

/// Definition of a contract whose implementation is built-in.
pub struct Builtin {
/// The gas cost of running this built-in for the given size of input data.
pub cost: Box<Fn(usize) -> U256>, // TODO: U256 should be bignum.
/// Run this built-in function with the input being the first argument and the output
/// being placed into the second.
pub execute: Box<Fn(&[u8], &mut [u8])>,
}

/// Parameters for a block chain; includes both those intrinsic to the design of the
/// chain and those to be interpreted by the active chain engine.
pub struct Params {
/*
TODO: std::unordered_map<Address, PrecompiledContract> precompiled;
*/
pub block_reward: U256,
pub maximum_extra_data_size: U256,
pub account_start_nonce: U256,
pub evm_schedule: EvmSchedule,
pub builtins: HashMap<Address, Builtin>,
pub misc: HashMap<String, String>,
}

/// A consensus mechanism for the chain. Generally either proof-of-work or proof-of-stake-based.
/// Provides hooks into each of the major parts of block import.
pub trait Engine {
/// The name of this engine.
fn name(&self) -> &str;
/// The version of this engine. Should be of the form
fn version(&self) -> SemanticVersion { SemanticVersion::new(0, 0 ,0) }

/// The number of additional header fields required for this engine.
fn seal_fields(&self) -> u32 { 0 }
/// Default values of the additional fields RLP-encoded in a raw (non-list) harness.
fn seal_rlp(&self) -> Bytes { vec![] }

/// Additional engine-specific information for the user/developer concerning `header`.
fn extra_info(&self, _header: &Header) -> HashMap<String, String> { HashMap::new() }

/// Verify that `header` is valid.
/// `parent` (the parent header) and `block` (the header's full block) may be provided for additional
/// checks. Returns either a null `Ok` or a general error detailing the problem with import.
fn verify(&self, _header: &Header, _parent: Option<&Header>, _block: Option<&[u8]>) -> Result<(), EthcoreError> { Ok(()) }
/*
virtual void verify(Strictness _s, BlockHeader const& _bi, BlockHeader const& _parent = BlockHeader(), bytesConstRef _block = bytesConstRef()) const;
/// Additional verification for transactions in blocks.
virtual void verifyTransaction(ImportRequirements::value _ir, TransactionBase const& _t, BlockHeader const& _bi) const;
/// Don't forget to call Super::populateFromParent when subclassing & overriding.
virtual void populateFromParent(BlockHeader& _bi, BlockHeader const& _parent) const;
*/

/// Get the general parameters of the chain.
fn params(&self) -> &Params;
/// Set the general parameters of the chain.
fn set_params(&mut self, p: Params);
}

/// An engine which does not provide any consensus mechanism.
pub struct NullEngine {
params: Params,
}

impl Engine for NullEngine {
fn name(&self) -> &str { "NullEngine" }
fn params(&self) -> &Params { &self.params }
fn set_params(&mut self, params: Params) { self.params = params; }
}
24 changes: 24 additions & 0 deletions src/env_info.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use util::uint::*;
use util::hash::*;

/// Simple vector of hashes, should be at most 256 items large, can be smaller if being used
/// for a block whose number is less than 257.
pub type LastHashes = Vec<H256>;

/// Information concerning the execution environment for a message-call/contract-creation.
pub struct EnvInfo {
/// The block number.
pub number: U256,
/// The block author.
pub author: Address,
/// The block timestamp.
pub timestamp: U256,
/// The block difficulty.
pub difficulty: U256,
/// The block gas limit.
pub gas_limit: U256,
/// The last 256 block hashes.
pub last_hashes: LastHashes,
/// The gas used.
pub gas_used: U256,
}
File renamed without changes.
7 changes: 6 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![feature(cell_extras)]

//! Ethcore's ethereum implementation
//!
//! ### Rust version
Expand Down Expand Up @@ -82,10 +84,13 @@ pub use util::hash::*;
pub use util::uint::*;
pub use util::bytes::*;

pub mod env_info;
pub mod engine;
pub mod state;
pub mod account;
pub mod blockheader;
pub mod header;
pub mod transaction;
pub mod receipt;
pub mod networkparams;
pub mod denominations;

Expand Down
6 changes: 6 additions & 0 deletions src/receipt.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
use util::hash::*;

pub struct Receipt {
// TODO
pub state_root: H256,
}
Loading