Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Merge pull request #845 from ethcore/beta-staging
Browse files Browse the repository at this point in the history
Merge fixes from master to beta
  • Loading branch information
gavofyork committed Mar 28, 2016
2 parents dad4bfe + 20f3f35 commit fe31367
Show file tree
Hide file tree
Showing 16 changed files with 176 additions and 39 deletions.
36 changes: 18 additions & 18 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
description = "Ethcore client."
name = "parity"
version = "1.0.0"
version = "1.0.1"
license = "GPL-3.0"
authors = ["Ethcore <admin@ethcore.io>"]
build = "build.rs"
Expand Down
2 changes: 1 addition & 1 deletion ethcore/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description = "Ethcore library"
homepage = "http://ethcore.io"
license = "GPL-3.0"
name = "ethcore"
version = "1.0.0"
version = "1.0.1"
authors = ["Ethcore <admin@ethcore.io>"]

[dependencies]
Expand Down
3 changes: 3 additions & 0 deletions miner/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ pub trait MinerService : Send + Sync {
/// Submit `seal` as a valid solution for the header of `pow_hash`.
/// Will check the seal, but not actually insert the block into the chain.
fn submit_seal(&self, chain: &BlockChainClient, pow_hash: H256, seal: Vec<Bytes>) -> Result<(), Error>;

/// Query pending transactions for hash
fn transaction(&self, hash: &H256) -> Option<SignedTransaction>;
}

/// Mining status
Expand Down
5 changes: 5 additions & 0 deletions miner/src/miner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,11 @@ impl MinerService for Miner {
transaction_queue.pending_hashes()
}

fn transaction(&self, hash: &H256) -> Option<SignedTransaction> {
let queue = self.transaction_queue.lock().unwrap();
queue.find(hash)
}

