Merge branch 'tx_queue_integration' into tx_queue_rpc

This commit is contained in:
Tomasz Drwięga
2016-03-04 12:34:34 +01:00
66 changed files with 1379 additions and 710 deletions

View File

@@ -9,12 +9,14 @@ build = "build.rs"
[lib]
[dependencies]
log = "0.3"
serde = "0.7.0"
serde_json = "0.7.0"
jsonrpc-core = "1.2"
jsonrpc-http-server = "2.1"
ethcore-util = { path = "../util" }
ethcore = { path = "../ethcore" }
ethash = { path = "../ethash" }
ethsync = { path = "../sync" }
clippy = { version = "0.0.44", optional = true }
rustc-serialize = "0.3"

View File

@@ -15,14 +15,17 @@
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
//! Eth rpc implementation.
use std::sync::{Arc, Weak};
use ethsync::{EthSync, SyncState};
use jsonrpc_core::*;
use util::hash::*;
use util::uint::*;
use util::numbers::*;
use util::sha3::*;
use util::standard::{RwLock, HashMap, Arc, Weak};
use util::rlp::encode;
use ethcore::client::*;
use ethcore::block::{IsBlock};
use ethcore::views::*;
//#[macro_use] extern crate log;
use ethcore::ethereum::Ethash;
use ethcore::ethereum::denominations::shannon;
use v1::traits::{Eth, EthFilter};
use v1::types::{Block, BlockTransactions, BlockNumber, Bytes, SyncStatus, SyncInfo, Transaction, OptionalValue, Index, Filter, Log};
@@ -30,7 +33,8 @@ use v1::types::{Block, BlockTransactions, BlockNumber, Bytes, SyncStatus, SyncIn
/// Eth rpc implementation.
pub struct EthClient {
client: Weak<Client>,
sync: Weak<EthSync>
sync: Weak<EthSync>,
hashrates: RwLock<HashMap<H256, u64>>,
}
impl EthClient {
@@ -38,7 +42,8 @@ impl EthClient {
pub fn new(client: &Arc<Client>, sync: &Arc<EthSync>) -> Self {
EthClient {
client: Arc::downgrade(client),
sync: Arc::downgrade(sync)
sync: Arc::downgrade(sync),
hashrates: RwLock::new(HashMap::new()),
}
}
@@ -125,7 +130,7 @@ impl Eth for EthClient {
// TODO: return real value of mining once it's implemented.
fn is_mining(&self, params: Params) -> Result<Value, Error> {
match params {
Params::None => Ok(Value::Bool(false)),
Params::None => to_value(&!self.hashrates.read().unwrap().is_empty()),
_ => Err(Error::invalid_params())
}
}
@@ -133,7 +138,7 @@ impl Eth for EthClient {
// TODO: return real hashrate once we have mining
fn hashrate(&self, params: Params) -> Result<Value, Error> {
match params {
Params::None => to_value(&U256::zero()),
Params::None => to_value(&self.hashrates.read().unwrap().iter().fold(0u64, |sum, (_, v)| sum + v)),
_ => Err(Error::invalid_params())
}
}
@@ -220,6 +225,43 @@ impl Eth for EthClient {
to_value(&logs)
})
}
fn work(&self, params: Params) -> Result<Value, Error> {
match params {
Params::None => {
let c = take_weak!(self.client);
let u = c.sealing_block().lock().unwrap();
match *u {
Some(ref b) => {
let pow_hash = b.hash();
let target = Ethash::difficulty_to_boundary(b.block().header().difficulty());
let seed_hash = Ethash::get_seedhash(b.block().header().number());
to_value(&(pow_hash, seed_hash, target))
}
_ => Err(Error::invalid_params())
}
},
_ => Err(Error::invalid_params())
}
}
fn submit_work(&self, params: Params) -> Result<Value, Error> {
from_params::<(H64, H256, H256)>(params).and_then(|(nonce, pow_hash, mix_hash)| {
// trace!("Decoded: nonce={}, pow_hash={}, mix_hash={}", nonce, pow_hash, mix_hash);
let c = take_weak!(self.client);
let seal = vec![encode(&mix_hash).to_vec(), encode(&nonce).to_vec()];
let r = c.submit_seal(pow_hash, seal);
to_value(&r.is_ok())
})
}
fn submit_hashrate(&self, params: Params) -> Result<Value, Error> {
// TODO: Index should be U256.
from_params::<(Index, H256)>(params).and_then(|(rate, id)| {
self.hashrates.write().unwrap().insert(id, rate.value() as u64);
to_value(&true)
})
}
}
/// Eth filter rpc implementation.

View File

@@ -31,7 +31,7 @@ impl Web3 for Web3Client {
fn client_version(&self, params: Params) -> Result<Value, Error> {
match params {
Params::None => {
Ok(Value::String(version())),
Ok(Value::String(version().to_owned().replace("Parity/", "Parity//"))),
}
_ => Err(Error::invalid_params())
}

View File

@@ -15,8 +15,7 @@
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
use serde::{Serialize, Serializer};
use util::hash::*;
use util::uint::*;
use util::numbers::*;
use v1::types::{Bytes, Transaction, OptionalValue};
#[derive(Debug)]
@@ -71,8 +70,7 @@ pub struct Block {
#[cfg(test)]
mod tests {
use serde_json;
use util::hash::*;
use util::uint::*;
use util::numbers::*;
use v1::types::{Transaction, Bytes, OptionalValue};
use super::*;

View File

@@ -17,7 +17,7 @@
use serde::{Deserialize, Deserializer, Error};
use serde_json::value;
use jsonrpc_core::Value;
use util::hash::*;
use util::numbers::*;
use v1::types::BlockNumber;
use ethcore::filter::Filter as EthFilter;
use ethcore::client::BlockId;

View File

@@ -14,8 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
use util::hash::*;
use util::uint::*;
use util::numbers::*;
use ethcore::log_entry::LocalizedLogEntry;
use v1::types::Bytes;
@@ -55,8 +54,7 @@ impl From<LocalizedLogEntry> for Log {
mod tests {
use serde_json;
use std::str::FromStr;
use util::hash::*;
use util::uint::*;
use util::numbers::*;
use v1::types::{Bytes, Log};
#[test]
@@ -66,7 +64,7 @@ mod tests {
let log = Log {
address: Address::from_str("33990122638b9132ca29c723bdf037f1a891a70c").unwrap(),
topics: vec![
H256::from_str("a6697e974e6a320f454390be03f74955e8978f1a6971ea6730542e37b66179bc").unwrap(),
H256::from_str("a6697e974e6a320f454390be03f74955e8978f1a6971ea6730542e37b66179bc").unwrap(),
H256::from_str("4861736852656700000000000000000000000000000000000000000000000000").unwrap()
],
data: Bytes::new(vec![]),

View File

@@ -15,7 +15,7 @@
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
use serde::{Serialize, Serializer};
use util::uint::*;
use util::numbers::*;
#[derive(Default, Debug, Serialize, PartialEq)]
pub struct SyncInfo {

View File

@@ -14,8 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
use util::hash::*;
use util::uint::*;
use util::numbers::*;
use ethcore::transaction::{LocalizedTransaction, Action};
use v1::types::{Bytes, OptionalValue};