From 74368663dbab468c6d4efc4a94ecbdac25e39040 Mon Sep 17 00:00:00 2001 From: debris Date: Wed, 9 Dec 2015 15:31:43 +0100 Subject: [PATCH] denominations and networkparams --- src/denominations.rs | 17 +++++++++++ src/lib.rs | 2 ++ src/networkparams.rs | 71 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 90 insertions(+) create mode 100644 src/denominations.rs create mode 100644 src/networkparams.rs diff --git a/src/denominations.rs b/src/denominations.rs new file mode 100644 index 000000000..183e89f26 --- /dev/null +++ b/src/denominations.rs @@ -0,0 +1,17 @@ +use util::uint::*; + +#[inline] +pub fn ether() -> U256 { U256::exp10(18) } + +#[inline] +pub fn finney() -> U256 { U256::exp10(15) } + +#[inline] +pub fn szabo() -> U256 { U256::exp10(12) } + +#[inline] +pub fn shannon() -> U256 { U256::exp10(9) } + +#[inline] +pub fn wei() -> U256 { U256::exp10(0) } + diff --git a/src/lib.rs b/src/lib.rs index 8037140df..ce40bc439 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -78,6 +78,8 @@ extern crate evmjit; pub mod blockheader; pub mod transaction; +pub mod networkparams; +pub mod denominations; #[test] fn it_works() { diff --git a/src/networkparams.rs b/src/networkparams.rs new file mode 100644 index 000000000..aedadf701 --- /dev/null +++ b/src/networkparams.rs @@ -0,0 +1,71 @@ +use util::uint::*; +use denominations::*; + +/// Network related const params +/// TODO: make it configurable from json file +pub struct NetworkParams { + maximum_extra_data_size: U256, + min_gas_limit: U256, + gas_limit_bounds_divisor: U256, + minimum_difficulty: U256, + difficulty_bound_divisor: U256, + duration_limit: U256, + block_reward: U256, + gas_floor_target: U256, + account_start_nonce: U256 +} + +impl NetworkParams { + pub fn olympic() -> NetworkParams { + NetworkParams { + maximum_extra_data_size: U256::from(1024u64), + min_gas_limit: U256::from(125_000u64), + gas_floor_target: U256::from(3_141_592u64), + gas_limit_bounds_divisor: U256::from(1024u64), + minimum_difficulty: U256::from(131_072u64), + difficulty_bound_divisor: U256::from(2048u64), + duration_limit: U256::from(8u64), + block_reward: finney() * U256::from(1500u64), + account_start_nonce: U256::from(0u64) + } + } + + pub fn frontier() -> NetworkParams { + NetworkParams { + maximum_extra_data_size: U256::from(32u64), + min_gas_limit: U256::from(5000u64), + gas_floor_target: U256::from(3_141_592u64), + gas_limit_bounds_divisor: U256::from(1024u64), + minimum_difficulty: U256::from(131_072u64), + difficulty_bound_divisor: U256::from(2048u64), + duration_limit: U256::from(13u64), + block_reward: ether() * U256::from(5u64), + account_start_nonce: U256::from(0u64) + } + } + + pub fn morden() -> NetworkParams { + NetworkParams { + maximum_extra_data_size: U256::from(32u64), + min_gas_limit: U256::from(5000u64), + gas_floor_target: U256::from(3_141_592u64), + gas_limit_bounds_divisor: U256::from(1024u64), + minimum_difficulty: U256::from(131_072u64), + difficulty_bound_divisor: U256::from(2048u64), + duration_limit: U256::from(13u64), + block_reward: ether() * U256::from(5u64), + account_start_nonce: U256::from(1u64) << 20 + } + } + + pub fn maximum_extra_data_size(&self) -> U256 { self.maximum_extra_data_size } + pub fn min_gas_limit(&self) -> U256 { self.min_gas_limit } + pub fn gas_limit_bounds_divisor(&self) -> U256 { self.gas_limit_bounds_divisor } + pub fn minimum_difficulty(&self) -> U256 { self.minimum_difficulty } + pub fn difficulty_bound_divisor(&self) -> U256 { self.difficulty_bound_divisor } + pub fn duration_limit(&self) -> U256 { self.duration_limit } + pub fn block_reward(&self) -> U256 { self.block_reward } + pub fn gas_floor_target(&self) -> U256 { self.gas_floor_target } + pub fn account_start_nonce(&self) -> U256 { self.account_start_nonce } +} +