fn update_sealing(&self, chain: &BlockChainClient) {
if self.sealing_enabled.load(atomic::Ordering::Relaxed) {
let current_no = chain.chain_info().best_block_number;
Expand Down
5 changes: 5 additions & 0 deletions miner/src/transaction_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,11 @@ impl TransactionQueue {
.collect()
}

/// Finds transaction in the queue by hash (if any)
pub fn find(&self, hash: &H256) -> Option<SignedTransaction> {
match self.by_hash.get(hash) { Some(transaction_ref) => Some(transaction_ref.transaction.clone()), None => None }
}

/// Removes all elements (in any state) from the queue
pub fn clear(&mut self) {
self.current.clear();
Expand Down
37 changes: 34 additions & 3 deletions parity/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ extern crate rpassword;
#[cfg(feature = "rpc")]
extern crate ethcore_rpc as rpc;

use std::io::{BufRead, BufReader};
use std::fs::File;
use std::net::{SocketAddr, IpAddr};
use std::env;
use std::process::exit;
Expand Down Expand Up @@ -89,6 +91,11 @@ Protocol Options:
[default: $HOME/.web3/keys].
--identity NAME Specify your node's name.
Account Options:
--unlock ACCOUNT Unlock ACCOUNT for the duration of the execution.
--password FILE Provide a file containing a password for unlocking
an account.
Networking Options:
--port PORT Override the port on which the node should listen
[default: 30303].
Expand Down Expand Up @@ -176,6 +183,8 @@ struct Args {
flag_chain: String,
flag_db_path: String,
flag_identity: String,
flag_unlock: Vec<String>,
flag_password: Vec<String>,
flag_cache: Option<usize>,
flag_keys_path: String,
flag_bootnodes: Option<String>,
Expand Down Expand Up @@ -490,6 +499,28 @@ impl Configuration {
}
}

fn account_service(&self) -> AccountService {
// Secret Store
let passwords = self.args.flag_password.iter().flat_map(|filename| {
BufReader::new(&File::open(filename).unwrap_or_else(|_| die!("{} Unable to read password file. Ensure it exists and permissions are correct.", filename)))
.lines()
.map(|l| l.unwrap())
.collect::<Vec<_>>()
.into_iter()
}).collect::<Vec<_>>();

let account_service = AccountService::new();
for d in &self.args.flag_unlock {
let a = Address::from_str(clean_0x(&d)).unwrap_or_else(|_| {
die!("{}: Invalid address for --unlock. Must be 40 hex characters, without the 0x at the beginning.", d)
});
if passwords.iter().find(|p| account_service.unlock_account_no_expire(&a, p).is_ok()).is_none() {
die!("No password given to unlock account {}. Pass the password using `--password`.", a);
}
}
account_service
}

#[cfg_attr(feature="dev", allow(useless_format))]
fn execute_client(&self) {
// Setup panic handler
Expand All @@ -504,6 +535,9 @@ impl Configuration {
let net_settings = self.net_settings(&spec);
let sync_config = self.sync_config(&spec);

// Secret Store
let account_service = Arc::new(self.account_service());

// Build client
let mut service = ClientService::start(self.client_config(), spec, net_settings, &Path::new(&self.path())).unwrap();
panic_handler.forward_from(&service);
Expand All @@ -519,9 +553,6 @@ impl Configuration {
// Sync
let sync = EthSync::register(service.network(), sync_config, client.clone(), miner.clone());

// Secret Store
let account_service = Arc::new(AccountService::new());

// Setup rpc
if self.args.flag_jsonrpc || self.args.flag_rpc {
let url = format!("{}:{}",
Expand Down
2 changes: 1 addition & 1 deletion rpc/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
description = "Ethcore jsonrpc"
name = "ethcore-rpc"
version = "1.0.0"
version = "1.0.1"
license = "GPL-3.0"
authors = ["Ethcore <admin@ethcore.io"]
build = "build.rs"
Expand Down
16 changes: 11 additions & 5 deletions rpc/src/v1/impls/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,13 @@ impl<C, S, A, M, EM> Eth for EthClient<C, S, A, M, EM>

fn transaction_by_hash(&self, params: Params) -> Result<Value, Error> {
from_params::<(H256,)>(params)
.and_then(|(hash,)| self.transaction(TransactionId::Hash(hash)))
.and_then(|(hash,)| {
let miner = take_weak!(self.miner);
match miner.transaction(&hash) {
Some(pending_tx) => to_value(&Transaction::from(pending_tx)),
None => self.transaction(TransactionId::Hash(hash))
}
})
}

fn transaction_by_block_hash_and_index(&self, params: Params) -> Result<Value, Error> {
Expand Down Expand Up @@ -476,11 +482,11 @@ impl<C, S, A, M, EM> Eth for EthClient<C, S, A, M, EM>
Ok(_) => to_value(&hash),
Err(e) => {
warn!("Error sending transaction: {:?}", e);
to_value(&U256::zero())
to_value(&H256::zero())
}
}
},
Err(_) => { to_value(&U256::zero()) }
Err(_) => { to_value(&H256::zero()) }
}
})
}
Expand All @@ -503,11 +509,11 @@ impl<C, S, A, M, EM> Eth for EthClient<C, S, A, M, EM>
Ok(_) => to_value(&hash),
Err(e) => {
warn!("Error sending transaction: {:?}", e);
to_value(&U256::zero())
to_value(&H256::zero())
}
}
},
Err(_) => { to_value(&U256::zero()) }
Err(_) => { to_value(&H256::zero()) }
}
})
}
Expand Down
25 changes: 23 additions & 2 deletions rpc/src/v1/tests/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ struct EthTester {
pub client: Arc<TestBlockChainClient>,
pub sync: Arc<TestSyncProvider>,
_accounts_provider: Arc<TestAccountProvider>,
_miner: Arc<TestMinerService>,
miner: Arc<TestMinerService>,
hashrates: Arc<RwLock<HashMap<H256, U256>>>,
pub io: IoHandler,
}
Expand All @@ -73,7 +73,7 @@ impl Default for EthTester {
client: client,
sync: sync,
_accounts_provider: ap,
_miner: miner,
miner: miner,
io: io,
hashrates: hashrates,
}
Expand Down Expand Up @@ -258,6 +258,27 @@ fn rpc_eth_transaction_count_by_number_pending() {
assert_eq!(EthTester::default().io.handle_request(request), Some(response.to_owned()));
}

