diff --git a/Cargo.lock b/Cargo.lock index 9c225dbbe..b8a92fc3d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -209,6 +209,7 @@ dependencies = [ "ethsync 0.9.99", "jsonrpc-core 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "jsonrpc-http-server 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.18 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde_codegen 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/ethcore/src/ethereum/ethash.rs b/ethcore/src/ethereum/ethash.rs index d26a7e2af..6dabe558f 100644 --- a/ethcore/src/ethereum/ethash.rs +++ b/ethcore/src/ethereum/ethash.rs @@ -249,6 +249,11 @@ impl Ethash { x!(U256::from((U512::one() << 256) / x!(difficulty))) } + /// Given the `block_number`, determine the seed hash for Ethash. + pub fn get_seedhash(number: BlockNumber) -> H256 { + Self::from_ethash(ethash::get_seedhash(number)) + } + fn to_ethash(hash: H256) -> EH256 { unsafe { mem::transmute(hash) } } @@ -259,12 +264,17 @@ impl Ethash { } impl Header { + /// Get the none field of the header. pub fn nonce(&self) -> H64 { decode(&self.seal()[1]) } + + /// Get the mix hash field of the header. pub fn mix_hash(&self) -> H256 { decode(&self.seal()[0]) } + + /// Set the nonce and mix hash fields of the header. pub fn set_nonce_and_mix_hash(&mut self, nonce: &H64, mix_hash: &H256) { self.seal = vec![encode(mix_hash).to_vec(), encode(nonce).to_vec()]; } diff --git a/rpc/Cargo.toml b/rpc/Cargo.toml index c38684643..086fb19c1 100644 --- a/rpc/Cargo.toml +++ b/rpc/Cargo.toml @@ -9,6 +9,7 @@ build = "build.rs" [lib] [dependencies] +log = "0.3" serde = "0.7.0" serde_json = "0.7.0" jsonrpc-core = "1.2" diff --git a/rpc/src/v1/impls/eth.rs b/rpc/src/v1/impls/eth.rs index 1b5c4739c..b26f38440 100644 --- a/rpc/src/v1/impls/eth.rs +++ b/rpc/src/v1/impls/eth.rs @@ -25,8 +25,7 @@ use util::rlp::encode; use ethcore::client::*; use ethcore::block::{IsBlock}; use ethcore::views::*; -extern crate ethash; -use self::ethash::get_seedhash; +//#[macro_use] extern crate log; use ethcore::ethereum::Ethash; use ethcore::ethereum::denominations::shannon; use v1::traits::{Eth, EthFilter}; @@ -216,6 +215,7 @@ impl Eth for EthClient { } fn work(&self, params: Params) -> Result { + println!("Work wanted: {:?}", params); match params { Params::None => { let c = take_weak!(self.client); @@ -224,7 +224,7 @@ impl Eth for EthClient { Some(ref b) => { let pow_hash = b.hash(); let target = Ethash::difficulty_to_boundary(b.block().header().difficulty()); - let seed_hash = get_seedhash(b.block().header().number()); + let seed_hash = Ethash::get_seedhash(b.block().header().number()); to_value(&(pow_hash, seed_hash, target)) } _ => Err(Error::invalid_params()) @@ -235,6 +235,7 @@ impl Eth for EthClient { } fn submit_work(&self, params: Params) -> Result { + println!("Work submission: {:?}", params); from_params::<(H64, H256, H256)>(params).and_then(|(nonce, pow_hash, mix_hash)| { let c = take_weak!(self.client); let seal = vec![encode(&mix_hash).to_vec(), encode(&nonce).to_vec()]; @@ -242,7 +243,13 @@ impl Eth for EthClient { }) } -// fn submit_hashrate(&self, _: Params) -> Result { rpc_unimplemented!() } + fn submit_hashrate(&self, params: Params) -> Result { + println!("Hashrate submission: {:?}", params); + from_params::<(Index, H256)>(params).and_then(|(rate, id)| { + println!("Miner {} reports a hash rate of {} H/s", id, rate.value()); + to_value(&true) + }) + } } /// Eth filter rpc implementation.