Make *ID names consistent with std Rust (Id)

This commit is contained in:
Gav Wood
2016-12-09 23:01:43 +01:00
parent 2226324495
commit 5f1fcf95e0
46 changed files with 389 additions and 389 deletions

View File

@@ -32,7 +32,7 @@ use util::sha3::*;
use util::{FromHex, Mutex};
use rlp::{self, UntrustedRlp, View};
use ethcore::account_provider::AccountProvider;
use ethcore::client::{MiningBlockChainClient, BlockID, TransactionID, UncleID};
use ethcore::client::{MiningBlockChainClient, BlockId, TransactionId, UncleId};
use ethcore::header::{Header as BlockHeader, BlockNumber as EthBlockNumber};
use ethcore::block::IsBlock;
use ethcore::views::*;
@@ -119,7 +119,7 @@ impl<C, SN: ?Sized, S: ?Sized, M, EM> EthClient<C, SN, S, M, EM> where
}
}
fn block(&self, id: BlockID, include_txs: bool) -> Result<Option<RichBlock>, Error> {
fn block(&self, id: BlockId, include_txs: bool) -> Result<Option<RichBlock>, Error> {
let client = take_weak!(self.client);
match (client.block(id.clone()), client.block_total_difficulty(id)) {
(Some(bytes), Some(total_difficulty)) => {
@@ -159,20 +159,20 @@ impl<C, SN: ?Sized, S: ?Sized, M, EM> EthClient<C, SN, S, M, EM> where
}
}
fn transaction(&self, id: TransactionID) -> Result<Option<Transaction>, Error> {
fn transaction(&self, id: TransactionId) -> Result<Option<Transaction>, Error> {
match take_weak!(self.client).transaction(id) {
Some(t) => Ok(Some(Transaction::from(t))),
None => Ok(None),
}
}
fn uncle(&self, id: UncleID) -> Result<Option<RichBlock>, Error> {
fn uncle(&self, id: UncleId) -> Result<Option<RichBlock>, Error> {
let client = take_weak!(self.client);
let uncle: BlockHeader = match client.uncle(id) {
Some(rlp) => rlp::decode(&rlp),
None => { return Ok(None); }
};
let parent_difficulty = match client.block_total_difficulty(BlockID::Hash(uncle.parent_hash().clone())) {
let parent_difficulty = match client.block_total_difficulty(BlockId::Hash(uncle.parent_hash().clone())) {
Some(difficulty) => difficulty,
None => { return Ok(None); }
};
@@ -393,7 +393,7 @@ impl<C, SN: ?Sized, S: ?Sized, M, EM> Eth for EthClient<C, SN, S, M, EM> where
fn block_transaction_count_by_hash(&self, hash: RpcH256) -> Result<Option<RpcU256>, Error> {
try!(self.active());
Ok(
take_weak!(self.client).block(BlockID::Hash(hash.into()))
take_weak!(self.client).block(BlockId::Hash(hash.into()))
.map(|bytes| BlockView::new(&bytes).transactions_count().into())
)
}
@@ -416,7 +416,7 @@ impl<C, SN: ?Sized, S: ?Sized, M, EM> Eth for EthClient<C, SN, S, M, EM> where
try!(self.active());
Ok(
take_weak!(self.client).block(BlockID::Hash(hash.into()))
take_weak!(self.client).block(BlockId::Hash(hash.into()))
.map(|bytes| BlockView::new(&bytes).uncles_count().into())
)
}
@@ -449,7 +449,7 @@ impl<C, SN: ?Sized, S: ?Sized, M, EM> Eth for EthClient<C, SN, S, M, EM> where
fn block_by_hash(&self, hash: RpcH256, include_txs: bool) -> Result<Option<RichBlock>, Error> {
try!(self.active());
self.block(BlockID::Hash(hash.into()), include_txs)
self.block(BlockId::Hash(hash.into()), include_txs)
}
fn block_by_number(&self, num: BlockNumber, include_txs: bool) -> Result<Option<RichBlock>, Error> {
@@ -463,19 +463,19 @@ impl<C, SN: ?Sized, S: ?Sized, M, EM> Eth for EthClient<C, SN, S, M, EM> where
let hash: H256 = hash.into();
let miner = take_weak!(self.miner);
let client = take_weak!(self.client);
Ok(try!(self.transaction(TransactionID::Hash(hash))).or_else(|| miner.transaction(client.chain_info().best_block_number, &hash).map(Into::into)))
Ok(try!(self.transaction(TransactionId::Hash(hash))).or_else(|| miner.transaction(client.chain_info().best_block_number, &hash).map(Into::into)))
}
fn transaction_by_block_hash_and_index(&self, hash: RpcH256, index: Index) -> Result<Option<Transaction>, Error> {
try!(self.active());
self.transaction(TransactionID::Location(BlockID::Hash(hash.into()), index.value()))
self.transaction(TransactionId::Location(BlockId::Hash(hash.into()), index.value()))
}
fn transaction_by_block_number_and_index(&self, num: BlockNumber, index: Index) -> Result<Option<Transaction>, Error> {
try!(self.active());
self.transaction(TransactionID::Location(num.into(), index.value()))
self.transaction(TransactionId::Location(num.into(), index.value()))
}
fn transaction_receipt(&self, hash: RpcH256) -> Result<Option<Receipt>, Error> {
@@ -488,7 +488,7 @@ impl<C, SN: ?Sized, S: ?Sized, M, EM> Eth for EthClient<C, SN, S, M, EM> where
(Some(receipt), true) => Ok(Some(receipt.into())),
_ => {
let client = take_weak!(self.client);
let receipt = client.transaction_receipt(TransactionID::Hash(hash));
let receipt = client.transaction_receipt(TransactionId::Hash(hash));
Ok(receipt.map(Into::into))
}
}
@@ -497,13 +497,13 @@ impl<C, SN: ?Sized, S: ?Sized, M, EM> Eth for EthClient<C, SN, S, M, EM> where
fn uncle_by_block_hash_and_index(&self, hash: RpcH256, index: Index) -> Result<Option<RichBlock>, Error> {
try!(self.active());
self.uncle(UncleID { block: BlockID::Hash(hash.into()), position: index.value() })
self.uncle(UncleId { block: BlockId::Hash(hash.into()), position: index.value() })
}
fn uncle_by_block_number_and_index(&self, num: BlockNumber, index: Index) -> Result<Option<RichBlock>, Error> {
try!(self.active());
self.uncle(UncleID { block: num.into(), position: index.value() })
self.uncle(UncleId { block: num.into(), position: index.value() })
}
fn compilers(&self) -> Result<Vec<String>, Error> {

View File

@@ -21,7 +21,7 @@ use std::collections::HashSet;
use jsonrpc_core::*;
use ethcore::miner::MinerService;
use ethcore::filter::Filter as EthcoreFilter;
use ethcore::client::{BlockChainClient, BlockID};
use ethcore::client::{BlockChainClient, BlockId};
use util::Mutex;
use v1::traits::EthFilter;
use v1::types::{BlockNumber, Index, Filter, FilterChanges, Log, H256 as RpcH256, U256 as RpcU256};
@@ -98,7 +98,7 @@ impl<C, M> EthFilter for EthFilterClient<C, M>
// + 1, cause we want to return hashes including current block hash.
let current_number = client.chain_info().best_block_number + 1;
let hashes = (*block_number..current_number).into_iter()
.map(BlockID::Number)
.map(BlockId::Number)
.filter_map(|id| client.block_hash(id))
.map(Into::into)
.collect::<Vec<RpcH256>>();
@@ -140,10 +140,10 @@ impl<C, M> EthFilter for EthFilterClient<C, M>
// build appropriate filter
let mut filter: EthcoreFilter = filter.clone().into();
filter.from_block = BlockID::Number(*block_number);
filter.to_block = BlockID::Latest;
filter.from_block = BlockId::Number(*block_number);
filter.to_block = BlockId::Latest;
// retrieve logs in range from_block..min(BlockID::Latest..to_block)
// retrieve logs in range from_block..min(BlockId::Latest..to_block)
let mut logs = client.logs(filter.clone())
.into_iter()
.map(From::from)

View File

@@ -19,7 +19,7 @@
use std::sync::{Weak, Arc};
use jsonrpc_core::*;
use rlp::{UntrustedRlp, View};
use ethcore::client::{BlockChainClient, CallAnalytics, TransactionID, TraceId};
use ethcore::client::{BlockChainClient, CallAnalytics, TransactionId, TraceId};
use ethcore::miner::MinerService;
use ethcore::transaction::{Transaction as EthTransaction, SignedTransaction, Action};
use v1::traits::Traces;
@@ -100,7 +100,7 @@ impl<C, M> Traces for TracesClient<C, M> where C: BlockChainClient + 'static, M:
from_params::<(H256,)>(params)
.and_then(|(transaction_hash,)| {
let client = take_weak!(self.client);
let traces = client.transaction_traces(TransactionID::Hash(transaction_hash.into()));
let traces = client.transaction_traces(TransactionId::Hash(transaction_hash.into()));
let traces = traces.map_or_else(Vec::new, |traces| traces.into_iter().map(LocalizedTrace::from).collect());
Ok(to_value(&traces))
})
@@ -112,7 +112,7 @@ impl<C, M> Traces for TracesClient<C, M> where C: BlockChainClient + 'static, M:
.and_then(|(transaction_hash, address)| {
let client = take_weak!(self.client);
let id = TraceId {
transaction: TransactionID::Hash(transaction_hash.into()),
transaction: TransactionId::Hash(transaction_hash.into()),
address: address.into_iter().map(|i| i.value()).collect()
};
let trace = client.trace(id);
@@ -153,7 +153,7 @@ impl<C, M> Traces for TracesClient<C, M> where C: BlockChainClient + 'static, M:
try!(self.active());
from_params::<(H256, _)>(params)
.and_then(|(transaction_hash, flags)| {
match take_weak!(self.client).replay(TransactionID::Hash(transaction_hash.into()), to_call_analytics(flags)) {
match take_weak!(self.client).replay(TransactionId::Hash(transaction_hash.into()), to_call_analytics(flags)) {
Ok(e) => Ok(to_value(&TraceResults::from(e))),
_ => Ok(Value::Null),
}

View File

@@ -19,7 +19,7 @@ use std::sync::Arc;
use std::time::Duration;
use ethcore::client::{BlockChainClient, Client, ClientConfig};
use ethcore::ids::BlockID;
use ethcore::ids::BlockId;
use ethcore::spec::{Genesis, Spec};
use ethcore::block::Block;
use ethcore::views::BlockView;
@@ -425,7 +425,7 @@ fn verify_transaction_counts(name: String, chain: BlockChain) {
assert_eq!(tester.handler.handle_request_sync(&req), Some(res));
// uncles can share block numbers, so skip them.
if tester.client.block_hash(BlockID::Number(number)) == Some(hash) {
if tester.client.block_hash(BlockId::Number(number)) == Some(hash) {
let (req, res) = by_number(number, count, &mut id);
assert_eq!(tester.handler.handle_request_sync(&req), Some(res));
}

View File

@@ -24,7 +24,7 @@ use rlp;
use util::{Uint, U256, Address, H256, FixedHash, Mutex};
use ethcore::account_provider::AccountProvider;
use ethcore::client::{TestBlockChainClient, EachBlockWith, Executed, TransactionID};
use ethcore::client::{TestBlockChainClient, EachBlockWith, Executed, TransactionId};
use ethcore::log_entry::{LocalizedLogEntry, LogEntry};
use ethcore::receipt::LocalizedReceipt;
use ethcore::transaction::{Transaction, Action};
@@ -952,7 +952,7 @@ fn rpc_eth_transaction_receipt() {
let hash = H256::from_str("b903239f8543d04b5dc1ba6579132b143087c68db1b2168786408fcbce568238").unwrap();
let tester = EthTester::default();
tester.client.set_transaction_receipt(TransactionID::Hash(hash), receipt);
tester.client.set_transaction_receipt(TransactionId::Hash(hash), receipt);
let request = r#"{
"jsonrpc": "2.0",

View File

@@ -16,7 +16,7 @@
use serde::{Deserialize, Deserializer, Error};
use serde::de::Visitor;
use ethcore::client::BlockID;
use ethcore::client::BlockId;
/// Represents rpc api block number param.
#[derive(Debug, PartialEq, Clone)]
@@ -64,20 +64,20 @@ impl Visitor for BlockNumberVisitor {
}
}
impl Into<BlockID> for BlockNumber {
fn into(self) -> BlockID {
impl Into<BlockId> for BlockNumber {
fn into(self) -> BlockId {
match self {
BlockNumber::Num(n) => BlockID::Number(n),
BlockNumber::Earliest => BlockID::Earliest,
BlockNumber::Latest => BlockID::Latest,
BlockNumber::Pending => BlockID::Pending,
BlockNumber::Num(n) => BlockId::Number(n),
BlockNumber::Earliest => BlockId::Earliest,
BlockNumber::Latest => BlockId::Latest,
BlockNumber::Pending => BlockId::Pending,
}
}
}
#[cfg(test)]
mod tests {
use ethcore::client::BlockID;
use ethcore::client::BlockId;
use super::*;
use serde_json;
@@ -90,10 +90,10 @@ mod tests {
#[test]
fn block_number_into() {
assert_eq!(BlockID::Number(100), BlockNumber::Num(100).into());
assert_eq!(BlockID::Earliest, BlockNumber::Earliest.into());
assert_eq!(BlockID::Latest, BlockNumber::Latest.into());
assert_eq!(BlockID::Pending, BlockNumber::Pending.into());
assert_eq!(BlockId::Number(100), BlockNumber::Num(100).into());
assert_eq!(BlockId::Earliest, BlockNumber::Earliest.into());
assert_eq!(BlockId::Latest, BlockNumber::Latest.into());
assert_eq!(BlockId::Pending, BlockNumber::Pending.into());
}
}

View File

@@ -18,7 +18,7 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer, Error};
use serde_json::value;
use jsonrpc_core::Value;
use ethcore::filter::Filter as EthFilter;
use ethcore::client::BlockID;
use ethcore::client::BlockId;
use v1::types::{BlockNumber, H160, H256, Log};
/// Variadic value
@@ -73,8 +73,8 @@ pub struct Filter {
impl Into<EthFilter> for Filter {
fn into(self) -> EthFilter {
EthFilter {
from_block: self.from_block.map_or_else(|| BlockID::Latest, Into::into),
to_block: self.to_block.map_or_else(|| BlockID::Latest, Into::into),
from_block: self.from_block.map_or_else(|| BlockId::Latest, Into::into),
to_block: self.to_block.map_or_else(|| BlockId::Latest, Into::into),
address: self.address.and_then(|address| match address {
VariadicValue::Null => None,
VariadicValue::Single(a) => Some(vec![a.into()]),
@@ -128,7 +128,7 @@ mod tests {
use super::{VariadicValue, Topic, Filter};
use v1::types::BlockNumber;
use ethcore::filter::Filter as EthFilter;
use ethcore::client::BlockID;
use ethcore::client::BlockId;
#[test]
fn topic_deserialization() {
@@ -173,8 +173,8 @@ mod tests {
let eth_filter: EthFilter = filter.into();
assert_eq!(eth_filter, EthFilter {
from_block: BlockID::Earliest,
to_block: BlockID::Latest,
from_block: BlockId::Earliest,
to_block: BlockId::Latest,
address: Some(vec![]),
topics: vec![
None,

View File

@@ -16,7 +16,7 @@
//! Trace filter deserialization.
use ethcore::client::BlockID;
use ethcore::client::BlockId;
use ethcore::client;
use v1::types::{BlockNumber, H160};
@@ -40,8 +40,8 @@ pub struct TraceFilter {
impl Into<client::TraceFilter> for TraceFilter {
fn into(self) -> client::TraceFilter {
let start = self.from_block.map_or(BlockID::Latest, Into::into);
let end = self.to_block.map_or(BlockID::Latest, Into::into);
let start = self.from_block.map_or(BlockId::Latest, Into::into);
let end = self.to_block.map_or(BlockId::Latest, Into::into);
client::TraceFilter {
range: start..end,
from_address: self.from_address.map_or_else(Vec::new, |x| x.into_iter().map(Into::into).collect()),