#[test]
fn rpc_eth_pending_transaction_by_hash() {
use util::*;
use ethcore::transaction::*;

let tester = EthTester::default();
{
let tx: SignedTransaction = decode(&FromHex::from_hex("f85f800182520894095e7baea6a6c7c4c2dfeb977efac326af552d870a801ba048b55bfa915ac795c431978d8a6a992b628d557da5ff759b307d495a36649353a0efffd310ac743f371de3b9f7f9cb56c0b28ad43601b4ab949f53faa07bd2c804").unwrap());
tester.miner.pending_transactions.lock().unwrap().insert(H256::zero(), tx);
}

let response = r#"{"jsonrpc":"2.0","result":{"blockHash":null,"blockNumber":null,"from":"0x0f65fe9276bc9a24ae7083ae28e2660ef72df99e","gas":"0x5208","gasPrice":"0x01","hash":"0x41df922fd0d4766fcc02e161f8295ec28522f329ae487f14d811e4b64c8d6e31","input":"0x","nonce":"0x00","to":"0x095e7baea6a6c7c4c2dfeb977efac326af552d87","transactionIndex":null,"value":"0x0a"},"id":1}"#;
let request = r#"{
"jsonrpc": "2.0",
"method": "eth_getTransactionByHash",
"params": ["0x0000000000000000000000000000000000000000000000000000000000000000"],
"id": 1
}"#;
assert_eq!(tester.io.handle_request(request), Some(response.to_owned()));
}


#[test]
fn rpc_eth_uncle_count_by_block_hash() {
Expand Down
7 changes: 7 additions & 0 deletions rpc/src/v1/tests/helpers/miner_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,16 @@ pub struct TestMinerService {
pub imported_transactions: RwLock<Vec<H256>>,
/// Latest closed block.
pub latest_closed_block: Mutex<Option<ClosedBlock>>,
/// Pre-existed pending transactions
pub pending_transactions: Mutex<HashMap<H256, SignedTransaction>>,
}

impl Default for TestMinerService {
fn default() -> TestMinerService {
TestMinerService {
imported_transactions: RwLock::new(Vec::new()),
latest_closed_block: Mutex::new(None),
pending_transactions: Mutex::new(HashMap::new()),
}
}
}
Expand Down Expand Up @@ -73,6 +76,10 @@ impl MinerService for TestMinerService {
&self.latest_closed_block
}

fn transaction(&self, hash: &H256) -> Option<SignedTransaction> {
self.pending_transactions.lock().unwrap().get(hash).and_then(|tx_ref| Some(tx_ref.clone()))
}

/// Submit `seal` as a valid solution for the header of `pow_hash`.
/// Will check the seal, but not actually insert the block into the chain.
fn submit_seal(&self, _chain: &BlockChainClient, _pow_hash: H256, _seal: Vec<Bytes>) -> Result<(), Error> { unimplemented!(); }
Expand Down
23 changes: 22 additions & 1 deletion rpc/src/v1/types/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// along with Parity. If not, see <http://www.gnu.org/licenses/>.

use util::numbers::*;
use ethcore::transaction::{LocalizedTransaction, Action};
use ethcore::transaction::{LocalizedTransaction, Action, SignedTransaction};
use v1::types::{Bytes, OptionalValue};

#[derive(Debug, Default, Serialize)]
Expand Down Expand Up @@ -58,6 +58,27 @@ impl From<LocalizedTransaction> for Transaction {
}
}

impl From<SignedTransaction> for Transaction {
fn from(t: SignedTransaction) -> Transaction {
Transaction {
hash: t.hash(),
nonce: t.nonce,
block_hash: OptionalValue::Null,
block_number: OptionalValue::Null,
transaction_index: OptionalValue::Null,
from: t.sender().unwrap(),
to: match t.action {
Action::Create => OptionalValue::Null,
Action::Call(ref address) => OptionalValue::Value(address.clone())
},
value: t.value,
gas_price: t.gas_price,
gas: t.gas,
input: Bytes::new(t.data.clone())
}
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down

0 comments on commit fe31367

Please sign in to comment.