Switch out .X().unwrap() for .unwrapped_X

This commit is contained in:
Gav Wood
2016-07-07 09:37:31 +02:00
parent 456ad9e21b
commit 3b662c285f
31 changed files with 335 additions and 311 deletions

View File

@@ -19,7 +19,7 @@ use std::time::{Instant, Duration};
use std::sync::{mpsc, Mutex, RwLock, Arc};
use std::collections::HashMap;
use jsonrpc_core;
use util::{U256, Lockable};
use util::{U256, Lockable, RwLockable};
use v1::helpers::{TransactionRequest, TransactionConfirmation};
/// Result that can be returned from JSON RPC.
@@ -214,7 +214,7 @@ impl ConfirmationsQueue {
/// Removes transaction from this queue and notifies `ConfirmationPromise` holders about the result.
/// Notifies also a receiver about that event.
fn remove(&self, id: U256, result: Option<RpcResult>) -> Option<TransactionConfirmation> {
let token = self.queue.write().unwrap().remove(&id);
let token = self.queue.unwrapped_write().remove(&id);
if let Some(token) = token {
// notify receiver about the event
@@ -247,7 +247,7 @@ impl SigningQueue for ConfirmationsQueue {
};
// Add request to queue
let res = {
let mut queue = self.queue.write().unwrap();
let mut queue = self.queue.unwrapped_write();
queue.insert(id, ConfirmationToken {
result: Arc::new(Mutex::new(ConfirmationResult::Waiting)),
handle: thread::current(),
@@ -266,7 +266,7 @@ impl SigningQueue for ConfirmationsQueue {
}
fn peek(&self, id: &U256) -> Option<TransactionConfirmation> {
self.queue.read().unwrap().get(id).map(|token| token.request.clone())
self.queue.unwrapped_read().get(id).map(|token| token.request.clone())
}
fn request_rejected(&self, id: U256) -> Option<TransactionConfirmation> {
@@ -280,17 +280,17 @@ impl SigningQueue for ConfirmationsQueue {
}
fn requests(&self) -> Vec<TransactionConfirmation> {
let queue = self.queue.read().unwrap();
let queue = self.queue.unwrapped_read();
queue.values().map(|token| token.request.clone()).collect()
}
fn len(&self) -> usize {
let queue = self.queue.read().unwrap();
let queue = self.queue.unwrapped_read();
queue.len()
}
fn is_empty(&self) -> bool {
let queue = self.queue.read().unwrap();
let queue = self.queue.unwrapped_read();
queue.is_empty()
}
}
@@ -301,7 +301,7 @@ mod test {
use std::time::Duration;
use std::thread;
use std::sync::{Arc, Mutex};
use util::{Address, U256, H256};
use util::{Address, U256, H256, Lockable};
use v1::helpers::{SigningQueue, ConfirmationsQueue, QueueEvent, TransactionRequest};
use v1::types::H256 as NH256;
use jsonrpc_core::to_value;

View File

@@ -16,7 +16,7 @@
//! Test implementation of miner service.
use util::{Address, H256, Bytes, U256, FixedHash, Uint, Lockable};
use util::{Address, H256, Bytes, U256, FixedHash, Uint, Lockable, RwLockable};
use util::standard::*;
use ethcore::error::{Error, ExecutionError};
use ethcore::client::{MiningBlockChainClient, Executed, CallAnalytics};
@@ -76,57 +76,57 @@ impl MinerService for TestMinerService {
}
fn set_author(&self, author: Address) {
*self.author.write().unwrap() = author;
*self.author.unwrapped_write() = author;
}
fn set_extra_data(&self, extra_data: Bytes) {
*self.extra_data.write().unwrap() = extra_data;
*self.extra_data.unwrapped_write() = extra_data;
}
/// Set the lower gas limit we wish to target when sealing a new block.
fn set_gas_floor_target(&self, target: U256) {
self.gas_range_target.write().unwrap().0 = target;
self.gas_range_target.unwrapped_write().0 = target;
}
/// Set the upper gas limit we wish to target when sealing a new block.
fn set_gas_ceil_target(&self, target: U256) {
self.gas_range_target.write().unwrap().1 = target;
self.gas_range_target.unwrapped_write().1 = target;
}
fn set_minimal_gas_price(&self, min_gas_price: U256) {
*self.min_gas_price.write().unwrap() = min_gas_price;
*self.min_gas_price.unwrapped_write() = min_gas_price;
}
fn set_transactions_limit(&self, limit: usize) {
*self.limit.write().unwrap() = limit;
*self.limit.unwrapped_write() = limit;
}
fn set_tx_gas_limit(&self, limit: U256) {
*self.tx_gas_limit.write().unwrap() = limit;
*self.tx_gas_limit.unwrapped_write() = limit;
}
fn transactions_limit(&self) -> usize {
*self.limit.read().unwrap()
*self.limit.unwrapped_read()
}
fn author(&self) -> Address {
*self.author.read().unwrap()
*self.author.unwrapped_read()
}
fn minimal_gas_price(&self) -> U256 {
*self.min_gas_price.read().unwrap()
*self.min_gas_price.unwrapped_read()
}
fn extra_data(&self) -> Bytes {
self.extra_data.read().unwrap().clone()
self.extra_data.unwrapped_read().clone()
}
fn gas_floor_target(&self) -> U256 {
self.gas_range_target.read().unwrap().0
self.gas_range_target.unwrapped_read().0
}
fn gas_ceil_target(&self) -> U256 {
self.gas_range_target.read().unwrap().1
self.gas_range_target.unwrapped_read().1
}
/// Imports transactions to transaction queue.
@@ -137,7 +137,7 @@ impl MinerService for TestMinerService {
for sender in transactions.iter().filter_map(|t| t.sender().ok()) {
let nonce = self.last_nonce(&sender).expect("last_nonce must be populated in tests");
self.last_nonces.write().unwrap().insert(sender, nonce + U256::from(1));
self.last_nonces.unwrapped_write().insert(sender, nonce + U256::from(1));
}
transactions
.iter()
@@ -152,7 +152,7 @@ impl MinerService for TestMinerService {
// keep the pending nonces up to date
if let Ok(ref sender) = transaction.sender() {
let nonce = self.last_nonce(sender).unwrap_or(chain.latest_nonce(sender));
self.last_nonces.write().unwrap().insert(sender.clone(), nonce + U256::from(1));
self.last_nonces.unwrapped_write().insert(sender.clone(), nonce + U256::from(1));
}
// lets assume that all txs are valid
@@ -202,7 +202,7 @@ impl MinerService for TestMinerService {
}
fn last_nonce(&self, address: &Address) -> Option<U256> {
self.last_nonces.read().unwrap().get(address).cloned()
self.last_nonces.unwrapped_read().get(address).cloned()
}
/// Submit `seal` as a valid solution for the header of `pow_hash`.

View File

@@ -16,7 +16,7 @@
//! Test implementation of SyncProvider.
use util::U256;
use util::{U256, RwLockable};
use ethsync::{SyncProvider, SyncStatus, SyncState};
use std::sync::RwLock;
@@ -57,7 +57,7 @@ impl TestSyncProvider {
impl SyncProvider for TestSyncProvider {
fn status(&self) -> SyncStatus {
self.status.read().unwrap().clone()
self.status.unwrapped_read().clone()
}
fn start_network(&self) {

View File

@@ -18,7 +18,7 @@ use std::str::FromStr;
use std::collections::HashMap;
use std::sync::{Arc, RwLock};
use jsonrpc_core::IoHandler;
use util::Lockable;
use util::{Lockable, RwLockable};
use util::hash::{Address, H256, FixedHash};
use util::numbers::{Uint, U256};
use ethcore::account_provider::AccountProvider;
@@ -104,13 +104,13 @@ fn rpc_eth_syncing() {
assert_eq!(tester.io.handle_request(request), Some(false_res.to_owned()));
{
let mut status = tester.sync.status.write().unwrap();
let mut status = tester.sync.status.unwrapped_write();
status.state = SyncState::Blocks;
status.highest_block_number = Some(2500);
// "sync" to 1000 blocks.
// causes TestBlockChainClient to return 1000 for its best block number.
let mut blocks = tester.client.blocks.write().unwrap();
let mut blocks = tester.client.blocks.unwrapped_write();
for i in 0..1000 {
blocks.insert(H256::from(i), Vec::new());
}
@@ -121,7 +121,7 @@ fn rpc_eth_syncing() {
{
// finish "syncing"
let mut blocks = tester.client.blocks.write().unwrap();
let mut blocks = tester.client.blocks.unwrapped_write();
for i in 0..1500 {
blocks.insert(H256::from(i + 1000), Vec::new());
}
@@ -133,9 +133,9 @@ fn rpc_eth_syncing() {
#[test]
fn rpc_eth_hashrate() {
let tester = EthTester::default();
tester.hashrates.write().unwrap().insert(H256::from(0), U256::from(0xfffa));
tester.hashrates.write().unwrap().insert(H256::from(0), U256::from(0xfffb));
tester.hashrates.write().unwrap().insert(H256::from(1), U256::from(0x1));
tester.hashrates.unwrapped_write().insert(H256::from(0), U256::from(0xfffa));
tester.hashrates.unwrapped_write().insert(H256::from(0), U256::from(0xfffb));
tester.hashrates.unwrapped_write().insert(H256::from(1), U256::from(0x1));
let request = r#"{"jsonrpc": "2.0", "method": "eth_hashrate", "params": [], "id": 1}"#;
let response = r#"{"jsonrpc":"2.0","result":"0xfffc","id":1}"#;
@@ -158,7 +158,7 @@ fn rpc_eth_submit_hashrate() {
let response = r#"{"jsonrpc":"2.0","result":true,"id":1}"#;
assert_eq!(tester.io.handle_request(request), Some(response.to_owned()));
assert_eq!(tester.hashrates.read().unwrap().get(&H256::from("0x59daa26581d0acd1fce254fb7e85952f4c09d0915afd33d3886cd914bc7d283c")).cloned(),
assert_eq!(tester.hashrates.unwrapped_read().get(&H256::from("0x59daa26581d0acd1fce254fb7e85952f4c09d0915afd33d3886cd914bc7d283c")).cloned(),
Some(U256::from(0x500_000)));
}
@@ -215,7 +215,7 @@ fn rpc_eth_mining() {
let response = r#"{"jsonrpc":"2.0","result":false,"id":1}"#;
assert_eq!(tester.io.handle_request(request), Some(response.to_owned()));
tester.hashrates.write().unwrap().insert(H256::from(1), U256::from(0x1));
tester.hashrates.unwrapped_write().insert(H256::from(1), U256::from(0x1));
let request = r#"{"jsonrpc": "2.0", "method": "eth_mining", "params": [], "id": 1}"#;
let response = r#"{"jsonrpc":"2.0","result":true,"id":1}"#;
@@ -591,7 +591,7 @@ fn rpc_eth_send_transaction() {
assert_eq!(tester.io.handle_request(&request), Some(response));
tester.miner.last_nonces.write().unwrap().insert(address.clone(), U256::zero());
tester.miner.last_nonces.unwrapped_write().insert(address.clone(), U256::zero());
let t = Transaction {
nonce: U256::one(),
@@ -749,7 +749,7 @@ fn returns_error_if_can_mine_and_no_closed_block() {
use ethsync::{SyncState};
let eth_tester = EthTester::default();
eth_tester.sync.status.write().unwrap().state = SyncState::Idle;
eth_tester.sync.status.unwrapped_write().state = SyncState::Idle;
let request = r#"{"jsonrpc": "2.0", "method": "eth_getWork", "params": [], "id": 1}"#;
let response = r#"{"jsonrpc":"2.0","error":{"code":-32603,"message":"Internal error","data":null},"id":1}"#;

View File

@@ -18,6 +18,7 @@ use std::sync::Arc;
use std::str::FromStr;
use jsonrpc_core::IoHandler;
use util::numbers::*;
use util::RwLockable;
use ethcore::account_provider::AccountProvider;
use v1::{PersonalClient, Personal};
use v1::tests::helpers::TestMinerService;
@@ -174,7 +175,7 @@ fn sign_and_send_transaction() {
assert_eq!(tester.io.handle_request(request.as_ref()), Some(response));
tester.miner.last_nonces.write().unwrap().insert(address.clone(), U256::zero());
tester.miner.last_nonces.unwrapped_write().insert(address.clone(), U256::zero());
let t = Transaction {
nonce: U256::one(),