Merge branch 'master' into ng-ui-fixes
This commit is contained in:
commit
89ed76497e
@ -423,12 +423,8 @@ test-rust-stable:
|
|||||||
before_script:
|
before_script:
|
||||||
- git submodule update --init --recursive
|
- git submodule update --init --recursive
|
||||||
- export RUST_FILES_MODIFIED=$(git --no-pager diff --name-only $CI_BUILD_REF^ $CI_BUILD_REF | grep -v ^js/ | wc -l)
|
- export RUST_FILES_MODIFIED=$(git --no-pager diff --name-only $CI_BUILD_REF^ $CI_BUILD_REF | grep -v ^js/ | wc -l)
|
||||||
- export JS_FILES_MODIFIED=$(git --no-pager diff --name-only $CI_BUILD_REF^ $CI_BUILD_REF | grep ^js/ | wc -l)
|
|
||||||
- echo "rust/js modified: $RUST_FILES_MODIFIED / $JS_FILES_MODIFIED"
|
|
||||||
- if [ "$JS_FILES_MODIFIED" = 0 ]; then echo "Skipping JS deps install since no JS files modified."; else ./js/scripts/install-deps.sh;fi
|
|
||||||
script:
|
script:
|
||||||
- export RUST_BACKTRACE=1
|
- export RUST_BACKTRACE=1
|
||||||
- if [ "$JS_FILES_MODIFIED" = 0 ]; then echo "Skipping JS lint since no JS files modified."; else ./js/scripts/lint.sh && ./js/scripts/test.sh && ./js/scripts/build.sh; fi
|
|
||||||
- if [ "$RUST_FILES_MODIFIED" = 0 ]; then echo "Skipping Rust tests since no Rust files modified."; else ./test.sh $CARGOFLAGS; fi
|
- if [ "$RUST_FILES_MODIFIED" = 0 ]; then echo "Skipping Rust tests since no Rust files modified."; else ./test.sh $CARGOFLAGS; fi
|
||||||
tags:
|
tags:
|
||||||
- rust
|
- rust
|
||||||
@ -439,11 +435,8 @@ js-test:
|
|||||||
before_script:
|
before_script:
|
||||||
- git submodule update --init --recursive
|
- git submodule update --init --recursive
|
||||||
- export JS_FILES_MODIFIED=$(git --no-pager diff --name-only $CI_BUILD_REF^ $CI_BUILD_REF | grep ^js/ | wc -l)
|
- export JS_FILES_MODIFIED=$(git --no-pager diff --name-only $CI_BUILD_REF^ $CI_BUILD_REF | grep ^js/ | wc -l)
|
||||||
- echo $JS_FILES_MODIFIED
|
|
||||||
- if [ "$JS_FILES_MODIFIED" = 0 ]; then echo "Skipping JS deps install since no JS files modified."; else ./js/scripts/install-deps.sh;fi
|
- if [ "$JS_FILES_MODIFIED" = 0 ]; then echo "Skipping JS deps install since no JS files modified."; else ./js/scripts/install-deps.sh;fi
|
||||||
script:
|
script:
|
||||||
- export RUST_BACKTRACE=1
|
|
||||||
- echo $JS_FILES_MODIFIED
|
|
||||||
- if [ "$JS_FILES_MODIFIED" = 0 ]; then echo "Skipping JS lint since no JS files modified."; else ./js/scripts/lint.sh && ./js/scripts/test.sh && ./js/scripts/build.sh; fi
|
- if [ "$JS_FILES_MODIFIED" = 0 ]; then echo "Skipping JS lint since no JS files modified."; else ./js/scripts/lint.sh && ./js/scripts/test.sh && ./js/scripts/build.sh; fi
|
||||||
tags:
|
tags:
|
||||||
- rust
|
- rust
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use ethcore::engines::Engine;
|
use ethcore::engines::Engine;
|
||||||
use ethcore::ids::BlockID;
|
use ethcore::ids::BlockId;
|
||||||
use ethcore::service::ClientIoMessage;
|
use ethcore::service::ClientIoMessage;
|
||||||
use ethcore::block_import_error::BlockImportError;
|
use ethcore::block_import_error::BlockImportError;
|
||||||
use ethcore::block_status::BlockStatus;
|
use ethcore::block_status::BlockStatus;
|
||||||
@ -51,7 +51,7 @@ impl Client {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Whether the block is already known (but not necessarily part of the canonical chain)
|
/// Whether the block is already known (but not necessarily part of the canonical chain)
|
||||||
pub fn is_known(&self, _id: BlockID) -> bool {
|
pub fn is_known(&self, _id: BlockId) -> bool {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,7 +61,7 @@ impl Client {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Inquire about the status of a given block.
|
/// Inquire about the status of a given block.
|
||||||
pub fn status(&self, _id: BlockID) -> BlockStatus {
|
pub fn status(&self, _id: BlockId) -> BlockStatus {
|
||||||
BlockStatus::Unknown
|
BlockStatus::Unknown
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
use ethcore::blockchain_info::BlockChainInfo;
|
use ethcore::blockchain_info::BlockChainInfo;
|
||||||
use ethcore::client::{BlockChainClient, EachBlockWith, TestBlockChainClient};
|
use ethcore::client::{BlockChainClient, EachBlockWith, TestBlockChainClient};
|
||||||
use ethcore::ids::BlockID;
|
use ethcore::ids::BlockId;
|
||||||
use ethcore::transaction::SignedTransaction;
|
use ethcore::transaction::SignedTransaction;
|
||||||
use network::PeerId;
|
use network::PeerId;
|
||||||
|
|
||||||
@ -94,7 +94,7 @@ impl Provider for TestProvider {
|
|||||||
let best_num = self.0.client.chain_info().best_block_number;
|
let best_num = self.0.client.chain_info().best_block_number;
|
||||||
let start_num = req.block_num;
|
let start_num = req.block_num;
|
||||||
|
|
||||||
match self.0.client.block_hash(BlockID::Number(req.block_num)) {
|
match self.0.client.block_hash(BlockId::Number(req.block_num)) {
|
||||||
Some(hash) if hash == req.block_hash => {}
|
Some(hash) if hash == req.block_hash => {}
|
||||||
_=> {
|
_=> {
|
||||||
trace!(target: "les_provider", "unknown/non-canonical start block in header request: {:?}", (req.block_num, req.block_hash));
|
trace!(target: "les_provider", "unknown/non-canonical start block in header request: {:?}", (req.block_num, req.block_hash));
|
||||||
@ -106,7 +106,7 @@ impl Provider for TestProvider {
|
|||||||
.map(|x: u64| x.saturating_mul(req.skip + 1))
|
.map(|x: u64| x.saturating_mul(req.skip + 1))
|
||||||
.take_while(|x| if req.reverse { x < &start_num } else { best_num - start_num >= *x })
|
.take_while(|x| if req.reverse { x < &start_num } else { best_num - start_num >= *x })
|
||||||
.map(|x| if req.reverse { start_num - x } else { start_num + x })
|
.map(|x| if req.reverse { start_num - x } else { start_num + x })
|
||||||
.map(|x| self.0.client.block_header(BlockID::Number(x)))
|
.map(|x| self.0.client.block_header(BlockId::Number(x)))
|
||||||
.take_while(|x| x.is_some())
|
.take_while(|x| x.is_some())
|
||||||
.flat_map(|x| x)
|
.flat_map(|x| x)
|
||||||
.collect()
|
.collect()
|
||||||
@ -114,7 +114,7 @@ impl Provider for TestProvider {
|
|||||||
|
|
||||||
fn block_bodies(&self, req: request::Bodies) -> Vec<Bytes> {
|
fn block_bodies(&self, req: request::Bodies) -> Vec<Bytes> {
|
||||||
req.block_hashes.into_iter()
|
req.block_hashes.into_iter()
|
||||||
.map(|hash| self.0.client.block_body(BlockID::Hash(hash)))
|
.map(|hash| self.0.client.block_body(BlockId::Hash(hash)))
|
||||||
.map(|body| body.unwrap_or_else(|| ::rlp::EMPTY_LIST_RLP.to_vec()))
|
.map(|body| body.unwrap_or_else(|| ::rlp::EMPTY_LIST_RLP.to_vec()))
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
@ -285,7 +285,7 @@ fn get_block_headers() {
|
|||||||
|
|
||||||
let request = Headers {
|
let request = Headers {
|
||||||
block_num: 1,
|
block_num: 1,
|
||||||
block_hash: provider.client.block_hash(BlockID::Number(1)).unwrap(),
|
block_hash: provider.client.block_hash(BlockId::Number(1)).unwrap(),
|
||||||
max: 10,
|
max: 10,
|
||||||
skip: 0,
|
skip: 0,
|
||||||
reverse: false,
|
reverse: false,
|
||||||
@ -294,7 +294,7 @@ fn get_block_headers() {
|
|||||||
|
|
||||||
let request_body = encode_request(&Request::Headers(request.clone()), req_id);
|
let request_body = encode_request(&Request::Headers(request.clone()), req_id);
|
||||||
let response = {
|
let response = {
|
||||||
let headers: Vec<_> = (0..10).map(|i| provider.client.block_header(BlockID::Number(i + 1)).unwrap()).collect();
|
let headers: Vec<_> = (0..10).map(|i| provider.client.block_header(BlockId::Number(i + 1)).unwrap()).collect();
|
||||||
assert_eq!(headers.len(), 10);
|
assert_eq!(headers.len(), 10);
|
||||||
|
|
||||||
let new_buf = *flow_params.limit() - flow_params.compute_cost(request::Kind::Headers, 10);
|
let new_buf = *flow_params.limit() - flow_params.compute_cost(request::Kind::Headers, 10);
|
||||||
@ -334,14 +334,14 @@ fn get_block_bodies() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let request = request::Bodies {
|
let request = request::Bodies {
|
||||||
block_hashes: (0..10).map(|i| provider.client.block_hash(BlockID::Number(i)).unwrap()).collect(),
|
block_hashes: (0..10).map(|i| provider.client.block_hash(BlockId::Number(i)).unwrap()).collect(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let req_id = 111;
|
let req_id = 111;
|
||||||
|
|
||||||
let request_body = encode_request(&Request::Bodies(request.clone()), req_id);
|
let request_body = encode_request(&Request::Bodies(request.clone()), req_id);
|
||||||
let response = {
|
let response = {
|
||||||
let bodies: Vec<_> = (0..10).map(|i| provider.client.block_body(BlockID::Number(i + 1)).unwrap()).collect();
|
let bodies: Vec<_> = (0..10).map(|i| provider.client.block_body(BlockId::Number(i + 1)).unwrap()).collect();
|
||||||
assert_eq!(bodies.len(), 10);
|
assert_eq!(bodies.len(), 10);
|
||||||
|
|
||||||
let new_buf = *flow_params.limit() - flow_params.compute_cost(request::Kind::Bodies, 10);
|
let new_buf = *flow_params.limit() - flow_params.compute_cost(request::Kind::Bodies, 10);
|
||||||
@ -382,7 +382,7 @@ fn get_block_receipts() {
|
|||||||
|
|
||||||
// find the first 10 block hashes starting with `f` because receipts are only provided
|
// find the first 10 block hashes starting with `f` because receipts are only provided
|
||||||
// by the test client in that case.
|
// by the test client in that case.
|
||||||
let block_hashes: Vec<_> = (0..1000).map(|i| provider.client.block_hash(BlockID::Number(i)).unwrap())
|
let block_hashes: Vec<_> = (0..1000).map(|i| provider.client.block_hash(BlockId::Number(i)).unwrap())
|
||||||
.filter(|hash| format!("{}", hash).starts_with("f")).take(10).collect();
|
.filter(|hash| format!("{}", hash).starts_with("f")).take(10).collect();
|
||||||
|
|
||||||
let request = request::Receipts {
|
let request = request::Receipts {
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
use ethcore::blockchain_info::BlockChainInfo;
|
use ethcore::blockchain_info::BlockChainInfo;
|
||||||
use ethcore::client::{BlockChainClient, ProvingBlockChainClient};
|
use ethcore::client::{BlockChainClient, ProvingBlockChainClient};
|
||||||
use ethcore::transaction::SignedTransaction;
|
use ethcore::transaction::SignedTransaction;
|
||||||
use ethcore::ids::BlockID;
|
use ethcore::ids::BlockId;
|
||||||
|
|
||||||
use util::{Bytes, H256};
|
use util::{Bytes, H256};
|
||||||
|
|
||||||
@ -100,7 +100,7 @@ impl<T: ProvingBlockChainClient + ?Sized> Provider for T {
|
|||||||
let best_num = self.chain_info().best_block_number;
|
let best_num = self.chain_info().best_block_number;
|
||||||
let start_num = req.block_num;
|
let start_num = req.block_num;
|
||||||
|
|
||||||
match self.block_hash(BlockID::Number(req.block_num)) {
|
match self.block_hash(BlockId::Number(req.block_num)) {
|
||||||
Some(hash) if hash == req.block_hash => {}
|
Some(hash) if hash == req.block_hash => {}
|
||||||
_=> {
|
_=> {
|
||||||
trace!(target: "les_provider", "unknown/non-canonical start block in header request: {:?}", (req.block_num, req.block_hash));
|
trace!(target: "les_provider", "unknown/non-canonical start block in header request: {:?}", (req.block_num, req.block_hash));
|
||||||
@ -112,7 +112,7 @@ impl<T: ProvingBlockChainClient + ?Sized> Provider for T {
|
|||||||
.map(|x: u64| x.saturating_mul(req.skip + 1))
|
.map(|x: u64| x.saturating_mul(req.skip + 1))
|
||||||
.take_while(|x| if req.reverse { x < &start_num } else { best_num - start_num >= *x })
|
.take_while(|x| if req.reverse { x < &start_num } else { best_num - start_num >= *x })
|
||||||
.map(|x| if req.reverse { start_num - x } else { start_num + x })
|
.map(|x| if req.reverse { start_num - x } else { start_num + x })
|
||||||
.map(|x| self.block_header(BlockID::Number(x)))
|
.map(|x| self.block_header(BlockId::Number(x)))
|
||||||
.take_while(|x| x.is_some())
|
.take_while(|x| x.is_some())
|
||||||
.flat_map(|x| x)
|
.flat_map(|x| x)
|
||||||
.collect()
|
.collect()
|
||||||
@ -120,7 +120,7 @@ impl<T: ProvingBlockChainClient + ?Sized> Provider for T {
|
|||||||
|
|
||||||
fn block_bodies(&self, req: request::Bodies) -> Vec<Bytes> {
|
fn block_bodies(&self, req: request::Bodies) -> Vec<Bytes> {
|
||||||
req.block_hashes.into_iter()
|
req.block_hashes.into_iter()
|
||||||
.map(|hash| self.block_body(BlockID::Hash(hash)))
|
.map(|hash| self.block_body(BlockId::Hash(hash)))
|
||||||
.map(|body| body.unwrap_or_else(|| ::rlp::EMPTY_LIST_RLP.to_vec()))
|
.map(|body| body.unwrap_or_else(|| ::rlp::EMPTY_LIST_RLP.to_vec()))
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
@ -139,8 +139,8 @@ impl<T: ProvingBlockChainClient + ?Sized> Provider for T {
|
|||||||
|
|
||||||
for request in req.requests {
|
for request in req.requests {
|
||||||
let proof = match request.key2 {
|
let proof = match request.key2 {
|
||||||
Some(key2) => self.prove_storage(request.key1, key2, request.from_level, BlockID::Hash(request.block)),
|
Some(key2) => self.prove_storage(request.key1, key2, request.from_level, BlockId::Hash(request.block)),
|
||||||
None => self.prove_account(request.key1, request.from_level, BlockID::Hash(request.block)),
|
None => self.prove_account(request.key1, request.from_level, BlockId::Hash(request.block)),
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut stream = RlpStream::new_list(proof.len());
|
let mut stream = RlpStream::new_list(proof.len());
|
||||||
@ -157,7 +157,7 @@ impl<T: ProvingBlockChainClient + ?Sized> Provider for T {
|
|||||||
fn contract_code(&self, req: request::ContractCodes) -> Vec<Bytes> {
|
fn contract_code(&self, req: request::ContractCodes) -> Vec<Bytes> {
|
||||||
req.code_requests.into_iter()
|
req.code_requests.into_iter()
|
||||||
.map(|req| {
|
.map(|req| {
|
||||||
self.code_by_hash(req.account_key, BlockID::Hash(req.block_hash))
|
self.code_by_hash(req.account_key, BlockId::Hash(req.block_hash))
|
||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
@ -170,9 +170,6 @@
|
|||||||
"enode://cadc6e573b6bc2a9128f2f635ac0db3353e360b56deef239e9be7e7fce039502e0ec670b595f6288c0d2116812516ad6b6ff8d5728ff45eba176989e40dead1e@37.128.191.230:30303",
|
"enode://cadc6e573b6bc2a9128f2f635ac0db3353e360b56deef239e9be7e7fce039502e0ec670b595f6288c0d2116812516ad6b6ff8d5728ff45eba176989e40dead1e@37.128.191.230:30303",
|
||||||
"enode://595a9a06f8b9bc9835c8723b6a82105aea5d55c66b029b6d44f229d6d135ac3ecdd3e9309360a961ea39d7bee7bac5d03564077a4e08823acc723370aace65ec@46.20.235.22:30303",
|
"enode://595a9a06f8b9bc9835c8723b6a82105aea5d55c66b029b6d44f229d6d135ac3ecdd3e9309360a961ea39d7bee7bac5d03564077a4e08823acc723370aace65ec@46.20.235.22:30303",
|
||||||
"enode://029178d6d6f9f8026fc0bc17d5d1401aac76ec9d86633bba2320b5eed7b312980c0a210b74b20c4f9a8b0b2bf884b111fa9ea5c5f916bb9bbc0e0c8640a0f56c@216.158.85.185:30303",
|
"enode://029178d6d6f9f8026fc0bc17d5d1401aac76ec9d86633bba2320b5eed7b312980c0a210b74b20c4f9a8b0b2bf884b111fa9ea5c5f916bb9bbc0e0c8640a0f56c@216.158.85.185:30303",
|
||||||
"enode://84f5d5957b4880a8b0545e32e05472318898ad9fc8ebe1d56c90c12334a98e12351eccfdf3a2bf72432ac38b57e9d348400d17caa083879ade3822390f89773f@10.1.52.78:30303",
|
|
||||||
"enode://f90dc9b9bf7b8db97726b7849e175f1eb2707f3d8f281c929336e398dd89b0409fc6aeceb89e846278e9d3ecc3857cebfbe6758ff352ece6fe5d42921ee761db@10.1.173.87:30303",
|
|
||||||
"enode://6a868ced2dec399c53f730261173638a93a40214cf299ccf4d42a76e3fa54701db410669e8006347a4b3a74fa090bb35af0320e4bc8d04cf5b7f582b1db285f5@10.3.149.199:30303",
|
|
||||||
"enode://fdd1b9bb613cfbc200bba17ce199a9490edc752a833f88d4134bf52bb0d858aa5524cb3ec9366c7a4ef4637754b8b15b5dc913e4ed9fdb6022f7512d7b63f181@212.47.247.103:30303",
|
"enode://fdd1b9bb613cfbc200bba17ce199a9490edc752a833f88d4134bf52bb0d858aa5524cb3ec9366c7a4ef4637754b8b15b5dc913e4ed9fdb6022f7512d7b63f181@212.47.247.103:30303",
|
||||||
"enode://a979fb575495b8d6db44f750317d0f4622bf4c2aa3365d6af7c284339968eef29b69ad0dce72a4d8db5ebb4968de0e3bec910127f134779fbcb0cb6d3331163c@52.16.188.185:30303",
|
"enode://a979fb575495b8d6db44f750317d0f4622bf4c2aa3365d6af7c284339968eef29b69ad0dce72a4d8db5ebb4968de0e3bec910127f134779fbcb0cb6d3331163c@52.16.188.185:30303",
|
||||||
"enode://de471bccee3d042261d52e9bff31458daecc406142b401d4cd848f677479f73104b9fdeb090af9583d3391b7f10cb2ba9e26865dd5fca4fcdc0fb1e3b723c786@54.94.239.50:30303",
|
"enode://de471bccee3d042261d52e9bff31458daecc406142b401d4cd848f677479f73104b9fdeb090af9583d3391b7f10cb2ba9e26865dd5fca4fcdc0fb1e3b723c786@54.94.239.50:30303",
|
||||||
|
@ -213,7 +213,7 @@ impl AccountProvider {
|
|||||||
Ok(AccountMeta {
|
Ok(AccountMeta {
|
||||||
name: try!(self.sstore.name(&account)),
|
name: try!(self.sstore.name(&account)),
|
||||||
meta: try!(self.sstore.meta(&account)),
|
meta: try!(self.sstore.meta(&account)),
|
||||||
uuid: self.sstore.uuid(&account).ok().map(Into::into), // allowed to not have a UUID
|
uuid: self.sstore.uuid(&account).ok().map(Into::into), // allowed to not have a Uuid
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,7 +146,7 @@ pub trait BlockProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Hash, Eq, PartialEq, Clone)]
|
#[derive(Debug, Hash, Eq, PartialEq, Clone)]
|
||||||
enum CacheID {
|
enum CacheId {
|
||||||
BlockHeader(H256),
|
BlockHeader(H256),
|
||||||
BlockBody(H256),
|
BlockBody(H256),
|
||||||
BlockDetails(H256),
|
BlockDetails(H256),
|
||||||
@ -160,7 +160,7 @@ impl bc::group::BloomGroupDatabase for BlockChain {
|
|||||||
fn blooms_at(&self, position: &bc::group::GroupPosition) -> Option<bc::group::BloomGroup> {
|
fn blooms_at(&self, position: &bc::group::GroupPosition) -> Option<bc::group::BloomGroup> {
|
||||||
let position = LogGroupPosition::from(position.clone());
|
let position = LogGroupPosition::from(position.clone());
|
||||||
let result = self.db.read_with_cache(db::COL_EXTRA, &self.blocks_blooms, &position).map(Into::into);
|
let result = self.db.read_with_cache(db::COL_EXTRA, &self.blocks_blooms, &position).map(Into::into);
|
||||||
self.cache_man.lock().note_used(CacheID::BlocksBlooms(position));
|
self.cache_man.lock().note_used(CacheId::BlocksBlooms(position));
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -193,7 +193,7 @@ pub struct BlockChain {
|
|||||||
|
|
||||||
db: Arc<Database>,
|
db: Arc<Database>,
|
||||||
|
|
||||||
cache_man: Mutex<CacheManager<CacheID>>,
|
cache_man: Mutex<CacheManager<CacheId>>,
|
||||||
|
|
||||||
pending_best_block: RwLock<Option<BestBlock>>,
|
pending_best_block: RwLock<Option<BestBlock>>,
|
||||||
pending_block_hashes: RwLock<HashMap<BlockNumber, H256>>,
|
pending_block_hashes: RwLock<HashMap<BlockNumber, H256>>,
|
||||||
@ -270,7 +270,7 @@ impl BlockProvider for BlockChain {
|
|||||||
None => None
|
None => None
|
||||||
};
|
};
|
||||||
|
|
||||||
self.cache_man.lock().note_used(CacheID::BlockHeader(hash.clone()));
|
self.cache_man.lock().note_used(CacheId::BlockHeader(hash.clone()));
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -306,7 +306,7 @@ impl BlockProvider for BlockChain {
|
|||||||
None => None
|
None => None
|
||||||
};
|
};
|
||||||
|
|
||||||
self.cache_man.lock().note_used(CacheID::BlockBody(hash.clone()));
|
self.cache_man.lock().note_used(CacheId::BlockBody(hash.clone()));
|
||||||
|
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
@ -314,28 +314,28 @@ impl BlockProvider for BlockChain {
|
|||||||
/// Get the familial details concerning a block.
|
/// Get the familial details concerning a block.
|
||||||
fn block_details(&self, hash: &H256) -> Option<BlockDetails> {
|
fn block_details(&self, hash: &H256) -> Option<BlockDetails> {
|
||||||
let result = self.db.read_with_cache(db::COL_EXTRA, &self.block_details, hash);
|
let result = self.db.read_with_cache(db::COL_EXTRA, &self.block_details, hash);
|
||||||
self.cache_man.lock().note_used(CacheID::BlockDetails(hash.clone()));
|
self.cache_man.lock().note_used(CacheId::BlockDetails(hash.clone()));
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the hash of given block's number.
|
/// Get the hash of given block's number.
|
||||||
fn block_hash(&self, index: BlockNumber) -> Option<H256> {
|
fn block_hash(&self, index: BlockNumber) -> Option<H256> {
|
||||||
let result = self.db.read_with_cache(db::COL_EXTRA, &self.block_hashes, &index);
|
let result = self.db.read_with_cache(db::COL_EXTRA, &self.block_hashes, &index);
|
||||||
self.cache_man.lock().note_used(CacheID::BlockHashes(index));
|
self.cache_man.lock().note_used(CacheId::BlockHashes(index));
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the address of transaction with given hash.
|
/// Get the address of transaction with given hash.
|
||||||
fn transaction_address(&self, hash: &H256) -> Option<TransactionAddress> {
|
fn transaction_address(&self, hash: &H256) -> Option<TransactionAddress> {
|
||||||
let result = self.db.read_with_cache(db::COL_EXTRA, &self.transaction_addresses, hash);
|
let result = self.db.read_with_cache(db::COL_EXTRA, &self.transaction_addresses, hash);
|
||||||
self.cache_man.lock().note_used(CacheID::TransactionAddresses(hash.clone()));
|
self.cache_man.lock().note_used(CacheId::TransactionAddresses(hash.clone()));
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get receipts of block with given hash.
|
/// Get receipts of block with given hash.
|
||||||
fn block_receipts(&self, hash: &H256) -> Option<BlockReceipts> {
|
fn block_receipts(&self, hash: &H256) -> Option<BlockReceipts> {
|
||||||
let result = self.db.read_with_cache(db::COL_EXTRA, &self.block_receipts, hash);
|
let result = self.db.read_with_cache(db::COL_EXTRA, &self.block_receipts, hash);
|
||||||
self.cache_man.lock().note_used(CacheID::BlockReceipts(hash.clone()));
|
self.cache_man.lock().note_used(CacheId::BlockReceipts(hash.clone()));
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -809,7 +809,7 @@ impl BlockChain {
|
|||||||
let mut write_details = self.block_details.write();
|
let mut write_details = self.block_details.write();
|
||||||
batch.extend_with_cache(db::COL_EXTRA, &mut *write_details, update, CacheUpdatePolicy::Overwrite);
|
batch.extend_with_cache(db::COL_EXTRA, &mut *write_details, update, CacheUpdatePolicy::Overwrite);
|
||||||
|
|
||||||
self.cache_man.lock().note_used(CacheID::BlockDetails(block_hash));
|
self.cache_man.lock().note_used(CacheId::BlockDetails(block_hash));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(feature="dev", allow(similar_names))]
|
#[cfg_attr(feature="dev", allow(similar_names))]
|
||||||
@ -968,15 +968,15 @@ impl BlockChain {
|
|||||||
|
|
||||||
let mut cache_man = self.cache_man.lock();
|
let mut cache_man = self.cache_man.lock();
|
||||||
for n in pending_hashes_keys {
|
for n in pending_hashes_keys {
|
||||||
cache_man.note_used(CacheID::BlockHashes(n));
|
cache_man.note_used(CacheId::BlockHashes(n));
|
||||||
}
|
}
|
||||||
|
|
||||||
for hash in enacted_txs_keys {
|
for hash in enacted_txs_keys {
|
||||||
cache_man.note_used(CacheID::TransactionAddresses(hash));
|
cache_man.note_used(CacheId::TransactionAddresses(hash));
|
||||||
}
|
}
|
||||||
|
|
||||||
for hash in pending_block_hashes {
|
for hash in pending_block_hashes {
|
||||||
cache_man.note_used(CacheID::BlockDetails(hash));
|
cache_man.note_used(CacheId::BlockDetails(hash));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1244,13 +1244,13 @@ impl BlockChain {
|
|||||||
cache_man.collect_garbage(current_size, | ids | {
|
cache_man.collect_garbage(current_size, | ids | {
|
||||||
for id in &ids {
|
for id in &ids {
|
||||||
match *id {
|
match *id {
|
||||||
CacheID::BlockHeader(ref h) => { block_headers.remove(h); },
|
CacheId::BlockHeader(ref h) => { block_headers.remove(h); },
|
||||||
CacheID::BlockBody(ref h) => { block_bodies.remove(h); },
|
CacheId::BlockBody(ref h) => { block_bodies.remove(h); },
|
||||||
CacheID::BlockDetails(ref h) => { block_details.remove(h); }
|
CacheId::BlockDetails(ref h) => { block_details.remove(h); }
|
||||||
CacheID::BlockHashes(ref h) => { block_hashes.remove(h); }
|
CacheId::BlockHashes(ref h) => { block_hashes.remove(h); }
|
||||||
CacheID::TransactionAddresses(ref h) => { transaction_addresses.remove(h); }
|
CacheId::TransactionAddresses(ref h) => { transaction_addresses.remove(h); }
|
||||||
CacheID::BlocksBlooms(ref h) => { blocks_blooms.remove(h); }
|
CacheId::BlocksBlooms(ref h) => { blocks_blooms.remove(h); }
|
||||||
CacheID::BlockReceipts(ref h) => { block_receipts.remove(h); }
|
CacheId::BlockReceipts(ref h) => { block_receipts.remove(h); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ use log_entry::LocalizedLogEntry;
|
|||||||
use verification::queue::BlockQueue;
|
use verification::queue::BlockQueue;
|
||||||
use blockchain::{BlockChain, BlockProvider, TreeRoute, ImportRoute};
|
use blockchain::{BlockChain, BlockProvider, TreeRoute, ImportRoute};
|
||||||
use client::{
|
use client::{
|
||||||
BlockID, TransactionID, UncleID, TraceId, ClientConfig, BlockChainClient,
|
BlockId, TransactionId, UncleId, TraceId, ClientConfig, BlockChainClient,
|
||||||
MiningBlockChainClient, TraceFilter, CallAnalytics, BlockImportError, Mode,
|
MiningBlockChainClient, TraceFilter, CallAnalytics, BlockImportError, Mode,
|
||||||
ChainNotify, PruningInfo,
|
ChainNotify, PruningInfo,
|
||||||
};
|
};
|
||||||
@ -580,13 +580,13 @@ impl Client {
|
|||||||
|
|
||||||
/// Attempt to get a copy of a specific block's final state.
|
/// Attempt to get a copy of a specific block's final state.
|
||||||
///
|
///
|
||||||
/// This will not fail if given BlockID::Latest.
|
/// This will not fail if given BlockId::Latest.
|
||||||
/// Otherwise, this can fail (but may not) if the DB prunes state.
|
/// Otherwise, this can fail (but may not) if the DB prunes state.
|
||||||
pub fn state_at(&self, id: BlockID) -> Option<State> {
|
pub fn state_at(&self, id: BlockId) -> Option<State> {
|
||||||
// fast path for latest state.
|
// fast path for latest state.
|
||||||
match id.clone() {
|
match id.clone() {
|
||||||
BlockID::Pending => return self.miner.pending_state().or_else(|| Some(self.state())),
|
BlockId::Pending => return self.miner.pending_state().or_else(|| Some(self.state())),
|
||||||
BlockID::Latest => return Some(self.state()),
|
BlockId::Latest => return Some(self.state()),
|
||||||
_ => {},
|
_ => {},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -611,15 +611,15 @@ impl Client {
|
|||||||
|
|
||||||
/// Attempt to get a copy of a specific block's beginning state.
|
/// Attempt to get a copy of a specific block's beginning state.
|
||||||
///
|
///
|
||||||
/// This will not fail if given BlockID::Latest.
|
/// This will not fail if given BlockId::Latest.
|
||||||
/// Otherwise, this can fail (but may not) if the DB prunes state.
|
/// Otherwise, this can fail (but may not) if the DB prunes state.
|
||||||
pub fn state_at_beginning(&self, id: BlockID) -> Option<State> {
|
pub fn state_at_beginning(&self, id: BlockId) -> Option<State> {
|
||||||
// fast path for latest state.
|
// fast path for latest state.
|
||||||
match id {
|
match id {
|
||||||
BlockID::Pending => self.state_at(BlockID::Latest),
|
BlockId::Pending => self.state_at(BlockId::Latest),
|
||||||
id => match self.block_number(id) {
|
id => match self.block_number(id) {
|
||||||
None | Some(0) => None,
|
None | Some(0) => None,
|
||||||
Some(n) => self.state_at(BlockID::Number(n - 1)),
|
Some(n) => self.state_at(BlockId::Number(n - 1)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -689,18 +689,18 @@ impl Client {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Look up the block number for the given block ID.
|
/// Look up the block number for the given block ID.
|
||||||
pub fn block_number(&self, id: BlockID) -> Option<BlockNumber> {
|
pub fn block_number(&self, id: BlockId) -> Option<BlockNumber> {
|
||||||
match id {
|
match id {
|
||||||
BlockID::Number(number) => Some(number),
|
BlockId::Number(number) => Some(number),
|
||||||
BlockID::Hash(ref hash) => self.chain.read().block_number(hash),
|
BlockId::Hash(ref hash) => self.chain.read().block_number(hash),
|
||||||
BlockID::Earliest => Some(0),
|
BlockId::Earliest => Some(0),
|
||||||
BlockID::Latest | BlockID::Pending => Some(self.chain.read().best_block_number()),
|
BlockId::Latest | BlockId::Pending => Some(self.chain.read().best_block_number()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Take a snapshot at the given block.
|
/// Take a snapshot at the given block.
|
||||||
/// If the ID given is "latest", this will default to 1000 blocks behind.
|
/// If the ID given is "latest", this will default to 1000 blocks behind.
|
||||||
pub fn take_snapshot<W: snapshot_io::SnapshotWriter + Send>(&self, writer: W, at: BlockID, p: &snapshot::Progress) -> Result<(), EthcoreError> {
|
pub fn take_snapshot<W: snapshot_io::SnapshotWriter + Send>(&self, writer: W, at: BlockId, p: &snapshot::Progress) -> Result<(), EthcoreError> {
|
||||||
let db = self.state_db.lock().journal_db().boxed_clone();
|
let db = self.state_db.lock().journal_db().boxed_clone();
|
||||||
let best_block_number = self.chain_info().best_block_number;
|
let best_block_number = self.chain_info().best_block_number;
|
||||||
let block_number = try!(self.block_number(at).ok_or(snapshot::Error::InvalidStartingBlock(at)));
|
let block_number = try!(self.block_number(at).ok_or(snapshot::Error::InvalidStartingBlock(at)));
|
||||||
@ -712,13 +712,13 @@ impl Client {
|
|||||||
let history = ::std::cmp::min(self.history, 1000);
|
let history = ::std::cmp::min(self.history, 1000);
|
||||||
|
|
||||||
let start_hash = match at {
|
let start_hash = match at {
|
||||||
BlockID::Latest => {
|
BlockId::Latest => {
|
||||||
let start_num = match db.earliest_era() {
|
let start_num = match db.earliest_era() {
|
||||||
Some(era) => ::std::cmp::max(era, best_block_number - history),
|
Some(era) => ::std::cmp::max(era, best_block_number - history),
|
||||||
None => best_block_number - history,
|
None => best_block_number - history,
|
||||||
};
|
};
|
||||||
|
|
||||||
match self.block_hash(BlockID::Number(start_num)) {
|
match self.block_hash(BlockId::Number(start_num)) {
|
||||||
Some(h) => h,
|
Some(h) => h,
|
||||||
None => return Err(snapshot::Error::InvalidStartingBlock(at).into()),
|
None => return Err(snapshot::Error::InvalidStartingBlock(at).into()),
|
||||||
}
|
}
|
||||||
@ -739,19 +739,19 @@ impl Client {
|
|||||||
self.history
|
self.history
|
||||||
}
|
}
|
||||||
|
|
||||||
fn block_hash(chain: &BlockChain, id: BlockID) -> Option<H256> {
|
fn block_hash(chain: &BlockChain, id: BlockId) -> Option<H256> {
|
||||||
match id {
|
match id {
|
||||||
BlockID::Hash(hash) => Some(hash),
|
BlockId::Hash(hash) => Some(hash),
|
||||||
BlockID::Number(number) => chain.block_hash(number),
|
BlockId::Number(number) => chain.block_hash(number),
|
||||||
BlockID::Earliest => chain.block_hash(0),
|
BlockId::Earliest => chain.block_hash(0),
|
||||||
BlockID::Latest | BlockID::Pending => Some(chain.best_block_hash()),
|
BlockId::Latest | BlockId::Pending => Some(chain.best_block_hash()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn transaction_address(&self, id: TransactionID) -> Option<TransactionAddress> {
|
fn transaction_address(&self, id: TransactionId) -> Option<TransactionAddress> {
|
||||||
match id {
|
match id {
|
||||||
TransactionID::Hash(ref hash) => self.chain.read().transaction_address(hash),
|
TransactionId::Hash(ref hash) => self.chain.read().transaction_address(hash),
|
||||||
TransactionID::Location(id, index) => Self::block_hash(&self.chain.read(), id).map(|hash| TransactionAddress {
|
TransactionId::Location(id, index) => Self::block_hash(&self.chain.read(), id).map(|hash| TransactionAddress {
|
||||||
block_hash: hash,
|
block_hash: hash,
|
||||||
index: index,
|
index: index,
|
||||||
})
|
})
|
||||||
@ -805,7 +805,7 @@ impl snapshot::DatabaseRestore for Client {
|
|||||||
|
|
||||||
|
|
||||||
impl BlockChainClient for Client {
|
impl BlockChainClient for Client {
|
||||||
fn call(&self, t: &SignedTransaction, block: BlockID, analytics: CallAnalytics) -> Result<Executed, CallError> {
|
fn call(&self, t: &SignedTransaction, block: BlockId, analytics: CallAnalytics) -> Result<Executed, CallError> {
|
||||||
let header = try!(self.block_header(block).ok_or(CallError::StatePruned));
|
let header = try!(self.block_header(block).ok_or(CallError::StatePruned));
|
||||||
let view = HeaderView::new(&header);
|
let view = HeaderView::new(&header);
|
||||||
let last_hashes = self.build_last_hashes(view.parent_hash());
|
let last_hashes = self.build_last_hashes(view.parent_hash());
|
||||||
@ -841,11 +841,11 @@ impl BlockChainClient for Client {
|
|||||||
Ok(ret)
|
Ok(ret)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn replay(&self, id: TransactionID, analytics: CallAnalytics) -> Result<Executed, CallError> {
|
fn replay(&self, id: TransactionId, analytics: CallAnalytics) -> Result<Executed, CallError> {
|
||||||
let address = try!(self.transaction_address(id).ok_or(CallError::TransactionNotFound));
|
let address = try!(self.transaction_address(id).ok_or(CallError::TransactionNotFound));
|
||||||
let header_data = try!(self.block_header(BlockID::Hash(address.block_hash)).ok_or(CallError::StatePruned));
|
let header_data = try!(self.block_header(BlockId::Hash(address.block_hash)).ok_or(CallError::StatePruned));
|
||||||
let body_data = try!(self.block_body(BlockID::Hash(address.block_hash)).ok_or(CallError::StatePruned));
|
let body_data = try!(self.block_body(BlockId::Hash(address.block_hash)).ok_or(CallError::StatePruned));
|
||||||
let mut state = try!(self.state_at_beginning(BlockID::Hash(address.block_hash)).ok_or(CallError::StatePruned));
|
let mut state = try!(self.state_at_beginning(BlockId::Hash(address.block_hash)).ok_or(CallError::StatePruned));
|
||||||
let txs = BodyView::new(&body_data).transactions();
|
let txs = BodyView::new(&body_data).transactions();
|
||||||
|
|
||||||
if address.index >= txs.len() {
|
if address.index >= txs.len() {
|
||||||
@ -918,18 +918,18 @@ impl BlockChainClient for Client {
|
|||||||
self.chain.read().best_block_header()
|
self.chain.read().best_block_header()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn block_header(&self, id: BlockID) -> Option<Bytes> {
|
fn block_header(&self, id: BlockId) -> Option<Bytes> {
|
||||||
let chain = self.chain.read();
|
let chain = self.chain.read();
|
||||||
Self::block_hash(&chain, id).and_then(|hash| chain.block_header_data(&hash))
|
Self::block_hash(&chain, id).and_then(|hash| chain.block_header_data(&hash))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn block_body(&self, id: BlockID) -> Option<Bytes> {
|
fn block_body(&self, id: BlockId) -> Option<Bytes> {
|
||||||
let chain = self.chain.read();
|
let chain = self.chain.read();
|
||||||
Self::block_hash(&chain, id).and_then(|hash| chain.block_body(&hash))
|
Self::block_hash(&chain, id).and_then(|hash| chain.block_body(&hash))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn block(&self, id: BlockID) -> Option<Bytes> {
|
fn block(&self, id: BlockId) -> Option<Bytes> {
|
||||||
if let BlockID::Pending = id {
|
if let BlockId::Pending = id {
|
||||||
if let Some(block) = self.miner.pending_block() {
|
if let Some(block) = self.miner.pending_block() {
|
||||||
return Some(block.rlp_bytes(Seal::Without));
|
return Some(block.rlp_bytes(Seal::Without));
|
||||||
}
|
}
|
||||||
@ -940,7 +940,7 @@ impl BlockChainClient for Client {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn block_status(&self, id: BlockID) -> BlockStatus {
|
fn block_status(&self, id: BlockId) -> BlockStatus {
|
||||||
let chain = self.chain.read();
|
let chain = self.chain.read();
|
||||||
match Self::block_hash(&chain, id) {
|
match Self::block_hash(&chain, id) {
|
||||||
Some(ref hash) if chain.is_known(hash) => BlockStatus::InChain,
|
Some(ref hash) if chain.is_known(hash) => BlockStatus::InChain,
|
||||||
@ -949,42 +949,42 @@ impl BlockChainClient for Client {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn block_total_difficulty(&self, id: BlockID) -> Option<U256> {
|
fn block_total_difficulty(&self, id: BlockId) -> Option<U256> {
|
||||||
if let BlockID::Pending = id {
|
if let BlockId::Pending = id {
|
||||||
if let Some(block) = self.miner.pending_block() {
|
if let Some(block) = self.miner.pending_block() {
|
||||||
return Some(*block.header.difficulty() + self.block_total_difficulty(BlockID::Latest).expect("blocks in chain have details; qed"));
|
return Some(*block.header.difficulty() + self.block_total_difficulty(BlockId::Latest).expect("blocks in chain have details; qed"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let chain = self.chain.read();
|
let chain = self.chain.read();
|
||||||
Self::block_hash(&chain, id).and_then(|hash| chain.block_details(&hash)).map(|d| d.total_difficulty)
|
Self::block_hash(&chain, id).and_then(|hash| chain.block_details(&hash)).map(|d| d.total_difficulty)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn nonce(&self, address: &Address, id: BlockID) -> Option<U256> {
|
fn nonce(&self, address: &Address, id: BlockId) -> Option<U256> {
|
||||||
self.state_at(id).map(|s| s.nonce(address))
|
self.state_at(id).map(|s| s.nonce(address))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn storage_root(&self, address: &Address, id: BlockID) -> Option<H256> {
|
fn storage_root(&self, address: &Address, id: BlockId) -> Option<H256> {
|
||||||
self.state_at(id).and_then(|s| s.storage_root(address))
|
self.state_at(id).and_then(|s| s.storage_root(address))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn block_hash(&self, id: BlockID) -> Option<H256> {
|
fn block_hash(&self, id: BlockId) -> Option<H256> {
|
||||||
let chain = self.chain.read();
|
let chain = self.chain.read();
|
||||||
Self::block_hash(&chain, id)
|
Self::block_hash(&chain, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn code(&self, address: &Address, id: BlockID) -> Option<Option<Bytes>> {
|
fn code(&self, address: &Address, id: BlockId) -> Option<Option<Bytes>> {
|
||||||
self.state_at(id).map(|s| s.code(address).map(|c| (*c).clone()))
|
self.state_at(id).map(|s| s.code(address).map(|c| (*c).clone()))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn balance(&self, address: &Address, id: BlockID) -> Option<U256> {
|
fn balance(&self, address: &Address, id: BlockId) -> Option<U256> {
|
||||||
self.state_at(id).map(|s| s.balance(address))
|
self.state_at(id).map(|s| s.balance(address))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn storage_at(&self, address: &Address, position: &H256, id: BlockID) -> Option<H256> {
|
fn storage_at(&self, address: &Address, position: &H256, id: BlockId) -> Option<H256> {
|
||||||
self.state_at(id).map(|s| s.storage_at(address, position))
|
self.state_at(id).map(|s| s.storage_at(address, position))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn list_accounts(&self, id: BlockID, after: Option<&Address>, count: u64) -> Option<Vec<Address>> {
|
fn list_accounts(&self, id: BlockId, after: Option<&Address>, count: u64) -> Option<Vec<Address>> {
|
||||||
if !self.factories.trie.is_fat() {
|
if !self.factories.trie.is_fat() {
|
||||||
trace!(target: "fatdb", "list_accounts: Not a fat DB");
|
trace!(target: "fatdb", "list_accounts: Not a fat DB");
|
||||||
return None;
|
return None;
|
||||||
@ -1022,7 +1022,7 @@ impl BlockChainClient for Client {
|
|||||||
Some(accounts)
|
Some(accounts)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn list_storage(&self, id: BlockID, account: &Address, after: Option<&H256>, count: u64) -> Option<Vec<H256>> {
|
fn list_storage(&self, id: BlockId, account: &Address, after: Option<&H256>, count: u64) -> Option<Vec<H256>> {
|
||||||
if !self.factories.trie.is_fat() {
|
if !self.factories.trie.is_fat() {
|
||||||
trace!(target: "fatdb", "list_stroage: Not a fat DB");
|
trace!(target: "fatdb", "list_stroage: Not a fat DB");
|
||||||
return None;
|
return None;
|
||||||
@ -1066,20 +1066,20 @@ impl BlockChainClient for Client {
|
|||||||
Some(keys)
|
Some(keys)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn transaction(&self, id: TransactionID) -> Option<LocalizedTransaction> {
|
fn transaction(&self, id: TransactionId) -> Option<LocalizedTransaction> {
|
||||||
self.transaction_address(id).and_then(|address| self.chain.read().transaction(&address))
|
self.transaction_address(id).and_then(|address| self.chain.read().transaction(&address))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn transaction_block(&self, id: TransactionID) -> Option<H256> {
|
fn transaction_block(&self, id: TransactionId) -> Option<H256> {
|
||||||
self.transaction_address(id).map(|addr| addr.block_hash)
|
self.transaction_address(id).map(|addr| addr.block_hash)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn uncle(&self, id: UncleID) -> Option<Bytes> {
|
fn uncle(&self, id: UncleId) -> Option<Bytes> {
|
||||||
let index = id.position;
|
let index = id.position;
|
||||||
self.block_body(id.block).and_then(|body| BodyView::new(&body).uncle_rlp_at(index))
|
self.block_body(id.block).and_then(|body| BodyView::new(&body).uncle_rlp_at(index))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn transaction_receipt(&self, id: TransactionID) -> Option<LocalizedReceipt> {
|
fn transaction_receipt(&self, id: TransactionId) -> Option<LocalizedReceipt> {
|
||||||
let chain = self.chain.read();
|
let chain = self.chain.read();
|
||||||
self.transaction_address(id)
|
self.transaction_address(id)
|
||||||
.and_then(|address| chain.block_number(&address.block_hash).and_then(|block_number| {
|
.and_then(|address| chain.block_number(&address.block_hash).and_then(|block_number| {
|
||||||
@ -1163,7 +1163,7 @@ impl BlockChainClient for Client {
|
|||||||
if self.chain.read().is_known(&unverified.hash()) {
|
if self.chain.read().is_known(&unverified.hash()) {
|
||||||
return Err(BlockImportError::Import(ImportError::AlreadyInChain));
|
return Err(BlockImportError::Import(ImportError::AlreadyInChain));
|
||||||
}
|
}
|
||||||
if self.block_status(BlockID::Hash(unverified.parent_hash())) == BlockStatus::Unknown {
|
if self.block_status(BlockId::Hash(unverified.parent_hash())) == BlockStatus::Unknown {
|
||||||
return Err(BlockImportError::Block(BlockError::UnknownParent(unverified.parent_hash())));
|
return Err(BlockImportError::Block(BlockError::UnknownParent(unverified.parent_hash())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1177,7 +1177,7 @@ impl BlockChainClient for Client {
|
|||||||
if self.chain.read().is_known(&header.hash()) {
|
if self.chain.read().is_known(&header.hash()) {
|
||||||
return Err(BlockImportError::Import(ImportError::AlreadyInChain));
|
return Err(BlockImportError::Import(ImportError::AlreadyInChain));
|
||||||
}
|
}
|
||||||
if self.block_status(BlockID::Hash(header.parent_hash())) == BlockStatus::Unknown {
|
if self.block_status(BlockId::Hash(header.parent_hash())) == BlockStatus::Unknown {
|
||||||
return Err(BlockImportError::Block(BlockError::UnknownParent(header.parent_hash())));
|
return Err(BlockImportError::Block(BlockError::UnknownParent(header.parent_hash())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1200,7 +1200,7 @@ impl BlockChainClient for Client {
|
|||||||
self.engine.additional_params().into_iter().collect()
|
self.engine.additional_params().into_iter().collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn blocks_with_bloom(&self, bloom: &H2048, from_block: BlockID, to_block: BlockID) -> Option<Vec<BlockNumber>> {
|
fn blocks_with_bloom(&self, bloom: &H2048, from_block: BlockId, to_block: BlockId) -> Option<Vec<BlockNumber>> {
|
||||||
match (self.block_number(from_block), self.block_number(to_block)) {
|
match (self.block_number(from_block), self.block_number(to_block)) {
|
||||||
(Some(from), Some(to)) => Some(self.chain.read().blocks_with_bloom(bloom, from, to)),
|
(Some(from), Some(to)) => Some(self.chain.read().blocks_with_bloom(bloom, from, to)),
|
||||||
_ => None
|
_ => None
|
||||||
@ -1242,20 +1242,20 @@ impl BlockChainClient for Client {
|
|||||||
let trace_address = trace.address;
|
let trace_address = trace.address;
|
||||||
self.transaction_address(trace.transaction)
|
self.transaction_address(trace.transaction)
|
||||||
.and_then(|tx_address| {
|
.and_then(|tx_address| {
|
||||||
self.block_number(BlockID::Hash(tx_address.block_hash))
|
self.block_number(BlockId::Hash(tx_address.block_hash))
|
||||||
.and_then(|number| self.tracedb.read().trace(number, tx_address.index, trace_address))
|
.and_then(|number| self.tracedb.read().trace(number, tx_address.index, trace_address))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn transaction_traces(&self, transaction: TransactionID) -> Option<Vec<LocalizedTrace>> {
|
fn transaction_traces(&self, transaction: TransactionId) -> Option<Vec<LocalizedTrace>> {
|
||||||
self.transaction_address(transaction)
|
self.transaction_address(transaction)
|
||||||
.and_then(|tx_address| {
|
.and_then(|tx_address| {
|
||||||
self.block_number(BlockID::Hash(tx_address.block_hash))
|
self.block_number(BlockId::Hash(tx_address.block_hash))
|
||||||
.and_then(|number| self.tracedb.read().transaction_traces(number, tx_address.index))
|
.and_then(|number| self.tracedb.read().transaction_traces(number, tx_address.index))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn block_traces(&self, block: BlockID) -> Option<Vec<LocalizedTrace>> {
|
fn block_traces(&self, block: BlockId) -> Option<Vec<LocalizedTrace>> {
|
||||||
self.block_number(block)
|
self.block_number(block)
|
||||||
.and_then(|number| self.tracedb.read().block_traces(number))
|
.and_then(|number| self.tracedb.read().block_traces(number))
|
||||||
}
|
}
|
||||||
@ -1290,13 +1290,13 @@ impl BlockChainClient for Client {
|
|||||||
self.engine.signing_network_id(&self.latest_env_info())
|
self.engine.signing_network_id(&self.latest_env_info())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn block_extra_info(&self, id: BlockID) -> Option<BTreeMap<String, String>> {
|
fn block_extra_info(&self, id: BlockId) -> Option<BTreeMap<String, String>> {
|
||||||
self.block_header(id)
|
self.block_header(id)
|
||||||
.map(|block| decode(&block))
|
.map(|block| decode(&block))
|
||||||
.map(|header| self.engine.extra_info(&header))
|
.map(|header| self.engine.extra_info(&header))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn uncle_extra_info(&self, id: UncleID) -> Option<BTreeMap<String, String>> {
|
fn uncle_extra_info(&self, id: UncleId) -> Option<BTreeMap<String, String>> {
|
||||||
self.uncle(id)
|
self.uncle(id)
|
||||||
.map(|header| self.engine.extra_info(&decode(&header)))
|
.map(|header| self.engine.extra_info(&decode(&header)))
|
||||||
}
|
}
|
||||||
@ -1392,19 +1392,19 @@ impl MayPanic for Client {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl ::client::ProvingBlockChainClient for Client {
|
impl ::client::ProvingBlockChainClient for Client {
|
||||||
fn prove_storage(&self, key1: H256, key2: H256, from_level: u32, id: BlockID) -> Vec<Bytes> {
|
fn prove_storage(&self, key1: H256, key2: H256, from_level: u32, id: BlockId) -> Vec<Bytes> {
|
||||||
self.state_at(id)
|
self.state_at(id)
|
||||||
.and_then(move |state| state.prove_storage(key1, key2, from_level).ok())
|
.and_then(move |state| state.prove_storage(key1, key2, from_level).ok())
|
||||||
.unwrap_or_else(Vec::new)
|
.unwrap_or_else(Vec::new)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn prove_account(&self, key1: H256, from_level: u32, id: BlockID) -> Vec<Bytes> {
|
fn prove_account(&self, key1: H256, from_level: u32, id: BlockId) -> Vec<Bytes> {
|
||||||
self.state_at(id)
|
self.state_at(id)
|
||||||
.and_then(move |state| state.prove_account(key1, from_level).ok())
|
.and_then(move |state| state.prove_account(key1, from_level).ok())
|
||||||
.unwrap_or_else(Vec::new)
|
.unwrap_or_else(Vec::new)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn code_by_hash(&self, account_key: H256, id: BlockID) -> Bytes {
|
fn code_by_hash(&self, account_key: H256, id: BlockId) -> Bytes {
|
||||||
self.state_at(id)
|
self.state_at(id)
|
||||||
.and_then(move |state| state.code_by_address_hash(account_key).ok())
|
.and_then(move |state| state.code_by_address_hash(account_key).ok())
|
||||||
.and_then(|x| x)
|
.and_then(|x| x)
|
||||||
|
@ -24,8 +24,8 @@ use devtools::*;
|
|||||||
use transaction::{Transaction, LocalizedTransaction, SignedTransaction, Action};
|
use transaction::{Transaction, LocalizedTransaction, SignedTransaction, Action};
|
||||||
use blockchain::TreeRoute;
|
use blockchain::TreeRoute;
|
||||||
use client::{
|
use client::{
|
||||||
BlockChainClient, MiningBlockChainClient, BlockChainInfo, BlockStatus, BlockID,
|
BlockChainClient, MiningBlockChainClient, BlockChainInfo, BlockStatus, BlockId,
|
||||||
TransactionID, UncleID, TraceId, TraceFilter, LastHashes, CallAnalytics, BlockImportError,
|
TransactionId, UncleId, TraceId, TraceFilter, LastHashes, CallAnalytics, BlockImportError,
|
||||||
};
|
};
|
||||||
use db::{NUM_COLUMNS, COL_STATE};
|
use db::{NUM_COLUMNS, COL_STATE};
|
||||||
use header::{Header as BlockHeader, BlockNumber};
|
use header::{Header as BlockHeader, BlockNumber};
|
||||||
@ -73,7 +73,7 @@ pub struct TestBlockChainClient {
|
|||||||
/// Execution result.
|
/// Execution result.
|
||||||
pub execution_result: RwLock<Option<Result<Executed, CallError>>>,
|
pub execution_result: RwLock<Option<Result<Executed, CallError>>>,
|
||||||
/// Transaction receipts.
|
/// Transaction receipts.
|
||||||
pub receipts: RwLock<HashMap<TransactionID, LocalizedReceipt>>,
|
pub receipts: RwLock<HashMap<TransactionId, LocalizedReceipt>>,
|
||||||
/// Logs
|
/// Logs
|
||||||
pub logs: RwLock<Vec<LocalizedLogEntry>>,
|
pub logs: RwLock<Vec<LocalizedLogEntry>>,
|
||||||
/// Block queue size.
|
/// Block queue size.
|
||||||
@ -158,7 +158,7 @@ impl TestBlockChainClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Set the transaction receipt result
|
/// Set the transaction receipt result
|
||||||
pub fn set_transaction_receipt(&self, id: TransactionID, receipt: LocalizedReceipt) {
|
pub fn set_transaction_receipt(&self, id: TransactionId, receipt: LocalizedReceipt) {
|
||||||
self.receipts.write().insert(id, receipt);
|
self.receipts.write().insert(id, receipt);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -256,8 +256,8 @@ impl TestBlockChainClient {
|
|||||||
|
|
||||||
/// Make a bad block by setting invalid extra data.
|
/// Make a bad block by setting invalid extra data.
|
||||||
pub fn corrupt_block(&self, n: BlockNumber) {
|
pub fn corrupt_block(&self, n: BlockNumber) {
|
||||||
let hash = self.block_hash(BlockID::Number(n)).unwrap();
|
let hash = self.block_hash(BlockId::Number(n)).unwrap();
|
||||||
let mut header: BlockHeader = decode(&self.block_header(BlockID::Number(n)).unwrap());
|
let mut header: BlockHeader = decode(&self.block_header(BlockId::Number(n)).unwrap());
|
||||||
header.set_extra_data(b"This extra data is way too long to be considered valid".to_vec());
|
header.set_extra_data(b"This extra data is way too long to be considered valid".to_vec());
|
||||||
let mut rlp = RlpStream::new_list(3);
|
let mut rlp = RlpStream::new_list(3);
|
||||||
rlp.append(&header);
|
rlp.append(&header);
|
||||||
@ -268,8 +268,8 @@ impl TestBlockChainClient {
|
|||||||
|
|
||||||
/// Make a bad block by setting invalid parent hash.
|
/// Make a bad block by setting invalid parent hash.
|
||||||
pub fn corrupt_block_parent(&self, n: BlockNumber) {
|
pub fn corrupt_block_parent(&self, n: BlockNumber) {
|
||||||
let hash = self.block_hash(BlockID::Number(n)).unwrap();
|
let hash = self.block_hash(BlockId::Number(n)).unwrap();
|
||||||
let mut header: BlockHeader = decode(&self.block_header(BlockID::Number(n)).unwrap());
|
let mut header: BlockHeader = decode(&self.block_header(BlockId::Number(n)).unwrap());
|
||||||
header.set_parent_hash(H256::from(42));
|
header.set_parent_hash(H256::from(42));
|
||||||
let mut rlp = RlpStream::new_list(3);
|
let mut rlp = RlpStream::new_list(3);
|
||||||
rlp.append(&header);
|
rlp.append(&header);
|
||||||
@ -285,12 +285,12 @@ impl TestBlockChainClient {
|
|||||||
blocks_read[&index].clone()
|
blocks_read[&index].clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn block_hash(&self, id: BlockID) -> Option<H256> {
|
fn block_hash(&self, id: BlockId) -> Option<H256> {
|
||||||
match id {
|
match id {
|
||||||
BlockID::Hash(hash) => Some(hash),
|
BlockId::Hash(hash) => Some(hash),
|
||||||
BlockID::Number(n) => self.numbers.read().get(&(n as usize)).cloned(),
|
BlockId::Number(n) => self.numbers.read().get(&(n as usize)).cloned(),
|
||||||
BlockID::Earliest => self.numbers.read().get(&0).cloned(),
|
BlockId::Earliest => self.numbers.read().get(&0).cloned(),
|
||||||
BlockID::Latest | BlockID::Pending => self.numbers.read().get(&(self.numbers.read().len() - 1)).cloned()
|
BlockId::Latest | BlockId::Pending => self.numbers.read().get(&(self.numbers.read().len() - 1)).cloned()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -363,46 +363,46 @@ impl MiningBlockChainClient for TestBlockChainClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl BlockChainClient for TestBlockChainClient {
|
impl BlockChainClient for TestBlockChainClient {
|
||||||
fn call(&self, _t: &SignedTransaction, _block: BlockID, _analytics: CallAnalytics) -> Result<Executed, CallError> {
|
fn call(&self, _t: &SignedTransaction, _block: BlockId, _analytics: CallAnalytics) -> Result<Executed, CallError> {
|
||||||
self.execution_result.read().clone().unwrap()
|
self.execution_result.read().clone().unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn replay(&self, _id: TransactionID, _analytics: CallAnalytics) -> Result<Executed, CallError> {
|
fn replay(&self, _id: TransactionId, _analytics: CallAnalytics) -> Result<Executed, CallError> {
|
||||||
self.execution_result.read().clone().unwrap()
|
self.execution_result.read().clone().unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn block_total_difficulty(&self, _id: BlockID) -> Option<U256> {
|
fn block_total_difficulty(&self, _id: BlockId) -> Option<U256> {
|
||||||
Some(U256::zero())
|
Some(U256::zero())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn block_hash(&self, id: BlockID) -> Option<H256> {
|
fn block_hash(&self, id: BlockId) -> Option<H256> {
|
||||||
Self::block_hash(self, id)
|
Self::block_hash(self, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn nonce(&self, address: &Address, id: BlockID) -> Option<U256> {
|
fn nonce(&self, address: &Address, id: BlockId) -> Option<U256> {
|
||||||
match id {
|
match id {
|
||||||
BlockID::Latest => Some(self.nonces.read().get(address).cloned().unwrap_or(self.spec.params.account_start_nonce)),
|
BlockId::Latest => Some(self.nonces.read().get(address).cloned().unwrap_or(self.spec.params.account_start_nonce)),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn storage_root(&self, _address: &Address, _id: BlockID) -> Option<H256> {
|
fn storage_root(&self, _address: &Address, _id: BlockId) -> Option<H256> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
fn latest_nonce(&self, address: &Address) -> U256 {
|
fn latest_nonce(&self, address: &Address) -> U256 {
|
||||||
self.nonce(address, BlockID::Latest).unwrap()
|
self.nonce(address, BlockId::Latest).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn code(&self, address: &Address, id: BlockID) -> Option<Option<Bytes>> {
|
fn code(&self, address: &Address, id: BlockId) -> Option<Option<Bytes>> {
|
||||||
match id {
|
match id {
|
||||||
BlockID::Latest => Some(self.code.read().get(address).cloned()),
|
BlockId::Latest => Some(self.code.read().get(address).cloned()),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn balance(&self, address: &Address, id: BlockID) -> Option<U256> {
|
fn balance(&self, address: &Address, id: BlockId) -> Option<U256> {
|
||||||
if let BlockID::Latest = id {
|
if let BlockId::Latest = id {
|
||||||
Some(self.balances.read().get(address).cloned().unwrap_or_else(U256::zero))
|
Some(self.balances.read().get(address).cloned().unwrap_or_else(U256::zero))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
@ -410,45 +410,45 @@ impl BlockChainClient for TestBlockChainClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn latest_balance(&self, address: &Address) -> U256 {
|
fn latest_balance(&self, address: &Address) -> U256 {
|
||||||
self.balance(address, BlockID::Latest).unwrap()
|
self.balance(address, BlockId::Latest).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn storage_at(&self, address: &Address, position: &H256, id: BlockID) -> Option<H256> {
|
fn storage_at(&self, address: &Address, position: &H256, id: BlockId) -> Option<H256> {
|
||||||
if let BlockID::Latest = id {
|
if let BlockId::Latest = id {
|
||||||
Some(self.storage.read().get(&(address.clone(), position.clone())).cloned().unwrap_or_else(H256::new))
|
Some(self.storage.read().get(&(address.clone(), position.clone())).cloned().unwrap_or_else(H256::new))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn list_accounts(&self, _id: BlockID, _after: Option<&Address>, _count: u64) -> Option<Vec<Address>> {
|
fn list_accounts(&self, _id: BlockId, _after: Option<&Address>, _count: u64) -> Option<Vec<Address>> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
fn list_storage(&self, _id: BlockID, _account: &Address, _after: Option<&H256>, _count: u64) -> Option<Vec<H256>> {
|
fn list_storage(&self, _id: BlockId, _account: &Address, _after: Option<&H256>, _count: u64) -> Option<Vec<H256>> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
fn transaction(&self, _id: TransactionID) -> Option<LocalizedTransaction> {
|
fn transaction(&self, _id: TransactionId) -> Option<LocalizedTransaction> {
|
||||||
None // Simple default.
|
None // Simple default.
|
||||||
}
|
}
|
||||||
|
|
||||||
fn transaction_block(&self, _id: TransactionID) -> Option<H256> {
|
fn transaction_block(&self, _id: TransactionId) -> Option<H256> {
|
||||||
None // Simple default.
|
None // Simple default.
|
||||||
}
|
}
|
||||||
|
|
||||||
fn uncle(&self, _id: UncleID) -> Option<Bytes> {
|
fn uncle(&self, _id: UncleId) -> Option<Bytes> {
|
||||||
None // Simple default.
|
None // Simple default.
|
||||||
}
|
}
|
||||||
|
|
||||||
fn uncle_extra_info(&self, _id: UncleID) -> Option<BTreeMap<String, String>> {
|
fn uncle_extra_info(&self, _id: UncleId) -> Option<BTreeMap<String, String>> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
fn transaction_receipt(&self, id: TransactionID) -> Option<LocalizedReceipt> {
|
fn transaction_receipt(&self, id: TransactionId) -> Option<LocalizedReceipt> {
|
||||||
self.receipts.read().get(&id).cloned()
|
self.receipts.read().get(&id).cloned()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn blocks_with_bloom(&self, _bloom: &H2048, _from_block: BlockID, _to_block: BlockID) -> Option<Vec<BlockNumber>> {
|
fn blocks_with_bloom(&self, _bloom: &H2048, _from_block: BlockId, _to_block: BlockId) -> Option<Vec<BlockNumber>> {
|
||||||
unimplemented!();
|
unimplemented!();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -466,14 +466,14 @@ impl BlockChainClient for TestBlockChainClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn best_block_header(&self) -> Bytes {
|
fn best_block_header(&self) -> Bytes {
|
||||||
self.block_header(BlockID::Hash(self.chain_info().best_block_hash)).expect("Best block always have header.")
|
self.block_header(BlockId::Hash(self.chain_info().best_block_hash)).expect("Best block always have header.")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn block_header(&self, id: BlockID) -> Option<Bytes> {
|
fn block_header(&self, id: BlockId) -> Option<Bytes> {
|
||||||
self.block_hash(id).and_then(|hash| self.blocks.read().get(&hash).map(|r| Rlp::new(r).at(0).as_raw().to_vec()))
|
self.block_hash(id).and_then(|hash| self.blocks.read().get(&hash).map(|r| Rlp::new(r).at(0).as_raw().to_vec()))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn block_body(&self, id: BlockID) -> Option<Bytes> {
|
fn block_body(&self, id: BlockId) -> Option<Bytes> {
|
||||||
self.block_hash(id).and_then(|hash| self.blocks.read().get(&hash).map(|r| {
|
self.block_hash(id).and_then(|hash| self.blocks.read().get(&hash).map(|r| {
|
||||||
let mut stream = RlpStream::new_list(2);
|
let mut stream = RlpStream::new_list(2);
|
||||||
stream.append_raw(Rlp::new(r).at(1).as_raw(), 1);
|
stream.append_raw(Rlp::new(r).at(1).as_raw(), 1);
|
||||||
@ -482,21 +482,21 @@ impl BlockChainClient for TestBlockChainClient {
|
|||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn block(&self, id: BlockID) -> Option<Bytes> {
|
fn block(&self, id: BlockId) -> Option<Bytes> {
|
||||||
self.block_hash(id).and_then(|hash| self.blocks.read().get(&hash).cloned())
|
self.block_hash(id).and_then(|hash| self.blocks.read().get(&hash).cloned())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn block_extra_info(&self, id: BlockID) -> Option<BTreeMap<String, String>> {
|
fn block_extra_info(&self, id: BlockId) -> Option<BTreeMap<String, String>> {
|
||||||
self.block(id)
|
self.block(id)
|
||||||
.map(|block| BlockView::new(&block).header())
|
.map(|block| BlockView::new(&block).header())
|
||||||
.map(|header| self.spec.engine.extra_info(&header))
|
.map(|header| self.spec.engine.extra_info(&header))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fn block_status(&self, id: BlockID) -> BlockStatus {
|
fn block_status(&self, id: BlockId) -> BlockStatus {
|
||||||
match id {
|
match id {
|
||||||
BlockID::Number(number) if (number as usize) < self.blocks.read().len() => BlockStatus::InChain,
|
BlockId::Number(number) if (number as usize) < self.blocks.read().len() => BlockStatus::InChain,
|
||||||
BlockID::Hash(ref hash) if self.blocks.read().get(hash).is_some() => BlockStatus::InChain,
|
BlockId::Hash(ref hash) if self.blocks.read().get(hash).is_some() => BlockStatus::InChain,
|
||||||
_ => BlockStatus::Unknown
|
_ => BlockStatus::Unknown
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -649,11 +649,11 @@ impl BlockChainClient for TestBlockChainClient {
|
|||||||
unimplemented!();
|
unimplemented!();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn transaction_traces(&self, _trace: TransactionID) -> Option<Vec<LocalizedTrace>> {
|
fn transaction_traces(&self, _trace: TransactionId) -> Option<Vec<LocalizedTrace>> {
|
||||||
unimplemented!();
|
unimplemented!();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn block_traces(&self, _trace: BlockID) -> Option<Vec<LocalizedTrace>> {
|
fn block_traces(&self, _trace: BlockId) -> Option<Vec<LocalizedTrace>> {
|
||||||
unimplemented!();
|
unimplemented!();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,93 +50,93 @@ pub trait BlockChainClient : Sync + Send {
|
|||||||
fn keep_alive(&self) {}
|
fn keep_alive(&self) {}
|
||||||
|
|
||||||
/// Get raw block header data by block id.
|
/// Get raw block header data by block id.
|
||||||
fn block_header(&self, id: BlockID) -> Option<Bytes>;
|
fn block_header(&self, id: BlockId) -> Option<Bytes>;
|
||||||
|
|
||||||
/// Get raw block body data by block id.
|
/// Get raw block body data by block id.
|
||||||
/// Block body is an RLP list of two items: uncles and transactions.
|
/// Block body is an RLP list of two items: uncles and transactions.
|
||||||
fn block_body(&self, id: BlockID) -> Option<Bytes>;
|
fn block_body(&self, id: BlockId) -> Option<Bytes>;
|
||||||
|
|
||||||
/// Get raw block data by block header hash.
|
/// Get raw block data by block header hash.
|
||||||
fn block(&self, id: BlockID) -> Option<Bytes>;
|
fn block(&self, id: BlockId) -> Option<Bytes>;
|
||||||
|
|
||||||
/// Get block status by block header hash.
|
/// Get block status by block header hash.
|
||||||
fn block_status(&self, id: BlockID) -> BlockStatus;
|
fn block_status(&self, id: BlockId) -> BlockStatus;
|
||||||
|
|
||||||
/// Get block total difficulty.
|
/// Get block total difficulty.
|
||||||
fn block_total_difficulty(&self, id: BlockID) -> Option<U256>;
|
fn block_total_difficulty(&self, id: BlockId) -> Option<U256>;
|
||||||
|
|
||||||
/// Attempt to get address nonce at given block.
|
/// Attempt to get address nonce at given block.
|
||||||
/// May not fail on BlockID::Latest.
|
/// May not fail on BlockId::Latest.
|
||||||
fn nonce(&self, address: &Address, id: BlockID) -> Option<U256>;
|
fn nonce(&self, address: &Address, id: BlockId) -> Option<U256>;
|
||||||
|
|
||||||
/// Attempt to get address storage root at given block.
|
/// Attempt to get address storage root at given block.
|
||||||
/// May not fail on BlockID::Latest.
|
/// May not fail on BlockId::Latest.
|
||||||
fn storage_root(&self, address: &Address, id: BlockID) -> Option<H256>;
|
fn storage_root(&self, address: &Address, id: BlockId) -> Option<H256>;
|
||||||
|
|
||||||
/// Get address nonce at the latest block's state.
|
/// Get address nonce at the latest block's state.
|
||||||
fn latest_nonce(&self, address: &Address) -> U256 {
|
fn latest_nonce(&self, address: &Address) -> U256 {
|
||||||
self.nonce(address, BlockID::Latest)
|
self.nonce(address, BlockId::Latest)
|
||||||
.expect("nonce will return Some when given BlockID::Latest. nonce was given BlockID::Latest. \
|
.expect("nonce will return Some when given BlockId::Latest. nonce was given BlockId::Latest. \
|
||||||
Therefore nonce has returned Some; qed")
|
Therefore nonce has returned Some; qed")
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get block hash.
|
/// Get block hash.
|
||||||
fn block_hash(&self, id: BlockID) -> Option<H256>;
|
fn block_hash(&self, id: BlockId) -> Option<H256>;
|
||||||
|
|
||||||
/// Get address code at given block's state.
|
/// Get address code at given block's state.
|
||||||
fn code(&self, address: &Address, id: BlockID) -> Option<Option<Bytes>>;
|
fn code(&self, address: &Address, id: BlockId) -> Option<Option<Bytes>>;
|
||||||
|
|
||||||
/// Get address code at the latest block's state.
|
/// Get address code at the latest block's state.
|
||||||
fn latest_code(&self, address: &Address) -> Option<Bytes> {
|
fn latest_code(&self, address: &Address) -> Option<Bytes> {
|
||||||
self.code(address, BlockID::Latest)
|
self.code(address, BlockId::Latest)
|
||||||
.expect("code will return Some if given BlockID::Latest; qed")
|
.expect("code will return Some if given BlockId::Latest; qed")
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get address balance at the given block's state.
|
/// Get address balance at the given block's state.
|
||||||
///
|
///
|
||||||
/// May not return None if given BlockID::Latest.
|
/// May not return None if given BlockId::Latest.
|
||||||
/// Returns None if and only if the block's root hash has been pruned from the DB.
|
/// Returns None if and only if the block's root hash has been pruned from the DB.
|
||||||
fn balance(&self, address: &Address, id: BlockID) -> Option<U256>;
|
fn balance(&self, address: &Address, id: BlockId) -> Option<U256>;
|
||||||
|
|
||||||
/// Get address balance at the latest block's state.
|
/// Get address balance at the latest block's state.
|
||||||
fn latest_balance(&self, address: &Address) -> U256 {
|
fn latest_balance(&self, address: &Address) -> U256 {
|
||||||
self.balance(address, BlockID::Latest)
|
self.balance(address, BlockId::Latest)
|
||||||
.expect("balance will return Some if given BlockID::Latest. balance was given BlockID::Latest \
|
.expect("balance will return Some if given BlockId::Latest. balance was given BlockId::Latest \
|
||||||
Therefore balance has returned Some; qed")
|
Therefore balance has returned Some; qed")
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get value of the storage at given position at the given block's state.
|
/// Get value of the storage at given position at the given block's state.
|
||||||
///
|
///
|
||||||
/// May not return None if given BlockID::Latest.
|
/// May not return None if given BlockId::Latest.
|
||||||
/// Returns None if and only if the block's root hash has been pruned from the DB.
|
/// Returns None if and only if the block's root hash has been pruned from the DB.
|
||||||
fn storage_at(&self, address: &Address, position: &H256, id: BlockID) -> Option<H256>;
|
fn storage_at(&self, address: &Address, position: &H256, id: BlockId) -> Option<H256>;
|
||||||
|
|
||||||
/// Get value of the storage at given position at the latest block's state.
|
/// Get value of the storage at given position at the latest block's state.
|
||||||
fn latest_storage_at(&self, address: &Address, position: &H256) -> H256 {
|
fn latest_storage_at(&self, address: &Address, position: &H256) -> H256 {
|
||||||
self.storage_at(address, position, BlockID::Latest)
|
self.storage_at(address, position, BlockId::Latest)
|
||||||
.expect("storage_at will return Some if given BlockID::Latest. storage_at was given BlockID::Latest. \
|
.expect("storage_at will return Some if given BlockId::Latest. storage_at was given BlockId::Latest. \
|
||||||
Therefore storage_at has returned Some; qed")
|
Therefore storage_at has returned Some; qed")
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get a list of all accounts in the block `id`, if fat DB is in operation, otherwise `None`.
|
/// Get a list of all accounts in the block `id`, if fat DB is in operation, otherwise `None`.
|
||||||
/// If `after` is set the list starts with the following item.
|
/// If `after` is set the list starts with the following item.
|
||||||
fn list_accounts(&self, id: BlockID, after: Option<&Address>, count: u64) -> Option<Vec<Address>>;
|
fn list_accounts(&self, id: BlockId, after: Option<&Address>, count: u64) -> Option<Vec<Address>>;
|
||||||
|
|
||||||
/// Get a list of all storage keys in the block `id`, if fat DB is in operation, otherwise `None`.
|
/// Get a list of all storage keys in the block `id`, if fat DB is in operation, otherwise `None`.
|
||||||
/// If `after` is set the list starts with the following item.
|
/// If `after` is set the list starts with the following item.
|
||||||
fn list_storage(&self, id: BlockID, account: &Address, after: Option<&H256>, count: u64) -> Option<Vec<H256>>;
|
fn list_storage(&self, id: BlockId, account: &Address, after: Option<&H256>, count: u64) -> Option<Vec<H256>>;
|
||||||
|
|
||||||
/// Get transaction with given hash.
|
/// Get transaction with given hash.
|
||||||
fn transaction(&self, id: TransactionID) -> Option<LocalizedTransaction>;
|
fn transaction(&self, id: TransactionId) -> Option<LocalizedTransaction>;
|
||||||
|
|
||||||
/// Get the hash of block that contains the transaction, if any.
|
/// Get the hash of block that contains the transaction, if any.
|
||||||
fn transaction_block(&self, id: TransactionID) -> Option<H256>;
|
fn transaction_block(&self, id: TransactionId) -> Option<H256>;
|
||||||
|
|
||||||
/// Get uncle with given id.
|
/// Get uncle with given id.
|
||||||
fn uncle(&self, id: UncleID) -> Option<Bytes>;
|
fn uncle(&self, id: UncleId) -> Option<Bytes>;
|
||||||
|
|
||||||
/// Get transaction receipt with given hash.
|
/// Get transaction receipt with given hash.
|
||||||
fn transaction_receipt(&self, id: TransactionID) -> Option<LocalizedReceipt>;
|
fn transaction_receipt(&self, id: TransactionId) -> Option<LocalizedReceipt>;
|
||||||
|
|
||||||
/// Get a tree route between `from` and `to`.
|
/// Get a tree route between `from` and `to`.
|
||||||
/// See `BlockChain::tree_route`.
|
/// See `BlockChain::tree_route`.
|
||||||
@ -173,16 +173,16 @@ pub trait BlockChainClient : Sync + Send {
|
|||||||
fn best_block_header(&self) -> Bytes;
|
fn best_block_header(&self) -> Bytes;
|
||||||
|
|
||||||
/// Returns numbers of blocks containing given bloom.
|
/// Returns numbers of blocks containing given bloom.
|
||||||
fn blocks_with_bloom(&self, bloom: &H2048, from_block: BlockID, to_block: BlockID) -> Option<Vec<BlockNumber>>;
|
fn blocks_with_bloom(&self, bloom: &H2048, from_block: BlockId, to_block: BlockId) -> Option<Vec<BlockNumber>>;
|
||||||
|
|
||||||
/// Returns logs matching given filter.
|
/// Returns logs matching given filter.
|
||||||
fn logs(&self, filter: Filter) -> Vec<LocalizedLogEntry>;
|
fn logs(&self, filter: Filter) -> Vec<LocalizedLogEntry>;
|
||||||
|
|
||||||
/// Makes a non-persistent transaction call.
|
/// Makes a non-persistent transaction call.
|
||||||
fn call(&self, t: &SignedTransaction, block: BlockID, analytics: CallAnalytics) -> Result<Executed, CallError>;
|
fn call(&self, t: &SignedTransaction, block: BlockId, analytics: CallAnalytics) -> Result<Executed, CallError>;
|
||||||
|
|
||||||
/// Replays a given transaction for inspection.
|
/// Replays a given transaction for inspection.
|
||||||
fn replay(&self, t: TransactionID, analytics: CallAnalytics) -> Result<Executed, CallError>;
|
fn replay(&self, t: TransactionId, analytics: CallAnalytics) -> Result<Executed, CallError>;
|
||||||
|
|
||||||
/// Returns traces matching given filter.
|
/// Returns traces matching given filter.
|
||||||
fn filter_traces(&self, filter: TraceFilter) -> Option<Vec<LocalizedTrace>>;
|
fn filter_traces(&self, filter: TraceFilter) -> Option<Vec<LocalizedTrace>>;
|
||||||
@ -191,10 +191,10 @@ pub trait BlockChainClient : Sync + Send {
|
|||||||
fn trace(&self, trace: TraceId) -> Option<LocalizedTrace>;
|
fn trace(&self, trace: TraceId) -> Option<LocalizedTrace>;
|
||||||
|
|
||||||
/// Returns traces created by transaction.
|
/// Returns traces created by transaction.
|
||||||
fn transaction_traces(&self, trace: TransactionID) -> Option<Vec<LocalizedTrace>>;
|
fn transaction_traces(&self, trace: TransactionId) -> Option<Vec<LocalizedTrace>>;
|
||||||
|
|
||||||
/// Returns traces created by transaction from block.
|
/// Returns traces created by transaction from block.
|
||||||
fn block_traces(&self, trace: BlockID) -> Option<Vec<LocalizedTrace>>;
|
fn block_traces(&self, trace: BlockId) -> Option<Vec<LocalizedTrace>>;
|
||||||
|
|
||||||
/// Get last hashes starting from best block.
|
/// Get last hashes starting from best block.
|
||||||
fn last_hashes(&self) -> LastHashes;
|
fn last_hashes(&self) -> LastHashes;
|
||||||
@ -211,7 +211,7 @@ pub trait BlockChainClient : Sync + Send {
|
|||||||
let mut corpus = Vec::new();
|
let mut corpus = Vec::new();
|
||||||
while corpus.is_empty() {
|
while corpus.is_empty() {
|
||||||
for _ in 0..sample_size {
|
for _ in 0..sample_size {
|
||||||
let block_bytes = self.block(BlockID::Hash(h)).expect("h is either the best_block_hash or an ancestor; qed");
|
let block_bytes = self.block(BlockId::Hash(h)).expect("h is either the best_block_hash or an ancestor; qed");
|
||||||
let block = BlockView::new(&block_bytes);
|
let block = BlockView::new(&block_bytes);
|
||||||
let header = block.header_view();
|
let header = block.header_view();
|
||||||
if header.number() == 0 {
|
if header.number() == 0 {
|
||||||
@ -249,11 +249,11 @@ pub trait BlockChainClient : Sync + Send {
|
|||||||
/// Set the mode.
|
/// Set the mode.
|
||||||
fn set_mode(&self, mode: Mode);
|
fn set_mode(&self, mode: Mode);
|
||||||
|
|
||||||
/// Returns engine-related extra info for `BlockID`.
|
/// Returns engine-related extra info for `BlockId`.
|
||||||
fn block_extra_info(&self, id: BlockID) -> Option<BTreeMap<String, String>>;
|
fn block_extra_info(&self, id: BlockId) -> Option<BTreeMap<String, String>>;
|
||||||
|
|
||||||
/// Returns engine-related extra info for `UncleID`.
|
/// Returns engine-related extra info for `UncleId`.
|
||||||
fn uncle_extra_info(&self, id: UncleID) -> Option<BTreeMap<String, String>>;
|
fn uncle_extra_info(&self, id: UncleId) -> Option<BTreeMap<String, String>>;
|
||||||
|
|
||||||
/// Returns information about pruning/data availability.
|
/// Returns information about pruning/data availability.
|
||||||
fn pruning_info(&self) -> PruningInfo;
|
fn pruning_info(&self) -> PruningInfo;
|
||||||
@ -288,15 +288,15 @@ pub trait ProvingBlockChainClient: BlockChainClient {
|
|||||||
/// Returns a vector of raw trie nodes (in order from the root) proving the storage query.
|
/// Returns a vector of raw trie nodes (in order from the root) proving the storage query.
|
||||||
/// Nodes after `from_level` may be omitted.
|
/// Nodes after `from_level` may be omitted.
|
||||||
/// An empty vector indicates unservable query.
|
/// An empty vector indicates unservable query.
|
||||||
fn prove_storage(&self, key1: H256, key2: H256, from_level: u32, id: BlockID) -> Vec<Bytes>;
|
fn prove_storage(&self, key1: H256, key2: H256, from_level: u32, id: BlockId) -> Vec<Bytes>;
|
||||||
|
|
||||||
/// Prove account existence at a specific block id.
|
/// Prove account existence at a specific block id.
|
||||||
/// The key is the keccak hash of the account's address.
|
/// The key is the keccak hash of the account's address.
|
||||||
/// Returns a vector of raw trie nodes (in order from the root) proving the query.
|
/// Returns a vector of raw trie nodes (in order from the root) proving the query.
|
||||||
/// Nodes after `from_level` may be omitted.
|
/// Nodes after `from_level` may be omitted.
|
||||||
/// An empty vector indicates unservable query.
|
/// An empty vector indicates unservable query.
|
||||||
fn prove_account(&self, key1: H256, from_level: u32, id: BlockID) -> Vec<Bytes>;
|
fn prove_account(&self, key1: H256, from_level: u32, id: BlockId) -> Vec<Bytes>;
|
||||||
|
|
||||||
/// Get code by address hash.
|
/// Get code by address hash.
|
||||||
fn code_by_hash(&self, account_key: H256, id: BlockID) -> Bytes;
|
fn code_by_hash(&self, account_key: H256, id: BlockId) -> Bytes;
|
||||||
}
|
}
|
@ -347,7 +347,6 @@ mod tests {
|
|||||||
use tests::helpers::*;
|
use tests::helpers::*;
|
||||||
use account_provider::AccountProvider;
|
use account_provider::AccountProvider;
|
||||||
use spec::Spec;
|
use spec::Spec;
|
||||||
use std::time::UNIX_EPOCH;
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn has_valid_metadata() {
|
fn has_valid_metadata() {
|
||||||
@ -442,13 +441,30 @@ mod tests {
|
|||||||
let engine = Spec::new_test_round().engine;
|
let engine = Spec::new_test_round().engine;
|
||||||
|
|
||||||
let signature = tap.sign(addr, Some("0".into()), header.bare_hash()).unwrap();
|
let signature = tap.sign(addr, Some("0".into()), header.bare_hash()).unwrap();
|
||||||
let time = UNIX_EPOCH.elapsed().unwrap().as_secs();
|
|
||||||
// Two authorities.
|
// Two authorities.
|
||||||
let mut step = time - time % 2;
|
// Spec starts with step 2.
|
||||||
header.set_seal(vec![encode(&step).to_vec(), encode(&(&*signature as &[u8])).to_vec()]);
|
header.set_seal(vec![encode(&2usize).to_vec(), encode(&(&*signature as &[u8])).to_vec()]);
|
||||||
assert!(engine.verify_block_seal(&header).is_err());
|
assert!(engine.verify_block_seal(&header).is_err());
|
||||||
step = step + 1;
|
header.set_seal(vec![encode(&1usize).to_vec(), encode(&(&*signature as &[u8])).to_vec()]);
|
||||||
header.set_seal(vec![encode(&step).to_vec(), encode(&(&*signature as &[u8])).to_vec()]);
|
|
||||||
assert!(engine.verify_block_seal(&header).is_ok());
|
assert!(engine.verify_block_seal(&header).is_ok());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn rejects_future_block() {
|
||||||
|
let mut header: Header = Header::default();
|
||||||
|
let tap = AccountProvider::transient_provider();
|
||||||
|
let addr = tap.insert_account("0".sha3(), "0").unwrap();
|
||||||
|
|
||||||
|
header.set_author(addr);
|
||||||
|
|
||||||
|
let engine = Spec::new_test_round().engine;
|
||||||
|
|
||||||
|
let signature = tap.sign(addr, Some("0".into()), header.bare_hash()).unwrap();
|
||||||
|
// Two authorities.
|
||||||
|
// Spec starts with step 2.
|
||||||
|
header.set_seal(vec![encode(&1usize).to_vec(), encode(&(&*signature as &[u8])).to_vec()]);
|
||||||
|
assert!(engine.verify_block_seal(&header).is_ok());
|
||||||
|
header.set_seal(vec![encode(&5usize).to_vec(), encode(&(&*signature as &[u8])).to_vec()]);
|
||||||
|
assert!(engine.verify_block_seal(&header).is_err());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ use account_provider::{AccountProvider, Error as AccountError};
|
|||||||
use views::{BlockView, HeaderView};
|
use views::{BlockView, HeaderView};
|
||||||
use header::Header;
|
use header::Header;
|
||||||
use state::{State, CleanupMode};
|
use state::{State, CleanupMode};
|
||||||
use client::{MiningBlockChainClient, Executive, Executed, EnvInfo, TransactOptions, BlockID, CallAnalytics, TransactionID};
|
use client::{MiningBlockChainClient, Executive, Executed, EnvInfo, TransactOptions, BlockId, CallAnalytics, TransactionId};
|
||||||
use client::TransactionImportResult;
|
use client::TransactionImportResult;
|
||||||
use executive::contract_address;
|
use executive::contract_address;
|
||||||
use block::{ClosedBlock, SealedBlock, IsBlock, Block};
|
use block::{ClosedBlock, SealedBlock, IsBlock, Block};
|
||||||
@ -585,7 +585,7 @@ impl Miner {
|
|||||||
let best_block_header: Header = ::rlp::decode(&chain.best_block_header());
|
let best_block_header: Header = ::rlp::decode(&chain.best_block_header());
|
||||||
transactions.into_iter()
|
transactions.into_iter()
|
||||||
.map(|tx| {
|
.map(|tx| {
|
||||||
if chain.transaction_block(TransactionID::Hash(tx.hash())).is_some() {
|
if chain.transaction_block(TransactionId::Hash(tx.hash())).is_some() {
|
||||||
debug!(target: "miner", "Rejected tx {:?}: already in the blockchain", tx.hash());
|
debug!(target: "miner", "Rejected tx {:?}: already in the blockchain", tx.hash());
|
||||||
return Err(Error::Transaction(TransactionError::AlreadyImported));
|
return Err(Error::Transaction(TransactionError::AlreadyImported));
|
||||||
}
|
}
|
||||||
@ -701,7 +701,7 @@ impl MinerService for Miner {
|
|||||||
Ok(ret)
|
Ok(ret)
|
||||||
},
|
},
|
||||||
None => {
|
None => {
|
||||||
chain.call(t, BlockID::Latest, analytics)
|
chain.call(t, BlockId::Latest, analytics)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1094,7 +1094,7 @@ impl MinerService for Miner {
|
|||||||
|
|
||||||
fn fetch_transactions(chain: &MiningBlockChainClient, hash: &H256) -> Vec<SignedTransaction> {
|
fn fetch_transactions(chain: &MiningBlockChainClient, hash: &H256) -> Vec<SignedTransaction> {
|
||||||
let block = chain
|
let block = chain
|
||||||
.block(BlockID::Hash(*hash))
|
.block(BlockId::Hash(*hash))
|
||||||
// Client should send message after commit to db and inserting to chain.
|
// Client should send message after commit to db and inserting to chain.
|
||||||
.expect("Expected in-chain blocks.");
|
.expect("Expected in-chain blocks.");
|
||||||
let block = BlockView::new(&block);
|
let block = BlockView::new(&block);
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
|
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
use ids::BlockID;
|
use ids::BlockId;
|
||||||
|
|
||||||
use util::H256;
|
use util::H256;
|
||||||
use util::trie::TrieError;
|
use util::trie::TrieError;
|
||||||
@ -28,7 +28,7 @@ use rlp::DecoderError;
|
|||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
/// Invalid starting block for snapshot.
|
/// Invalid starting block for snapshot.
|
||||||
InvalidStartingBlock(BlockID),
|
InvalidStartingBlock(BlockId),
|
||||||
/// Block not found.
|
/// Block not found.
|
||||||
BlockNotFound(H256),
|
BlockNotFound(H256),
|
||||||
/// Incomplete chain.
|
/// Incomplete chain.
|
||||||
|
@ -27,7 +27,7 @@ use account_db::{AccountDB, AccountDBMut};
|
|||||||
use blockchain::{BlockChain, BlockProvider};
|
use blockchain::{BlockChain, BlockProvider};
|
||||||
use engines::Engine;
|
use engines::Engine;
|
||||||
use header::Header;
|
use header::Header;
|
||||||
use ids::BlockID;
|
use ids::BlockId;
|
||||||
use views::BlockView;
|
use views::BlockView;
|
||||||
|
|
||||||
use util::{Bytes, Hashable, HashDB, DBValue, snappy, U256, Uint};
|
use util::{Bytes, Hashable, HashDB, DBValue, snappy, U256, Uint};
|
||||||
@ -129,7 +129,7 @@ pub fn take_snapshot<W: SnapshotWriter + Send>(
|
|||||||
p: &Progress
|
p: &Progress
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
let start_header = try!(chain.block_header(&block_at)
|
let start_header = try!(chain.block_header(&block_at)
|
||||||
.ok_or(Error::InvalidStartingBlock(BlockID::Hash(block_at))));
|
.ok_or(Error::InvalidStartingBlock(BlockId::Hash(block_at))));
|
||||||
let state_root = start_header.state_root();
|
let state_root = start_header.state_root();
|
||||||
let number = start_header.number();
|
let number = start_header.number();
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ use blockchain::BlockChain;
|
|||||||
use client::{BlockChainClient, Client};
|
use client::{BlockChainClient, Client};
|
||||||
use engines::Engine;
|
use engines::Engine;
|
||||||
use error::Error;
|
use error::Error;
|
||||||
use ids::BlockID;
|
use ids::BlockId;
|
||||||
use service::ClientIoMessage;
|
use service::ClientIoMessage;
|
||||||
|
|
||||||
use io::IoChannel;
|
use io::IoChannel;
|
||||||
@ -354,7 +354,7 @@ impl Service {
|
|||||||
let writer = try!(LooseWriter::new(temp_dir.clone()));
|
let writer = try!(LooseWriter::new(temp_dir.clone()));
|
||||||
|
|
||||||
let guard = Guard::new(temp_dir.clone());
|
let guard = Guard::new(temp_dir.clone());
|
||||||
let res = client.take_snapshot(writer, BlockID::Number(num), &self.progress);
|
let res = client.take_snapshot(writer, BlockId::Number(num), &self.progress);
|
||||||
|
|
||||||
self.taking_snapshot.store(false, Ordering::SeqCst);
|
self.taking_snapshot.store(false, Ordering::SeqCst);
|
||||||
if let Err(e) = res {
|
if let Err(e) = res {
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use client::{BlockChainClient, Client};
|
use client::{BlockChainClient, Client};
|
||||||
use ids::BlockID;
|
use ids::BlockId;
|
||||||
use snapshot::service::{Service, ServiceParams};
|
use snapshot::service::{Service, ServiceParams};
|
||||||
use snapshot::{self, ManifestData, SnapshotService};
|
use snapshot::{self, ManifestData, SnapshotService};
|
||||||
use spec::Spec;
|
use spec::Spec;
|
||||||
@ -96,8 +96,8 @@ fn restored_is_equivalent() {
|
|||||||
assert_eq!(service.status(), ::snapshot::RestorationStatus::Inactive);
|
assert_eq!(service.status(), ::snapshot::RestorationStatus::Inactive);
|
||||||
|
|
||||||
for x in 0..NUM_BLOCKS {
|
for x in 0..NUM_BLOCKS {
|
||||||
let block1 = client.block(BlockID::Number(x as u64)).unwrap();
|
let block1 = client.block(BlockId::Number(x as u64)).unwrap();
|
||||||
let block2 = client2.block(BlockID::Number(x as u64)).unwrap();
|
let block2 = client2.block(BlockId::Number(x as u64)).unwrap();
|
||||||
|
|
||||||
assert_eq!(block1, block2);
|
assert_eq!(block1, block2);
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
|
|
||||||
use util::Mutex;
|
use util::Mutex;
|
||||||
use client::{BlockChainClient, Client, ChainNotify};
|
use client::{BlockChainClient, Client, ChainNotify};
|
||||||
use ids::BlockID;
|
use ids::BlockId;
|
||||||
use service::ClientIoMessage;
|
use service::ClientIoMessage;
|
||||||
use views::HeaderView;
|
use views::HeaderView;
|
||||||
|
|
||||||
@ -43,7 +43,7 @@ impl<F> Oracle for StandardOracle<F>
|
|||||||
where F: Send + Sync + Fn() -> bool
|
where F: Send + Sync + Fn() -> bool
|
||||||
{
|
{
|
||||||
fn to_number(&self, hash: H256) -> Option<u64> {
|
fn to_number(&self, hash: H256) -> Option<u64> {
|
||||||
self.client.block_header(BlockID::Hash(hash)).map(|h| HeaderView::new(&h).number())
|
self.client.block_header(BlockId::Hash(hash)).map(|h| HeaderView::new(&h).number())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_major_importing(&self) -> bool {
|
fn is_major_importing(&self) -> bool {
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use io::IoChannel;
|
use io::IoChannel;
|
||||||
use client::{BlockChainClient, MiningBlockChainClient, Client, ClientConfig, BlockID};
|
use client::{BlockChainClient, MiningBlockChainClient, Client, ClientConfig, BlockId};
|
||||||
use state::CleanupMode;
|
use state::CleanupMode;
|
||||||
use ethereum;
|
use ethereum;
|
||||||
use block::IsBlock;
|
use block::IsBlock;
|
||||||
@ -99,7 +99,7 @@ fn imports_good_block() {
|
|||||||
client.flush_queue();
|
client.flush_queue();
|
||||||
client.import_verified_blocks();
|
client.import_verified_blocks();
|
||||||
|
|
||||||
let block = client.block_header(BlockID::Number(1)).unwrap();
|
let block = client.block_header(BlockId::Number(1)).unwrap();
|
||||||
assert!(!block.is_empty());
|
assert!(!block.is_empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,7 +117,7 @@ fn query_none_block() {
|
|||||||
IoChannel::disconnected(),
|
IoChannel::disconnected(),
|
||||||
&db_config
|
&db_config
|
||||||
).unwrap();
|
).unwrap();
|
||||||
let non_existant = client.block_header(BlockID::Number(188));
|
let non_existant = client.block_header(BlockId::Number(188));
|
||||||
assert!(non_existant.is_none());
|
assert!(non_existant.is_none());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,7 +125,7 @@ fn query_none_block() {
|
|||||||
fn query_bad_block() {
|
fn query_bad_block() {
|
||||||
let client_result = get_test_client_with_blocks(vec![get_bad_state_dummy_block()]);
|
let client_result = get_test_client_with_blocks(vec![get_bad_state_dummy_block()]);
|
||||||
let client = client_result.reference();
|
let client = client_result.reference();
|
||||||
let bad_block:Option<Bytes> = client.block_header(BlockID::Number(1));
|
let bad_block:Option<Bytes> = client.block_header(BlockId::Number(1));
|
||||||
|
|
||||||
assert!(bad_block.is_none());
|
assert!(bad_block.is_none());
|
||||||
}
|
}
|
||||||
@ -146,8 +146,8 @@ fn returns_logs() {
|
|||||||
let client_result = get_test_client_with_blocks(vec![dummy_block.clone()]);
|
let client_result = get_test_client_with_blocks(vec![dummy_block.clone()]);
|
||||||
let client = client_result.reference();
|
let client = client_result.reference();
|
||||||
let logs = client.logs(Filter {
|
let logs = client.logs(Filter {
|
||||||
from_block: BlockID::Earliest,
|
from_block: BlockId::Earliest,
|
||||||
to_block: BlockID::Latest,
|
to_block: BlockId::Latest,
|
||||||
address: None,
|
address: None,
|
||||||
topics: vec![],
|
topics: vec![],
|
||||||
limit: None,
|
limit: None,
|
||||||
@ -161,8 +161,8 @@ fn returns_logs_with_limit() {
|
|||||||
let client_result = get_test_client_with_blocks(vec![dummy_block.clone()]);
|
let client_result = get_test_client_with_blocks(vec![dummy_block.clone()]);
|
||||||
let client = client_result.reference();
|
let client = client_result.reference();
|
||||||
let logs = client.logs(Filter {
|
let logs = client.logs(Filter {
|
||||||
from_block: BlockID::Earliest,
|
from_block: BlockId::Earliest,
|
||||||
to_block: BlockID::Latest,
|
to_block: BlockId::Latest,
|
||||||
address: None,
|
address: None,
|
||||||
topics: vec![],
|
topics: vec![],
|
||||||
limit: Some(2),
|
limit: Some(2),
|
||||||
@ -176,7 +176,7 @@ fn returns_block_body() {
|
|||||||
let client_result = get_test_client_with_blocks(vec![dummy_block.clone()]);
|
let client_result = get_test_client_with_blocks(vec![dummy_block.clone()]);
|
||||||
let client = client_result.reference();
|
let client = client_result.reference();
|
||||||
let block = BlockView::new(&dummy_block);
|
let block = BlockView::new(&dummy_block);
|
||||||
let body = client.block_body(BlockID::Hash(block.header().hash())).unwrap();
|
let body = client.block_body(BlockId::Hash(block.header().hash())).unwrap();
|
||||||
let body = Rlp::new(&body);
|
let body = Rlp::new(&body);
|
||||||
assert_eq!(body.item_count(), 2);
|
assert_eq!(body.item_count(), 2);
|
||||||
assert_eq!(body.at(0).as_raw()[..], block.rlp().at(1).as_raw()[..]);
|
assert_eq!(body.at(0).as_raw()[..], block.rlp().at(1).as_raw()[..]);
|
||||||
@ -187,7 +187,7 @@ fn returns_block_body() {
|
|||||||
fn imports_block_sequence() {
|
fn imports_block_sequence() {
|
||||||
let client_result = generate_dummy_client(6);
|
let client_result = generate_dummy_client(6);
|
||||||
let client = client_result.reference();
|
let client = client_result.reference();
|
||||||
let block = client.block_header(BlockID::Number(5)).unwrap();
|
let block = client.block_header(BlockId::Number(5)).unwrap();
|
||||||
|
|
||||||
assert!(!block.is_empty());
|
assert!(!block.is_empty());
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
use nanoipc;
|
use nanoipc;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::sync::atomic::{Ordering, AtomicBool};
|
use std::sync::atomic::{Ordering, AtomicBool};
|
||||||
use client::{Client, BlockChainClient, ClientConfig, BlockID};
|
use client::{Client, BlockChainClient, ClientConfig, BlockId};
|
||||||
use client::remote::RemoteClient;
|
use client::remote::RemoteClient;
|
||||||
use tests::helpers::*;
|
use tests::helpers::*;
|
||||||
use devtools::*;
|
use devtools::*;
|
||||||
@ -71,7 +71,7 @@ fn can_query_block() {
|
|||||||
run_test_worker(scope, stop_guard.share(), socket_path);
|
run_test_worker(scope, stop_guard.share(), socket_path);
|
||||||
let remote_client = nanoipc::generic_client::<RemoteClient<_>>(socket_path).unwrap();
|
let remote_client = nanoipc::generic_client::<RemoteClient<_>>(socket_path).unwrap();
|
||||||
|
|
||||||
let non_existant_block = remote_client.block_header(BlockID::Number(999));
|
let non_existant_block = remote_client.block_header(BlockId::Number(999));
|
||||||
|
|
||||||
assert!(non_existant_block.is_none());
|
assert!(non_existant_block.is_none());
|
||||||
})
|
})
|
||||||
|
@ -94,7 +94,7 @@ impl Key<blooms::BloomGroup> for TraceGroupPosition {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Hash, Eq, PartialEq)]
|
#[derive(Debug, Hash, Eq, PartialEq)]
|
||||||
enum CacheID {
|
enum CacheId {
|
||||||
Trace(H256),
|
Trace(H256),
|
||||||
Bloom(TraceGroupPosition),
|
Bloom(TraceGroupPosition),
|
||||||
}
|
}
|
||||||
@ -104,7 +104,7 @@ pub struct TraceDB<T> where T: DatabaseExtras {
|
|||||||
// cache
|
// cache
|
||||||
traces: RwLock<HashMap<H256, FlatBlockTraces>>,
|
traces: RwLock<HashMap<H256, FlatBlockTraces>>,
|
||||||
blooms: RwLock<HashMap<TraceGroupPosition, blooms::BloomGroup>>,
|
blooms: RwLock<HashMap<TraceGroupPosition, blooms::BloomGroup>>,
|
||||||
cache_manager: RwLock<CacheManager<CacheID>>,
|
cache_manager: RwLock<CacheManager<CacheId>>,
|
||||||
// db
|
// db
|
||||||
tracesdb: Arc<Database>,
|
tracesdb: Arc<Database>,
|
||||||
// config,
|
// config,
|
||||||
@ -119,7 +119,7 @@ impl<T> BloomGroupDatabase for TraceDB<T> where T: DatabaseExtras {
|
|||||||
fn blooms_at(&self, position: &GroupPosition) -> Option<BloomGroup> {
|
fn blooms_at(&self, position: &GroupPosition) -> Option<BloomGroup> {
|
||||||
let position = TraceGroupPosition::from(position.clone());
|
let position = TraceGroupPosition::from(position.clone());
|
||||||
let result = self.tracesdb.read_with_cache(db::COL_TRACE, &self.blooms, &position).map(Into::into);
|
let result = self.tracesdb.read_with_cache(db::COL_TRACE, &self.blooms, &position).map(Into::into);
|
||||||
self.note_used(CacheID::Bloom(position));
|
self.note_used(CacheId::Bloom(position));
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -152,7 +152,7 @@ impl<T> TraceDB<T> where T: DatabaseExtras {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Let the cache system know that a cacheable item has been used.
|
/// Let the cache system know that a cacheable item has been used.
|
||||||
fn note_used(&self, id: CacheID) {
|
fn note_used(&self, id: CacheId) {
|
||||||
let mut cache_manager = self.cache_manager.write();
|
let mut cache_manager = self.cache_manager.write();
|
||||||
cache_manager.note_used(id);
|
cache_manager.note_used(id);
|
||||||
}
|
}
|
||||||
@ -168,8 +168,8 @@ impl<T> TraceDB<T> where T: DatabaseExtras {
|
|||||||
cache_manager.collect_garbage(current_size, | ids | {
|
cache_manager.collect_garbage(current_size, | ids | {
|
||||||
for id in &ids {
|
for id in &ids {
|
||||||
match *id {
|
match *id {
|
||||||
CacheID::Trace(ref h) => { traces.remove(h); },
|
CacheId::Trace(ref h) => { traces.remove(h); },
|
||||||
CacheID::Bloom(ref h) => { blooms.remove(h); },
|
CacheId::Bloom(ref h) => { blooms.remove(h); },
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
traces.shrink_to_fit();
|
traces.shrink_to_fit();
|
||||||
@ -182,7 +182,7 @@ impl<T> TraceDB<T> where T: DatabaseExtras {
|
|||||||
/// Returns traces for block with hash.
|
/// Returns traces for block with hash.
|
||||||
fn traces(&self, block_hash: &H256) -> Option<FlatBlockTraces> {
|
fn traces(&self, block_hash: &H256) -> Option<FlatBlockTraces> {
|
||||||
let result = self.tracesdb.read_with_cache(db::COL_TRACE, &self.traces, block_hash);
|
let result = self.tracesdb.read_with_cache(db::COL_TRACE, &self.traces, block_hash);
|
||||||
self.note_used(CacheID::Trace(block_hash.clone()));
|
self.note_used(CacheId::Trace(block_hash.clone()));
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -289,7 +289,7 @@ impl<T> TraceDatabase for TraceDB<T> where T: DatabaseExtras {
|
|||||||
batch.extend_with_cache(db::COL_TRACE, &mut *blooms, blooms_to_insert, CacheUpdatePolicy::Remove);
|
batch.extend_with_cache(db::COL_TRACE, &mut *blooms, blooms_to_insert, CacheUpdatePolicy::Remove);
|
||||||
// note_used must be called after locking blooms to avoid cache/traces deadlock on garbage collection
|
// note_used must be called after locking blooms to avoid cache/traces deadlock on garbage collection
|
||||||
for key in blooms_keys {
|
for key in blooms_keys {
|
||||||
self.note_used(CacheID::Bloom(key));
|
self.note_used(CacheId::Bloom(key));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -300,7 +300,7 @@ impl<T> TraceDatabase for TraceDB<T> where T: DatabaseExtras {
|
|||||||
// cause this value might be queried by hash later
|
// cause this value might be queried by hash later
|
||||||
batch.write_with_cache(db::COL_TRACE, &mut *traces, request.block_hash, request.traces, CacheUpdatePolicy::Overwrite);
|
batch.write_with_cache(db::COL_TRACE, &mut *traces, request.block_hash, request.traces, CacheUpdatePolicy::Overwrite);
|
||||||
// note_used must be called after locking traces to avoid cache/traces deadlock on garbage collection
|
// note_used must be called after locking traces to avoid cache/traces deadlock on garbage collection
|
||||||
self.note_used(CacheID::Trace(request.block_hash.clone()));
|
self.note_used(CacheId::Trace(request.block_hash.clone()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,17 +18,17 @@
|
|||||||
|
|
||||||
use util::{Address, H256, Hashable, H2048};
|
use util::{Address, H256, Hashable, H2048};
|
||||||
use util::bloom::Bloomable;
|
use util::bloom::Bloomable;
|
||||||
use client::BlockID;
|
use client::BlockId;
|
||||||
use log_entry::LogEntry;
|
use log_entry::LogEntry;
|
||||||
|
|
||||||
/// Blockchain Filter.
|
/// Blockchain Filter.
|
||||||
#[derive(Binary, Debug, PartialEq)]
|
#[derive(Binary, Debug, PartialEq)]
|
||||||
pub struct Filter {
|
pub struct Filter {
|
||||||
/// Blockchain will be searched from this block.
|
/// Blockchain will be searched from this block.
|
||||||
pub from_block: BlockID,
|
pub from_block: BlockId,
|
||||||
|
|
||||||
/// Till this block.
|
/// Till this block.
|
||||||
pub to_block: BlockID,
|
pub to_block: BlockId,
|
||||||
|
|
||||||
/// Search addresses.
|
/// Search addresses.
|
||||||
///
|
///
|
||||||
@ -114,14 +114,14 @@ impl Filter {
|
|||||||
mod tests {
|
mod tests {
|
||||||
use util::FixedHash;
|
use util::FixedHash;
|
||||||
use filter::Filter;
|
use filter::Filter;
|
||||||
use client::BlockID;
|
use client::BlockId;
|
||||||
use log_entry::LogEntry;
|
use log_entry::LogEntry;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_bloom_possibilities_none() {
|
fn test_bloom_possibilities_none() {
|
||||||
let none_filter = Filter {
|
let none_filter = Filter {
|
||||||
from_block: BlockID::Earliest,
|
from_block: BlockId::Earliest,
|
||||||
to_block: BlockID::Latest,
|
to_block: BlockId::Latest,
|
||||||
address: None,
|
address: None,
|
||||||
topics: vec![None, None, None, None],
|
topics: vec![None, None, None, None],
|
||||||
limit: None,
|
limit: None,
|
||||||
@ -136,8 +136,8 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_bloom_possibilities_single_address_and_topic() {
|
fn test_bloom_possibilities_single_address_and_topic() {
|
||||||
let filter = Filter {
|
let filter = Filter {
|
||||||
from_block: BlockID::Earliest,
|
from_block: BlockId::Earliest,
|
||||||
to_block: BlockID::Latest,
|
to_block: BlockId::Latest,
|
||||||
address: Some(vec!["b372018f3be9e171df0581136b59d2faf73a7d5d".into()]),
|
address: Some(vec!["b372018f3be9e171df0581136b59d2faf73a7d5d".into()]),
|
||||||
topics: vec![
|
topics: vec![
|
||||||
Some(vec!["ff74e91598aed6ae5d2fdcf8b24cd2c7be49a0808112a305069355b7160f23f9".into()]),
|
Some(vec!["ff74e91598aed6ae5d2fdcf8b24cd2c7be49a0808112a305069355b7160f23f9".into()]),
|
||||||
@ -155,8 +155,8 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_bloom_possibilities_single_address_and_many_topics() {
|
fn test_bloom_possibilities_single_address_and_many_topics() {
|
||||||
let filter = Filter {
|
let filter = Filter {
|
||||||
from_block: BlockID::Earliest,
|
from_block: BlockId::Earliest,
|
||||||
to_block: BlockID::Latest,
|
to_block: BlockId::Latest,
|
||||||
address: Some(vec!["b372018f3be9e171df0581136b59d2faf73a7d5d".into()]),
|
address: Some(vec!["b372018f3be9e171df0581136b59d2faf73a7d5d".into()]),
|
||||||
topics: vec![
|
topics: vec![
|
||||||
Some(vec!["ff74e91598aed6ae5d2fdcf8b24cd2c7be49a0808112a305069355b7160f23f9".into()]),
|
Some(vec!["ff74e91598aed6ae5d2fdcf8b24cd2c7be49a0808112a305069355b7160f23f9".into()]),
|
||||||
@ -174,8 +174,8 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_bloom_possibilites_multiple_addresses_and_topics() {
|
fn test_bloom_possibilites_multiple_addresses_and_topics() {
|
||||||
let filter = Filter {
|
let filter = Filter {
|
||||||
from_block: BlockID::Earliest,
|
from_block: BlockId::Earliest,
|
||||||
to_block: BlockID::Latest,
|
to_block: BlockId::Latest,
|
||||||
address: Some(vec![
|
address: Some(vec![
|
||||||
"b372018f3be9e171df0581136b59d2faf73a7d5d".into(),
|
"b372018f3be9e171df0581136b59d2faf73a7d5d".into(),
|
||||||
"b372018f3be9e171df0581136b59d2faf73a7d5d".into(),
|
"b372018f3be9e171df0581136b59d2faf73a7d5d".into(),
|
||||||
@ -204,8 +204,8 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_filter_matches() {
|
fn test_filter_matches() {
|
||||||
let filter = Filter {
|
let filter = Filter {
|
||||||
from_block: BlockID::Earliest,
|
from_block: BlockId::Earliest,
|
||||||
to_block: BlockID::Latest,
|
to_block: BlockId::Latest,
|
||||||
address: Some(vec!["b372018f3be9e171df0581136b59d2faf73a7d5d".into()]),
|
address: Some(vec!["b372018f3be9e171df0581136b59d2faf73a7d5d".into()]),
|
||||||
topics: vec![
|
topics: vec![
|
||||||
Some(vec!["ff74e91598aed6ae5d2fdcf8b24cd2c7be49a0808112a305069355b7160f23f9".into()]),
|
Some(vec!["ff74e91598aed6ae5d2fdcf8b24cd2c7be49a0808112a305069355b7160f23f9".into()]),
|
||||||
|
@ -21,7 +21,7 @@ use header::BlockNumber;
|
|||||||
|
|
||||||
/// Uniquely identifies block.
|
/// Uniquely identifies block.
|
||||||
#[derive(Debug, PartialEq, Copy, Clone, Hash, Eq, Binary)]
|
#[derive(Debug, PartialEq, Copy, Clone, Hash, Eq, Binary)]
|
||||||
pub enum BlockID {
|
pub enum BlockId {
|
||||||
/// Block's sha3.
|
/// Block's sha3.
|
||||||
/// Querying by hash is always faster.
|
/// Querying by hash is always faster.
|
||||||
Hash(H256),
|
Hash(H256),
|
||||||
@ -37,28 +37,28 @@ pub enum BlockID {
|
|||||||
|
|
||||||
/// Uniquely identifies transaction.
|
/// Uniquely identifies transaction.
|
||||||
#[derive(Debug, PartialEq, Clone, Hash, Eq, Binary)]
|
#[derive(Debug, PartialEq, Clone, Hash, Eq, Binary)]
|
||||||
pub enum TransactionID {
|
pub enum TransactionId {
|
||||||
/// Transaction's sha3.
|
/// Transaction's sha3.
|
||||||
Hash(H256),
|
Hash(H256),
|
||||||
/// Block id and transaction index within this block.
|
/// Block id and transaction index within this block.
|
||||||
/// Querying by block position is always faster.
|
/// Querying by block position is always faster.
|
||||||
Location(BlockID, usize)
|
Location(BlockId, usize)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Uniquely identifies Trace.
|
/// Uniquely identifies Trace.
|
||||||
#[derive(Binary)]
|
#[derive(Binary)]
|
||||||
pub struct TraceId {
|
pub struct TraceId {
|
||||||
/// Transaction
|
/// Transaction
|
||||||
pub transaction: TransactionID,
|
pub transaction: TransactionId,
|
||||||
/// Trace address within transaction.
|
/// Trace address within transaction.
|
||||||
pub address: Vec<usize>,
|
pub address: Vec<usize>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Uniquely identifies Uncle.
|
/// Uniquely identifies Uncle.
|
||||||
#[derive(Debug, PartialEq, Eq, Copy, Clone, Binary)]
|
#[derive(Debug, PartialEq, Eq, Copy, Clone, Binary)]
|
||||||
pub struct UncleID {
|
pub struct UncleId {
|
||||||
/// Block id.
|
/// Block id.
|
||||||
pub block: BlockID,
|
pub block: BlockId,
|
||||||
/// Position in block.
|
/// Position in block.
|
||||||
pub position: usize
|
pub position: usize
|
||||||
}
|
}
|
||||||
|
@ -18,13 +18,13 @@
|
|||||||
|
|
||||||
use std::ops::Range;
|
use std::ops::Range;
|
||||||
use util::{Address};
|
use util::{Address};
|
||||||
use types::ids::BlockID;
|
use types::ids::BlockId;
|
||||||
|
|
||||||
/// Easy to use trace filter.
|
/// Easy to use trace filter.
|
||||||
#[derive(Binary)]
|
#[derive(Binary)]
|
||||||
pub struct Filter {
|
pub struct Filter {
|
||||||
/// Range of filtering.
|
/// Range of filtering.
|
||||||
pub range: Range<BlockID>,
|
pub range: Range<BlockId>,
|
||||||
/// From address.
|
/// From address.
|
||||||
pub from_address: Vec<Address>,
|
pub from_address: Vec<Address>,
|
||||||
/// To address.
|
/// To address.
|
||||||
|
@ -20,7 +20,7 @@ use std::collections::HashMap;
|
|||||||
use time;
|
use time;
|
||||||
use ethkey::Address;
|
use ethkey::Address;
|
||||||
use {json, SafeAccount, Error};
|
use {json, SafeAccount, Error};
|
||||||
use json::UUID;
|
use json::Uuid;
|
||||||
use super::KeyDirectory;
|
use super::KeyDirectory;
|
||||||
|
|
||||||
const IGNORED_FILES: &'static [&'static str] = &["thumbs.db", "address_book.json"];
|
const IGNORED_FILES: &'static [&'static str] = &["thumbs.db", "address_book.json"];
|
||||||
@ -113,7 +113,7 @@ impl KeyDirectory for DiskDirectory {
|
|||||||
// build file path
|
// build file path
|
||||||
let filename = account.filename.as_ref().cloned().unwrap_or_else(|| {
|
let filename = account.filename.as_ref().cloned().unwrap_or_else(|| {
|
||||||
let timestamp = time::strftime("%Y-%m-%dT%H-%M-%S", &time::now_utc()).expect("Time-format string is valid.");
|
let timestamp = time::strftime("%Y-%m-%dT%H-%M-%S", &time::now_utc()).expect("Time-format string is valid.");
|
||||||
format!("UTC--{}Z--{}", timestamp, UUID::from(account.id))
|
format!("UTC--{}Z--{}", timestamp, Uuid::from(account.id))
|
||||||
});
|
});
|
||||||
|
|
||||||
// update account filename
|
// update account filename
|
||||||
|
@ -24,7 +24,7 @@ use dir::KeyDirectory;
|
|||||||
use account::SafeAccount;
|
use account::SafeAccount;
|
||||||
use {Error, SecretStore};
|
use {Error, SecretStore};
|
||||||
use json;
|
use json;
|
||||||
use json::UUID;
|
use json::Uuid;
|
||||||
use parking_lot::RwLock;
|
use parking_lot::RwLock;
|
||||||
use presale::PresaleWallet;
|
use presale::PresaleWallet;
|
||||||
use import;
|
use import;
|
||||||
@ -154,7 +154,7 @@ impl SecretStore for EthStore {
|
|||||||
account.public(password)
|
account.public(password)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn uuid(&self, address: &Address) -> Result<UUID, Error> {
|
fn uuid(&self, address: &Address) -> Result<Uuid, Error> {
|
||||||
let account = try!(self.get(address));
|
let account = try!(self.get(address));
|
||||||
Ok(account.id.into())
|
Ok(account.id.into())
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ pub enum Error {
|
|||||||
UnsupportedCipher,
|
UnsupportedCipher,
|
||||||
InvalidCipherParams,
|
InvalidCipherParams,
|
||||||
UnsupportedKdf,
|
UnsupportedKdf,
|
||||||
InvalidUUID,
|
InvalidUuid,
|
||||||
UnsupportedVersion,
|
UnsupportedVersion,
|
||||||
InvalidCiphertext,
|
InvalidCiphertext,
|
||||||
InvalidH256,
|
InvalidH256,
|
||||||
@ -31,7 +31,7 @@ pub enum Error {
|
|||||||
impl fmt::Display for Error {
|
impl fmt::Display for Error {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
||||||
match *self {
|
match *self {
|
||||||
Error::InvalidUUID => write!(f, "Invalid UUID"),
|
Error::InvalidUuid => write!(f, "Invalid Uuid"),
|
||||||
Error::UnsupportedVersion => write!(f, "Unsupported version"),
|
Error::UnsupportedVersion => write!(f, "Unsupported version"),
|
||||||
Error::UnsupportedKdf => write!(f, "Unsupported kdf"),
|
Error::UnsupportedKdf => write!(f, "Unsupported kdf"),
|
||||||
Error::InvalidCiphertext => write!(f, "Invalid ciphertext"),
|
Error::InvalidCiphertext => write!(f, "Invalid ciphertext"),
|
||||||
|
@ -23,15 +23,15 @@ use super::Error;
|
|||||||
|
|
||||||
/// Universaly unique identifier.
|
/// Universaly unique identifier.
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
pub struct UUID([u8; 16]);
|
pub struct Uuid([u8; 16]);
|
||||||
|
|
||||||
impl From<[u8; 16]> for UUID {
|
impl From<[u8; 16]> for Uuid {
|
||||||
fn from(uuid: [u8; 16]) -> Self {
|
fn from(uuid: [u8; 16]) -> Self {
|
||||||
UUID(uuid)
|
Uuid(uuid)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Into<String> for &'a UUID {
|
impl<'a> Into<String> for &'a Uuid {
|
||||||
fn into(self) -> String {
|
fn into(self) -> String {
|
||||||
let d1 = &self.0[0..4];
|
let d1 = &self.0[0..4];
|
||||||
let d2 = &self.0[4..6];
|
let d2 = &self.0[4..6];
|
||||||
@ -42,44 +42,44 @@ impl<'a> Into<String> for &'a UUID {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Into<String> for UUID {
|
impl Into<String> for Uuid {
|
||||||
fn into(self) -> String {
|
fn into(self) -> String {
|
||||||
Into::into(&self)
|
Into::into(&self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Into<[u8; 16]> for UUID {
|
impl Into<[u8; 16]> for Uuid {
|
||||||
fn into(self) -> [u8; 16] {
|
fn into(self) -> [u8; 16] {
|
||||||
self.0
|
self.0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for UUID {
|
impl fmt::Display for Uuid {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
||||||
let s: String = (self as &UUID).into();
|
let s: String = (self as &Uuid).into();
|
||||||
write!(f, "{}", s)
|
write!(f, "{}", s)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn copy_into(from: &str, into: &mut [u8]) -> Result<(), Error> {
|
fn copy_into(from: &str, into: &mut [u8]) -> Result<(), Error> {
|
||||||
let from = try!(from.from_hex().map_err(|_| Error::InvalidUUID));
|
let from = try!(from.from_hex().map_err(|_| Error::InvalidUuid));
|
||||||
|
|
||||||
if from.len() != into.len() {
|
if from.len() != into.len() {
|
||||||
return Err(Error::InvalidUUID);
|
return Err(Error::InvalidUuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
into.copy_from_slice(&from);
|
into.copy_from_slice(&from);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
impl str::FromStr for UUID {
|
impl str::FromStr for Uuid {
|
||||||
type Err = Error;
|
type Err = Error;
|
||||||
|
|
||||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||||
let parts: Vec<&str> = s.split("-").collect();
|
let parts: Vec<&str> = s.split("-").collect();
|
||||||
|
|
||||||
if parts.len() != 5 {
|
if parts.len() != 5 {
|
||||||
return Err(Error::InvalidUUID);
|
return Err(Error::InvalidUuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut uuid = [0u8; 16];
|
let mut uuid = [0u8; 16];
|
||||||
@ -90,17 +90,17 @@ impl str::FromStr for UUID {
|
|||||||
try!(copy_into(parts[3], &mut uuid[8..10]));
|
try!(copy_into(parts[3], &mut uuid[8..10]));
|
||||||
try!(copy_into(parts[4], &mut uuid[10..16]));
|
try!(copy_into(parts[4], &mut uuid[10..16]));
|
||||||
|
|
||||||
Ok(UUID(uuid))
|
Ok(Uuid(uuid))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<&'static str> for UUID {
|
impl From<&'static str> for Uuid {
|
||||||
fn from(s: &'static str) -> Self {
|
fn from(s: &'static str) -> Self {
|
||||||
s.parse().expect(&format!("invalid string literal for {}: '{}'", stringify!(Self), s))
|
s.parse().expect(&format!("invalid string literal for {}: '{}'", stringify!(Self), s))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Serialize for UUID {
|
impl Serialize for Uuid {
|
||||||
fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error>
|
fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error>
|
||||||
where S: Serializer {
|
where S: Serializer {
|
||||||
let s: String = self.into();
|
let s: String = self.into();
|
||||||
@ -108,17 +108,17 @@ impl Serialize for UUID {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Deserialize for UUID {
|
impl Deserialize for Uuid {
|
||||||
fn deserialize<D>(deserializer: &mut D) -> Result<Self, D::Error>
|
fn deserialize<D>(deserializer: &mut D) -> Result<Self, D::Error>
|
||||||
where D: Deserializer {
|
where D: Deserializer {
|
||||||
deserializer.deserialize(UUIDVisitor)
|
deserializer.deserialize(UuidVisitor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct UUIDVisitor;
|
struct UuidVisitor;
|
||||||
|
|
||||||
impl Visitor for UUIDVisitor {
|
impl Visitor for UuidVisitor {
|
||||||
type Value = UUID;
|
type Value = Uuid;
|
||||||
|
|
||||||
fn visit_str<E>(&mut self, value: &str) -> Result<Self::Value, E> where E: SerdeError {
|
fn visit_str<E>(&mut self, value: &str) -> Result<Self::Value, E> where E: SerdeError {
|
||||||
value.parse().map_err(SerdeError::custom)
|
value.parse().map_err(SerdeError::custom)
|
||||||
@ -131,18 +131,18 @@ impl Visitor for UUIDVisitor {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::UUID;
|
use super::Uuid;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn uuid_from_str() {
|
fn uuid_from_str() {
|
||||||
let uuid: UUID = "3198bc9c-6672-5ab3-d995-4942343ae5b6".into();
|
let uuid: Uuid = "3198bc9c-6672-5ab3-d995-4942343ae5b6".into();
|
||||||
assert_eq!(uuid, UUID::from([0x31, 0x98, 0xbc, 0x9c, 0x66, 0x72, 0x5a, 0xb3, 0xd9, 0x95, 0x49, 0x42, 0x34, 0x3a, 0xe5, 0xb6]));
|
assert_eq!(uuid, Uuid::from([0x31, 0x98, 0xbc, 0x9c, 0x66, 0x72, 0x5a, 0xb3, 0xd9, 0x95, 0x49, 0x42, 0x34, 0x3a, 0xe5, 0xb6]));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn uuid_from_and_to_str() {
|
fn uuid_from_and_to_str() {
|
||||||
let from = "3198bc9c-6672-5ab3-d995-4942343ae5b6";
|
let from = "3198bc9c-6672-5ab3-d995-4942343ae5b6";
|
||||||
let uuid: UUID = from.into();
|
let uuid: Uuid = from.into();
|
||||||
let to: String = uuid.into();
|
let to: String = uuid.into();
|
||||||
assert_eq!(from, &to);
|
assert_eq!(from, &to);
|
||||||
}
|
}
|
||||||
|
@ -18,11 +18,11 @@ use std::io::{Read, Write};
|
|||||||
use serde::{Deserialize, Deserializer, Error};
|
use serde::{Deserialize, Deserializer, Error};
|
||||||
use serde::de::{Visitor, MapVisitor};
|
use serde::de::{Visitor, MapVisitor};
|
||||||
use serde_json;
|
use serde_json;
|
||||||
use super::{UUID, Version, Crypto, H160};
|
use super::{Uuid, Version, Crypto, H160};
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Serialize)]
|
#[derive(Debug, PartialEq, Serialize)]
|
||||||
pub struct KeyFile {
|
pub struct KeyFile {
|
||||||
pub id: UUID,
|
pub id: Uuid,
|
||||||
pub version: Version,
|
pub version: Version,
|
||||||
pub crypto: Crypto,
|
pub crypto: Crypto,
|
||||||
pub address: H160,
|
pub address: H160,
|
||||||
@ -31,7 +31,7 @@ pub struct KeyFile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
enum KeyFileField {
|
enum KeyFileField {
|
||||||
ID,
|
Id,
|
||||||
Version,
|
Version,
|
||||||
Crypto,
|
Crypto,
|
||||||
Address,
|
Address,
|
||||||
@ -56,7 +56,7 @@ impl Visitor for KeyFileFieldVisitor {
|
|||||||
where E: Error
|
where E: Error
|
||||||
{
|
{
|
||||||
match value {
|
match value {
|
||||||
"id" => Ok(KeyFileField::ID),
|
"id" => Ok(KeyFileField::Id),
|
||||||
"version" => Ok(KeyFileField::Version),
|
"version" => Ok(KeyFileField::Version),
|
||||||
"crypto" => Ok(KeyFileField::Crypto),
|
"crypto" => Ok(KeyFileField::Crypto),
|
||||||
"Crypto" => Ok(KeyFileField::Crypto),
|
"Crypto" => Ok(KeyFileField::Crypto),
|
||||||
@ -94,7 +94,7 @@ impl Visitor for KeyFileVisitor {
|
|||||||
|
|
||||||
loop {
|
loop {
|
||||||
match try!(visitor.visit_key()) {
|
match try!(visitor.visit_key()) {
|
||||||
Some(KeyFileField::ID) => { id = Some(try!(visitor.visit_value())); }
|
Some(KeyFileField::Id) => { id = Some(try!(visitor.visit_value())); }
|
||||||
Some(KeyFileField::Version) => { version = Some(try!(visitor.visit_value())); }
|
Some(KeyFileField::Version) => { version = Some(try!(visitor.visit_value())); }
|
||||||
Some(KeyFileField::Crypto) => { crypto = Some(try!(visitor.visit_value())); }
|
Some(KeyFileField::Crypto) => { crypto = Some(try!(visitor.visit_value())); }
|
||||||
Some(KeyFileField::Address) => { address = Some(try!(visitor.visit_value())); }
|
Some(KeyFileField::Address) => { address = Some(try!(visitor.visit_value())); }
|
||||||
@ -153,7 +153,7 @@ impl KeyFile {
|
|||||||
mod tests {
|
mod tests {
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use serde_json;
|
use serde_json;
|
||||||
use json::{KeyFile, UUID, Version, Crypto, Cipher, Aes128Ctr, Kdf, Scrypt};
|
use json::{KeyFile, Uuid, Version, Crypto, Cipher, Aes128Ctr, Kdf, Scrypt};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn basic_keyfile() {
|
fn basic_keyfile() {
|
||||||
@ -183,7 +183,7 @@ mod tests {
|
|||||||
}"#;
|
}"#;
|
||||||
|
|
||||||
let expected = KeyFile {
|
let expected = KeyFile {
|
||||||
id: UUID::from_str("8777d9f6-7860-4b9b-88b7-0b57ee6b3a73").unwrap(),
|
id: Uuid::from_str("8777d9f6-7860-4b9b-88b7-0b57ee6b3a73").unwrap(),
|
||||||
version: Version::V3,
|
version: Version::V3,
|
||||||
address: "6edddfc6349aff20bc6467ccf276c5b52487f7a8".into(),
|
address: "6edddfc6349aff20bc6467ccf276c5b52487f7a8".into(),
|
||||||
crypto: Crypto {
|
crypto: Crypto {
|
||||||
|
@ -14,7 +14,7 @@ pub use self::cipher::{Cipher, CipherSer, CipherSerParams, Aes128Ctr};
|
|||||||
pub use self::crypto::{Crypto, CipherText};
|
pub use self::crypto::{Crypto, CipherText};
|
||||||
pub use self::error::Error;
|
pub use self::error::Error;
|
||||||
pub use self::hash::{H128, H160, H256};
|
pub use self::hash::{H128, H160, H256};
|
||||||
pub use self::id::UUID;
|
pub use self::id::Uuid;
|
||||||
pub use self::kdf::{Kdf, KdfSer, Prf, Pbkdf2, Scrypt, KdfSerParams};
|
pub use self::kdf::{Kdf, KdfSer, Prf, Pbkdf2, Scrypt, KdfSerParams};
|
||||||
pub use self::key_file::KeyFile;
|
pub use self::key_file::KeyFile;
|
||||||
pub use self::presale::{PresaleWallet, Encseed};
|
pub use self::presale::{PresaleWallet, Encseed};
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
use ethkey::{Address, Message, Signature, Secret, Public};
|
use ethkey::{Address, Message, Signature, Secret, Public};
|
||||||
use Error;
|
use Error;
|
||||||
use json::UUID;
|
use json::Uuid;
|
||||||
|
|
||||||
pub trait SecretStore: Send + Sync {
|
pub trait SecretStore: Send + Sync {
|
||||||
fn insert_account(&self, secret: Secret, password: &str) -> Result<Address, Error>;
|
fn insert_account(&self, secret: Secret, password: &str) -> Result<Address, Error>;
|
||||||
@ -30,7 +30,7 @@ pub trait SecretStore: Send + Sync {
|
|||||||
fn public(&self, account: &Address, password: &str) -> Result<Public, Error>;
|
fn public(&self, account: &Address, password: &str) -> Result<Public, Error>;
|
||||||
|
|
||||||
fn accounts(&self) -> Result<Vec<Address>, Error>;
|
fn accounts(&self) -> Result<Vec<Address>, Error>;
|
||||||
fn uuid(&self, account: &Address) -> Result<UUID, Error>;
|
fn uuid(&self, account: &Address) -> Result<Uuid, Error>;
|
||||||
fn name(&self, account: &Address) -> Result<String, Error>;
|
fn name(&self, account: &Address) -> Result<String, Error>;
|
||||||
fn meta(&self, account: &Address) -> Result<String, Error>;
|
fn meta(&self, account: &Address) -> Result<String, Error>;
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ export default {
|
|||||||
},
|
},
|
||||||
uuid: {
|
uuid: {
|
||||||
type: String,
|
type: String,
|
||||||
desc: 'The account UUID, or null if not available/unknown/not applicable.'
|
desc: 'The account Uuid, or null if not available/unknown/not applicable.'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -66,7 +66,7 @@ export default {
|
|||||||
},
|
},
|
||||||
uuid: {
|
uuid: {
|
||||||
type: String,
|
type: String,
|
||||||
desc: 'The account UUID, or null if not available/unknown/not applicable.'
|
desc: 'The account Uuid, or null if not available/unknown/not applicable.'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ pub struct AccountMeta {
|
|||||||
pub name: String,
|
pub name: String,
|
||||||
/// The rest of the metadata of the account.
|
/// The rest of the metadata of the account.
|
||||||
pub meta: String,
|
pub meta: String,
|
||||||
/// The 128-bit UUID of the account, if it has one (brain-wallets don't).
|
/// The 128-bit Uuid of the account, if it has one (brain-wallets don't).
|
||||||
pub uuid: Option<String>,
|
pub uuid: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ use io::{PanicHandler, ForwardPanic};
|
|||||||
use util::{ToPretty, Uint, U256, H256, Address, Hashable};
|
use util::{ToPretty, Uint, U256, H256, Address, Hashable};
|
||||||
use rlp::PayloadInfo;
|
use rlp::PayloadInfo;
|
||||||
use ethcore::service::ClientService;
|
use ethcore::service::ClientService;
|
||||||
use ethcore::client::{Mode, DatabaseCompactionProfile, VMType, BlockImportError, BlockChainClient, BlockID};
|
use ethcore::client::{Mode, DatabaseCompactionProfile, VMType, BlockImportError, BlockChainClient, BlockId};
|
||||||
use ethcore::error::ImportError;
|
use ethcore::error::ImportError;
|
||||||
use ethcore::miner::Miner;
|
use ethcore::miner::Miner;
|
||||||
use ethcore::verification::queue::VerifierSettings;
|
use ethcore::verification::queue::VerifierSettings;
|
||||||
@ -101,8 +101,8 @@ pub struct ExportBlockchain {
|
|||||||
pub wal: bool,
|
pub wal: bool,
|
||||||
pub fat_db: Switch,
|
pub fat_db: Switch,
|
||||||
pub tracing: Switch,
|
pub tracing: Switch,
|
||||||
pub from_block: BlockID,
|
pub from_block: BlockId,
|
||||||
pub to_block: BlockID,
|
pub to_block: BlockId,
|
||||||
pub check_seal: bool,
|
pub check_seal: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,7 +119,7 @@ pub struct ExportState {
|
|||||||
pub wal: bool,
|
pub wal: bool,
|
||||||
pub fat_db: Switch,
|
pub fat_db: Switch,
|
||||||
pub tracing: Switch,
|
pub tracing: Switch,
|
||||||
pub at: BlockID,
|
pub at: BlockId,
|
||||||
pub storage: bool,
|
pub storage: bool,
|
||||||
pub code: bool,
|
pub code: bool,
|
||||||
pub min_balance: Option<U256>,
|
pub min_balance: Option<U256>,
|
||||||
@ -384,7 +384,7 @@ fn execute_export(cmd: ExportBlockchain) -> Result<String, String> {
|
|||||||
if i % 10000 == 0 {
|
if i % 10000 == 0 {
|
||||||
info!("#{}", i);
|
info!("#{}", i);
|
||||||
}
|
}
|
||||||
let b = try!(client.block(BlockID::Number(i)).ok_or("Error exporting incomplete chain"));
|
let b = try!(client.block(BlockId::Number(i)).ok_or("Error exporting incomplete chain"));
|
||||||
match format {
|
match format {
|
||||||
DataFormat::Binary => { out.write(&b).expect("Couldn't write to stream."); }
|
DataFormat::Binary => { out.write(&b).expect("Couldn't write to stream."); }
|
||||||
DataFormat::Hex => { out.write_fmt(format_args!("{}", b.pretty())).expect("Couldn't write to stream."); }
|
DataFormat::Hex => { out.write_fmt(format_args!("{}", b.pretty())).expect("Couldn't write to stream."); }
|
||||||
|
@ -730,7 +730,7 @@ mod tests {
|
|||||||
use super::*;
|
use super::*;
|
||||||
use cli::Args;
|
use cli::Args;
|
||||||
use ethcore_rpc::NetworkSettings;
|
use ethcore_rpc::NetworkSettings;
|
||||||
use ethcore::client::{VMType, BlockID};
|
use ethcore::client::{VMType, BlockId};
|
||||||
use ethcore::miner::{MinerOptions, PrioritizationStrategy};
|
use ethcore::miner::{MinerOptions, PrioritizationStrategy};
|
||||||
use helpers::{replace_home, default_network_config};
|
use helpers::{replace_home, default_network_config};
|
||||||
use run::RunCmd;
|
use run::RunCmd;
|
||||||
@ -839,8 +839,8 @@ mod tests {
|
|||||||
wal: true,
|
wal: true,
|
||||||
tracing: Default::default(),
|
tracing: Default::default(),
|
||||||
fat_db: Default::default(),
|
fat_db: Default::default(),
|
||||||
from_block: BlockID::Number(1),
|
from_block: BlockId::Number(1),
|
||||||
to_block: BlockID::Latest,
|
to_block: BlockId::Latest,
|
||||||
check_seal: true,
|
check_seal: true,
|
||||||
})));
|
})));
|
||||||
}
|
}
|
||||||
@ -861,7 +861,7 @@ mod tests {
|
|||||||
wal: true,
|
wal: true,
|
||||||
tracing: Default::default(),
|
tracing: Default::default(),
|
||||||
fat_db: Default::default(),
|
fat_db: Default::default(),
|
||||||
at: BlockID::Latest,
|
at: BlockId::Latest,
|
||||||
storage: true,
|
storage: true,
|
||||||
code: true,
|
code: true,
|
||||||
min_balance: None,
|
min_balance: None,
|
||||||
@ -885,8 +885,8 @@ mod tests {
|
|||||||
wal: true,
|
wal: true,
|
||||||
tracing: Default::default(),
|
tracing: Default::default(),
|
||||||
fat_db: Default::default(),
|
fat_db: Default::default(),
|
||||||
from_block: BlockID::Number(1),
|
from_block: BlockId::Number(1),
|
||||||
to_block: BlockID::Latest,
|
to_block: BlockId::Latest,
|
||||||
check_seal: true,
|
check_seal: true,
|
||||||
})));
|
})));
|
||||||
}
|
}
|
||||||
|
@ -106,7 +106,7 @@ mod server {
|
|||||||
use util::{Bytes, Address, U256};
|
use util::{Bytes, Address, U256};
|
||||||
|
|
||||||
use ethcore::transaction::{Transaction, Action};
|
use ethcore::transaction::{Transaction, Action};
|
||||||
use ethcore::client::{Client, BlockChainClient, BlockID};
|
use ethcore::client::{Client, BlockChainClient, BlockId};
|
||||||
|
|
||||||
use rpc_apis;
|
use rpc_apis;
|
||||||
use ethcore_rpc::is_major_importing;
|
use ethcore_rpc::is_major_importing;
|
||||||
@ -182,7 +182,7 @@ mod server {
|
|||||||
data: data,
|
data: data,
|
||||||
}.fake_sign(from);
|
}.fake_sign(from);
|
||||||
|
|
||||||
self.client.call(&transaction, BlockID::Latest, Default::default())
|
self.client.call(&transaction, BlockId::Latest, Default::default())
|
||||||
.map_err(|e| format!("{:?}", e))
|
.map_err(|e| format!("{:?}", e))
|
||||||
.map(|executed| {
|
.map(|executed| {
|
||||||
executed.output
|
executed.output
|
||||||
|
@ -20,7 +20,7 @@ use std::time::Duration;
|
|||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use util::{clean_0x, U256, Uint, Address, path, CompactionProfile};
|
use util::{clean_0x, U256, Uint, Address, path, CompactionProfile};
|
||||||
use util::journaldb::Algorithm;
|
use util::journaldb::Algorithm;
|
||||||
use ethcore::client::{Mode, BlockID, VMType, DatabaseCompactionProfile, ClientConfig, VerifierType};
|
use ethcore::client::{Mode, BlockId, VMType, DatabaseCompactionProfile, ClientConfig, VerifierType};
|
||||||
use ethcore::miner::{PendingSet, GasLimit, PrioritizationStrategy};
|
use ethcore::miner::{PendingSet, GasLimit, PrioritizationStrategy};
|
||||||
use cache::CacheConfig;
|
use cache::CacheConfig;
|
||||||
use dir::DatabaseDirectories;
|
use dir::DatabaseDirectories;
|
||||||
@ -62,13 +62,13 @@ pub fn to_mode(s: &str, timeout: u64, alarm: u64) -> Result<Mode, String> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_block_id(s: &str) -> Result<BlockID, String> {
|
pub fn to_block_id(s: &str) -> Result<BlockId, String> {
|
||||||
if s == "latest" {
|
if s == "latest" {
|
||||||
Ok(BlockID::Latest)
|
Ok(BlockId::Latest)
|
||||||
} else if let Ok(num) = s.parse() {
|
} else if let Ok(num) = s.parse() {
|
||||||
Ok(BlockID::Number(num))
|
Ok(BlockId::Number(num))
|
||||||
} else if let Ok(hash) = s.parse() {
|
} else if let Ok(hash) = s.parse() {
|
||||||
Ok(BlockID::Hash(hash))
|
Ok(BlockId::Hash(hash))
|
||||||
} else {
|
} else {
|
||||||
Err("Invalid block.".into())
|
Err("Invalid block.".into())
|
||||||
}
|
}
|
||||||
@ -327,7 +327,7 @@ mod tests {
|
|||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use devtools::RandomTempPath;
|
use devtools::RandomTempPath;
|
||||||
use util::{U256};
|
use util::{U256};
|
||||||
use ethcore::client::{Mode, BlockID};
|
use ethcore::client::{Mode, BlockId};
|
||||||
use ethcore::miner::PendingSet;
|
use ethcore::miner::PendingSet;
|
||||||
use super::{to_duration, to_mode, to_block_id, to_u256, to_pending_set, to_address, to_addresses, to_price, geth_ipc_path, to_bootnodes, password_from_file};
|
use super::{to_duration, to_mode, to_block_id, to_u256, to_pending_set, to_address, to_addresses, to_price, geth_ipc_path, to_bootnodes, password_from_file};
|
||||||
|
|
||||||
@ -361,13 +361,13 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_to_block_id() {
|
fn test_to_block_id() {
|
||||||
assert_eq!(to_block_id("latest").unwrap(), BlockID::Latest);
|
assert_eq!(to_block_id("latest").unwrap(), BlockId::Latest);
|
||||||
assert_eq!(to_block_id("0").unwrap(), BlockID::Number(0));
|
assert_eq!(to_block_id("0").unwrap(), BlockId::Number(0));
|
||||||
assert_eq!(to_block_id("2").unwrap(), BlockID::Number(2));
|
assert_eq!(to_block_id("2").unwrap(), BlockId::Number(2));
|
||||||
assert_eq!(to_block_id("15").unwrap(), BlockID::Number(15));
|
assert_eq!(to_block_id("15").unwrap(), BlockId::Number(15));
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
to_block_id("9fc84d84f6a785dc1bd5abacfcf9cbdd3b6afb80c0f799bfb2fd42c44a0c224e").unwrap(),
|
to_block_id("9fc84d84f6a785dc1bd5abacfcf9cbdd3b6afb80c0f799bfb2fd42c44a0c224e").unwrap(),
|
||||||
BlockID::Hash("9fc84d84f6a785dc1bd5abacfcf9cbdd3b6afb80c0f799bfb2fd42c44a0c224e".parse().unwrap())
|
BlockId::Hash("9fc84d84f6a785dc1bd5abacfcf9cbdd3b6afb80c0f799bfb2fd42c44a0c224e".parse().unwrap())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -184,12 +184,12 @@ impl ChainNotify for Informant {
|
|||||||
let ripe = Instant::now() > *last_import + Duration::from_secs(1) && !importing;
|
let ripe = Instant::now() > *last_import + Duration::from_secs(1) && !importing;
|
||||||
let txs_imported = imported.iter()
|
let txs_imported = imported.iter()
|
||||||
.take(imported.len() - if ripe {1} else {0})
|
.take(imported.len() - if ripe {1} else {0})
|
||||||
.filter_map(|h| self.client.block(BlockID::Hash(*h)))
|
.filter_map(|h| self.client.block(BlockId::Hash(*h)))
|
||||||
.map(|b| BlockView::new(&b).transactions_count())
|
.map(|b| BlockView::new(&b).transactions_count())
|
||||||
.sum();
|
.sum();
|
||||||
|
|
||||||
if ripe {
|
if ripe {
|
||||||
if let Some(block) = imported.last().and_then(|h| self.client.block(BlockID::Hash(*h))) {
|
if let Some(block) = imported.last().and_then(|h| self.client.block(BlockId::Hash(*h))) {
|
||||||
let view = BlockView::new(&block);
|
let view = BlockView::new(&block);
|
||||||
let header = view.header();
|
let header = view.header();
|
||||||
let tx_count = view.transactions_count();
|
let tx_count = view.transactions_count();
|
||||||
|
@ -26,7 +26,7 @@ use ethcore::snapshot::service::Service as SnapshotService;
|
|||||||
use ethcore::service::ClientService;
|
use ethcore::service::ClientService;
|
||||||
use ethcore::client::{Mode, DatabaseCompactionProfile, VMType};
|
use ethcore::client::{Mode, DatabaseCompactionProfile, VMType};
|
||||||
use ethcore::miner::Miner;
|
use ethcore::miner::Miner;
|
||||||
use ethcore::ids::BlockID;
|
use ethcore::ids::BlockId;
|
||||||
|
|
||||||
use cache::CacheConfig;
|
use cache::CacheConfig;
|
||||||
use params::{SpecType, Pruning, Switch, tracing_switch_to_bool, fatdb_switch_to_bool};
|
use params::{SpecType, Pruning, Switch, tracing_switch_to_bool, fatdb_switch_to_bool};
|
||||||
@ -60,7 +60,7 @@ pub struct SnapshotCommand {
|
|||||||
pub file_path: Option<String>,
|
pub file_path: Option<String>,
|
||||||
pub wal: bool,
|
pub wal: bool,
|
||||||
pub kind: Kind,
|
pub kind: Kind,
|
||||||
pub block_at: BlockID,
|
pub block_at: BlockId,
|
||||||
}
|
}
|
||||||
|
|
||||||
// helper for reading chunks from arbitrary reader and feeding them into the
|
// helper for reading chunks from arbitrary reader and feeding them into the
|
||||||
|
@ -32,7 +32,7 @@ use util::sha3::*;
|
|||||||
use util::{FromHex, Mutex};
|
use util::{FromHex, Mutex};
|
||||||
use rlp::{self, UntrustedRlp, View};
|
use rlp::{self, UntrustedRlp, View};
|
||||||
use ethcore::account_provider::AccountProvider;
|
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::header::{Header as BlockHeader, BlockNumber as EthBlockNumber};
|
||||||
use ethcore::block::IsBlock;
|
use ethcore::block::IsBlock;
|
||||||
use ethcore::views::*;
|
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);
|
let client = take_weak!(self.client);
|
||||||
match (client.block(id.clone()), client.block_total_difficulty(id)) {
|
match (client.block(id.clone()), client.block_total_difficulty(id)) {
|
||||||
(Some(bytes), Some(total_difficulty)) => {
|
(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) {
|
match take_weak!(self.client).transaction(id) {
|
||||||
Some(t) => Ok(Some(Transaction::from(t))),
|
Some(t) => Ok(Some(Transaction::from(t))),
|
||||||
None => Ok(None),
|
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 client = take_weak!(self.client);
|
||||||
let uncle: BlockHeader = match client.uncle(id) {
|
let uncle: BlockHeader = match client.uncle(id) {
|
||||||
Some(rlp) => rlp::decode(&rlp),
|
Some(rlp) => rlp::decode(&rlp),
|
||||||
None => { return Ok(None); }
|
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,
|
Some(difficulty) => difficulty,
|
||||||
None => { return Ok(None); }
|
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> {
|
fn block_transaction_count_by_hash(&self, hash: RpcH256) -> Result<Option<RpcU256>, Error> {
|
||||||
try!(self.active());
|
try!(self.active());
|
||||||
Ok(
|
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())
|
.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());
|
try!(self.active());
|
||||||
|
|
||||||
Ok(
|
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())
|
.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> {
|
fn block_by_hash(&self, hash: RpcH256, include_txs: bool) -> Result<Option<RichBlock>, Error> {
|
||||||
try!(self.active());
|
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> {
|
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 hash: H256 = hash.into();
|
||||||
let miner = take_weak!(self.miner);
|
let miner = take_weak!(self.miner);
|
||||||
let client = take_weak!(self.client);
|
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> {
|
fn transaction_by_block_hash_and_index(&self, hash: RpcH256, index: Index) -> Result<Option<Transaction>, Error> {
|
||||||
try!(self.active());
|
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> {
|
fn transaction_by_block_number_and_index(&self, num: BlockNumber, index: Index) -> Result<Option<Transaction>, Error> {
|
||||||
try!(self.active());
|
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> {
|
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())),
|
(Some(receipt), true) => Ok(Some(receipt.into())),
|
||||||
_ => {
|
_ => {
|
||||||
let client = take_weak!(self.client);
|
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))
|
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> {
|
fn uncle_by_block_hash_and_index(&self, hash: RpcH256, index: Index) -> Result<Option<RichBlock>, Error> {
|
||||||
try!(self.active());
|
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> {
|
fn uncle_by_block_number_and_index(&self, num: BlockNumber, index: Index) -> Result<Option<RichBlock>, Error> {
|
||||||
try!(self.active());
|
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> {
|
fn compilers(&self) -> Result<Vec<String>, Error> {
|
||||||
|
@ -21,7 +21,7 @@ use std::collections::HashSet;
|
|||||||
use jsonrpc_core::*;
|
use jsonrpc_core::*;
|
||||||
use ethcore::miner::MinerService;
|
use ethcore::miner::MinerService;
|
||||||
use ethcore::filter::Filter as EthcoreFilter;
|
use ethcore::filter::Filter as EthcoreFilter;
|
||||||
use ethcore::client::{BlockChainClient, BlockID};
|
use ethcore::client::{BlockChainClient, BlockId};
|
||||||
use util::Mutex;
|
use util::Mutex;
|
||||||
use v1::traits::EthFilter;
|
use v1::traits::EthFilter;
|
||||||
use v1::types::{BlockNumber, Index, Filter, FilterChanges, Log, H256 as RpcH256, U256 as RpcU256};
|
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.
|
// + 1, cause we want to return hashes including current block hash.
|
||||||
let current_number = client.chain_info().best_block_number + 1;
|
let current_number = client.chain_info().best_block_number + 1;
|
||||||
let hashes = (*block_number..current_number).into_iter()
|
let hashes = (*block_number..current_number).into_iter()
|
||||||
.map(BlockID::Number)
|
.map(BlockId::Number)
|
||||||
.filter_map(|id| client.block_hash(id))
|
.filter_map(|id| client.block_hash(id))
|
||||||
.map(Into::into)
|
.map(Into::into)
|
||||||
.collect::<Vec<RpcH256>>();
|
.collect::<Vec<RpcH256>>();
|
||||||
@ -140,10 +140,10 @@ impl<C, M> EthFilter for EthFilterClient<C, M>
|
|||||||
|
|
||||||
// build appropriate filter
|
// build appropriate filter
|
||||||
let mut filter: EthcoreFilter = filter.clone().into();
|
let mut filter: EthcoreFilter = filter.clone().into();
|
||||||
filter.from_block = BlockID::Number(*block_number);
|
filter.from_block = BlockId::Number(*block_number);
|
||||||
filter.to_block = BlockID::Latest;
|
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())
|
let mut logs = client.logs(filter.clone())
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(From::from)
|
.map(From::from)
|
||||||
|
@ -89,11 +89,13 @@ impl<C: 'static, M: 'static> Signer for SignerClient<C, M> where C: MiningBlockC
|
|||||||
signer.peek(&id).map(|confirmation| {
|
signer.peek(&id).map(|confirmation| {
|
||||||
let mut payload = confirmation.payload.clone();
|
let mut payload = confirmation.payload.clone();
|
||||||
// Modify payload
|
// Modify payload
|
||||||
match (&mut payload, modification.gas_price) {
|
if let ConfirmationPayload::SendTransaction(ref mut request) = payload {
|
||||||
(&mut ConfirmationPayload::SendTransaction(ref mut request), Some(gas_price)) => {
|
if let Some(gas_price) = modification.gas_price {
|
||||||
request.gas_price = gas_price.into();
|
request.gas_price = gas_price.into();
|
||||||
},
|
}
|
||||||
_ => {},
|
if let Some(gas) = modification.gas {
|
||||||
|
request.gas = gas.into();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Execute
|
// Execute
|
||||||
let result = dispatch::execute(&*client, &*miner, &*accounts, payload, Some(pass));
|
let result = dispatch::execute(&*client, &*miner, &*accounts, payload, Some(pass));
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
use std::sync::{Weak, Arc};
|
use std::sync::{Weak, Arc};
|
||||||
use jsonrpc_core::*;
|
use jsonrpc_core::*;
|
||||||
use rlp::{UntrustedRlp, View};
|
use rlp::{UntrustedRlp, View};
|
||||||
use ethcore::client::{BlockChainClient, CallAnalytics, TransactionID, TraceId};
|
use ethcore::client::{BlockChainClient, CallAnalytics, TransactionId, TraceId};
|
||||||
use ethcore::miner::MinerService;
|
use ethcore::miner::MinerService;
|
||||||
use ethcore::transaction::{Transaction as EthTransaction, SignedTransaction, Action};
|
use ethcore::transaction::{Transaction as EthTransaction, SignedTransaction, Action};
|
||||||
use v1::traits::Traces;
|
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)
|
from_params::<(H256,)>(params)
|
||||||
.and_then(|(transaction_hash,)| {
|
.and_then(|(transaction_hash,)| {
|
||||||
let client = take_weak!(self.client);
|
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());
|
let traces = traces.map_or_else(Vec::new, |traces| traces.into_iter().map(LocalizedTrace::from).collect());
|
||||||
Ok(to_value(&traces))
|
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)| {
|
.and_then(|(transaction_hash, address)| {
|
||||||
let client = take_weak!(self.client);
|
let client = take_weak!(self.client);
|
||||||
let id = TraceId {
|
let id = TraceId {
|
||||||
transaction: TransactionID::Hash(transaction_hash.into()),
|
transaction: TransactionId::Hash(transaction_hash.into()),
|
||||||
address: address.into_iter().map(|i| i.value()).collect()
|
address: address.into_iter().map(|i| i.value()).collect()
|
||||||
};
|
};
|
||||||
let trace = client.trace(id);
|
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());
|
try!(self.active());
|
||||||
from_params::<(H256, _)>(params)
|
from_params::<(H256, _)>(params)
|
||||||
.and_then(|(transaction_hash, flags)| {
|
.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(e) => Ok(to_value(&TraceResults::from(e))),
|
||||||
_ => Ok(Value::Null),
|
_ => Ok(Value::Null),
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ use std::sync::Arc;
|
|||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use ethcore::client::{BlockChainClient, Client, ClientConfig};
|
use ethcore::client::{BlockChainClient, Client, ClientConfig};
|
||||||
use ethcore::ids::BlockID;
|
use ethcore::ids::BlockId;
|
||||||
use ethcore::spec::{Genesis, Spec};
|
use ethcore::spec::{Genesis, Spec};
|
||||||
use ethcore::block::Block;
|
use ethcore::block::Block;
|
||||||
use ethcore::views::BlockView;
|
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));
|
assert_eq!(tester.handler.handle_request_sync(&req), Some(res));
|
||||||
|
|
||||||
// uncles can share block numbers, so skip them.
|
// 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);
|
let (req, res) = by_number(number, count, &mut id);
|
||||||
assert_eq!(tester.handler.handle_request_sync(&req), Some(res));
|
assert_eq!(tester.handler.handle_request_sync(&req), Some(res));
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ use rlp;
|
|||||||
|
|
||||||
use util::{Uint, U256, Address, H256, FixedHash, Mutex};
|
use util::{Uint, U256, Address, H256, FixedHash, Mutex};
|
||||||
use ethcore::account_provider::AccountProvider;
|
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::log_entry::{LocalizedLogEntry, LogEntry};
|
||||||
use ethcore::receipt::LocalizedReceipt;
|
use ethcore::receipt::LocalizedReceipt;
|
||||||
use ethcore::transaction::{Transaction, Action};
|
use ethcore::transaction::{Transaction, Action};
|
||||||
@ -952,7 +952,7 @@ fn rpc_eth_transaction_receipt() {
|
|||||||
|
|
||||||
let hash = H256::from_str("b903239f8543d04b5dc1ba6579132b143087c68db1b2168786408fcbce568238").unwrap();
|
let hash = H256::from_str("b903239f8543d04b5dc1ba6579132b143087c68db1b2168786408fcbce568238").unwrap();
|
||||||
let tester = EthTester::default();
|
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#"{
|
let request = r#"{
|
||||||
"jsonrpc": "2.0",
|
"jsonrpc": "2.0",
|
||||||
|
@ -183,7 +183,7 @@ fn should_confirm_transaction_and_dispatch() {
|
|||||||
let t = Transaction {
|
let t = Transaction {
|
||||||
nonce: U256::zero(),
|
nonce: U256::zero(),
|
||||||
gas_price: U256::from(0x1000),
|
gas_price: U256::from(0x1000),
|
||||||
gas: U256::from(10_000_000),
|
gas: U256::from(0x50505),
|
||||||
action: Action::Call(recipient),
|
action: Action::Call(recipient),
|
||||||
value: U256::from(0x1),
|
value: U256::from(0x1),
|
||||||
data: vec![]
|
data: vec![]
|
||||||
@ -198,7 +198,7 @@ fn should_confirm_transaction_and_dispatch() {
|
|||||||
let request = r#"{
|
let request = r#"{
|
||||||
"jsonrpc":"2.0",
|
"jsonrpc":"2.0",
|
||||||
"method":"signer_confirmRequest",
|
"method":"signer_confirmRequest",
|
||||||
"params":["0x1", {"gasPrice":"0x1000"}, "test"],
|
"params":["0x1", {"gasPrice":"0x1000","gas":"0x50505"}, "test"],
|
||||||
"id":1
|
"id":1
|
||||||
}"#;
|
}"#;
|
||||||
let response = r#"{"jsonrpc":"2.0","result":""#.to_owned() + format!("0x{:?}", t.hash()).as_ref() + r#"","id":1}"#;
|
let response = r#"{"jsonrpc":"2.0","result":""#.to_owned() + format!("0x{:?}", t.hash()).as_ref() + r#"","id":1}"#;
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
use serde::{Deserialize, Deserializer, Error};
|
use serde::{Deserialize, Deserializer, Error};
|
||||||
use serde::de::Visitor;
|
use serde::de::Visitor;
|
||||||
use ethcore::client::BlockID;
|
use ethcore::client::BlockId;
|
||||||
|
|
||||||
/// Represents rpc api block number param.
|
/// Represents rpc api block number param.
|
||||||
#[derive(Debug, PartialEq, Clone)]
|
#[derive(Debug, PartialEq, Clone)]
|
||||||
@ -64,20 +64,20 @@ impl Visitor for BlockNumberVisitor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Into<BlockID> for BlockNumber {
|
impl Into<BlockId> for BlockNumber {
|
||||||
fn into(self) -> BlockID {
|
fn into(self) -> BlockId {
|
||||||
match self {
|
match self {
|
||||||
BlockNumber::Num(n) => BlockID::Number(n),
|
BlockNumber::Num(n) => BlockId::Number(n),
|
||||||
BlockNumber::Earliest => BlockID::Earliest,
|
BlockNumber::Earliest => BlockId::Earliest,
|
||||||
BlockNumber::Latest => BlockID::Latest,
|
BlockNumber::Latest => BlockId::Latest,
|
||||||
BlockNumber::Pending => BlockID::Pending,
|
BlockNumber::Pending => BlockId::Pending,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use ethcore::client::BlockID;
|
use ethcore::client::BlockId;
|
||||||
use super::*;
|
use super::*;
|
||||||
use serde_json;
|
use serde_json;
|
||||||
|
|
||||||
@ -90,10 +90,10 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn block_number_into() {
|
fn block_number_into() {
|
||||||
assert_eq!(BlockID::Number(100), BlockNumber::Num(100).into());
|
assert_eq!(BlockId::Number(100), BlockNumber::Num(100).into());
|
||||||
assert_eq!(BlockID::Earliest, BlockNumber::Earliest.into());
|
assert_eq!(BlockId::Earliest, BlockNumber::Earliest.into());
|
||||||
assert_eq!(BlockID::Latest, BlockNumber::Latest.into());
|
assert_eq!(BlockId::Latest, BlockNumber::Latest.into());
|
||||||
assert_eq!(BlockID::Pending, BlockNumber::Pending.into());
|
assert_eq!(BlockId::Pending, BlockNumber::Pending.into());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,6 +142,8 @@ pub struct TransactionModification {
|
|||||||
/// Modified gas price
|
/// Modified gas price
|
||||||
#[serde(rename="gasPrice")]
|
#[serde(rename="gasPrice")]
|
||||||
pub gas_price: Option<U256>,
|
pub gas_price: Option<U256>,
|
||||||
|
/// Modified gas
|
||||||
|
pub gas: Option<U256>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Represents two possible return values.
|
/// Represents two possible return values.
|
||||||
@ -275,18 +277,26 @@ mod tests {
|
|||||||
let s1 = r#"{
|
let s1 = r#"{
|
||||||
"gasPrice":"0xba43b7400"
|
"gasPrice":"0xba43b7400"
|
||||||
}"#;
|
}"#;
|
||||||
let s2 = r#"{}"#;
|
let s2 = r#"{"gas": "0x1233"}"#;
|
||||||
|
let s3 = r#"{}"#;
|
||||||
|
|
||||||
// when
|
// when
|
||||||
let res1: TransactionModification = serde_json::from_str(s1).unwrap();
|
let res1: TransactionModification = serde_json::from_str(s1).unwrap();
|
||||||
let res2: TransactionModification = serde_json::from_str(s2).unwrap();
|
let res2: TransactionModification = serde_json::from_str(s2).unwrap();
|
||||||
|
let res3: TransactionModification = serde_json::from_str(s3).unwrap();
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assert_eq!(res1, TransactionModification {
|
assert_eq!(res1, TransactionModification {
|
||||||
gas_price: Some(U256::from_str("0ba43b7400").unwrap()),
|
gas_price: Some(U256::from_str("0ba43b7400").unwrap()),
|
||||||
|
gas: None,
|
||||||
});
|
});
|
||||||
assert_eq!(res2, TransactionModification {
|
assert_eq!(res2, TransactionModification {
|
||||||
gas_price: None,
|
gas_price: None,
|
||||||
|
gas: Some(U256::from_str("1233").unwrap()),
|
||||||
|
});
|
||||||
|
assert_eq!(res3, TransactionModification {
|
||||||
|
gas_price: None,
|
||||||
|
gas: None,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer, Error};
|
|||||||
use serde_json::value;
|
use serde_json::value;
|
||||||
use jsonrpc_core::Value;
|
use jsonrpc_core::Value;
|
||||||
use ethcore::filter::Filter as EthFilter;
|
use ethcore::filter::Filter as EthFilter;
|
||||||
use ethcore::client::BlockID;
|
use ethcore::client::BlockId;
|
||||||
use v1::types::{BlockNumber, H160, H256, Log};
|
use v1::types::{BlockNumber, H160, H256, Log};
|
||||||
|
|
||||||
/// Variadic value
|
/// Variadic value
|
||||||
@ -73,8 +73,8 @@ pub struct Filter {
|
|||||||
impl Into<EthFilter> for Filter {
|
impl Into<EthFilter> for Filter {
|
||||||
fn into(self) -> EthFilter {
|
fn into(self) -> EthFilter {
|
||||||
EthFilter {
|
EthFilter {
|
||||||
from_block: self.from_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),
|
to_block: self.to_block.map_or_else(|| BlockId::Latest, Into::into),
|
||||||
address: self.address.and_then(|address| match address {
|
address: self.address.and_then(|address| match address {
|
||||||
VariadicValue::Null => None,
|
VariadicValue::Null => None,
|
||||||
VariadicValue::Single(a) => Some(vec![a.into()]),
|
VariadicValue::Single(a) => Some(vec![a.into()]),
|
||||||
@ -128,7 +128,7 @@ mod tests {
|
|||||||
use super::{VariadicValue, Topic, Filter};
|
use super::{VariadicValue, Topic, Filter};
|
||||||
use v1::types::BlockNumber;
|
use v1::types::BlockNumber;
|
||||||
use ethcore::filter::Filter as EthFilter;
|
use ethcore::filter::Filter as EthFilter;
|
||||||
use ethcore::client::BlockID;
|
use ethcore::client::BlockId;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn topic_deserialization() {
|
fn topic_deserialization() {
|
||||||
@ -173,8 +173,8 @@ mod tests {
|
|||||||
|
|
||||||
let eth_filter: EthFilter = filter.into();
|
let eth_filter: EthFilter = filter.into();
|
||||||
assert_eq!(eth_filter, EthFilter {
|
assert_eq!(eth_filter, EthFilter {
|
||||||
from_block: BlockID::Earliest,
|
from_block: BlockId::Earliest,
|
||||||
to_block: BlockID::Latest,
|
to_block: BlockId::Latest,
|
||||||
address: Some(vec![]),
|
address: Some(vec![]),
|
||||||
topics: vec![
|
topics: vec![
|
||||||
None,
|
None,
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
//! Trace filter deserialization.
|
//! Trace filter deserialization.
|
||||||
|
|
||||||
use ethcore::client::BlockID;
|
use ethcore::client::BlockId;
|
||||||
use ethcore::client;
|
use ethcore::client;
|
||||||
use v1::types::{BlockNumber, H160};
|
use v1::types::{BlockNumber, H160};
|
||||||
|
|
||||||
@ -40,8 +40,8 @@ pub struct TraceFilter {
|
|||||||
|
|
||||||
impl Into<client::TraceFilter> for TraceFilter {
|
impl Into<client::TraceFilter> for TraceFilter {
|
||||||
fn into(self) -> client::TraceFilter {
|
fn into(self) -> client::TraceFilter {
|
||||||
let start = self.from_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);
|
let end = self.to_block.map_or(BlockId::Latest, Into::into);
|
||||||
client::TraceFilter {
|
client::TraceFilter {
|
||||||
range: start..end,
|
range: start..end,
|
||||||
from_address: self.from_address.map_or_else(Vec::new, |x| x.into_iter().map(Into::into).collect()),
|
from_address: self.from_address.map_or_else(Vec::new, |x| x.into_iter().map(Into::into).collect()),
|
||||||
|
@ -22,7 +22,7 @@ use util::*;
|
|||||||
use rlp::*;
|
use rlp::*;
|
||||||
use ethcore::views::{BlockView};
|
use ethcore::views::{BlockView};
|
||||||
use ethcore::header::{BlockNumber, Header as BlockHeader};
|
use ethcore::header::{BlockNumber, Header as BlockHeader};
|
||||||
use ethcore::client::{BlockStatus, BlockID, BlockImportError};
|
use ethcore::client::{BlockStatus, BlockId, BlockImportError};
|
||||||
use ethcore::block::Block;
|
use ethcore::block::Block;
|
||||||
use ethcore::error::{ImportError, BlockError};
|
use ethcore::error::{ImportError, BlockError};
|
||||||
use sync_io::SyncIo;
|
use sync_io::SyncIo;
|
||||||
@ -225,7 +225,7 @@ impl BlockDownloader {
|
|||||||
trace!(target: "sync", "Error decoding block header RLP: {:?}", e);
|
trace!(target: "sync", "Error decoding block header RLP: {:?}", e);
|
||||||
BlockDownloaderImportError::Invalid
|
BlockDownloaderImportError::Invalid
|
||||||
}));
|
}));
|
||||||
match io.chain().block_status(BlockID::Hash(hash.clone())) {
|
match io.chain().block_status(BlockId::Hash(hash.clone())) {
|
||||||
BlockStatus::InChain | BlockStatus::Queued => {
|
BlockStatus::InChain | BlockStatus::Queued => {
|
||||||
match self.state {
|
match self.state {
|
||||||
State::Blocks => trace!(target: "sync", "Header already in chain {} ({})", number, hash),
|
State::Blocks => trace!(target: "sync", "Header already in chain {} ({})", number, hash),
|
||||||
@ -353,7 +353,7 @@ impl BlockDownloader {
|
|||||||
debug!(target: "sync", "Could not revert to previous ancient block, last: {} ({})", self.last_imported_block, self.last_imported_hash);
|
debug!(target: "sync", "Could not revert to previous ancient block, last: {} ({})", self.last_imported_block, self.last_imported_hash);
|
||||||
self.reset();
|
self.reset();
|
||||||
} else {
|
} else {
|
||||||
match io.chain().block_hash(BlockID::Number(self.last_imported_block - 1)) {
|
match io.chain().block_hash(BlockId::Number(self.last_imported_block - 1)) {
|
||||||
Some(h) => {
|
Some(h) => {
|
||||||
self.last_imported_block -= 1;
|
self.last_imported_block -= 1;
|
||||||
self.last_imported_hash = h;
|
self.last_imported_hash = h;
|
||||||
|
@ -475,7 +475,7 @@ impl BlockCollection {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::BlockCollection;
|
use super::BlockCollection;
|
||||||
use ethcore::client::{TestBlockChainClient, EachBlockWith, BlockID, BlockChainClient};
|
use ethcore::client::{TestBlockChainClient, EachBlockWith, BlockId, BlockChainClient};
|
||||||
use ethcore::views::HeaderView;
|
use ethcore::views::HeaderView;
|
||||||
use ethcore::header::BlockNumber;
|
use ethcore::header::BlockNumber;
|
||||||
use util::*;
|
use util::*;
|
||||||
@ -497,7 +497,7 @@ mod test {
|
|||||||
assert!(is_empty(&bc));
|
assert!(is_empty(&bc));
|
||||||
let client = TestBlockChainClient::new();
|
let client = TestBlockChainClient::new();
|
||||||
client.add_blocks(100, EachBlockWith::Nothing);
|
client.add_blocks(100, EachBlockWith::Nothing);
|
||||||
let hashes = (0 .. 100).map(|i| (&client as &BlockChainClient).block_hash(BlockID::Number(i)).unwrap()).collect();
|
let hashes = (0 .. 100).map(|i| (&client as &BlockChainClient).block_hash(BlockId::Number(i)).unwrap()).collect();
|
||||||
bc.reset_to(hashes);
|
bc.reset_to(hashes);
|
||||||
assert!(!is_empty(&bc));
|
assert!(!is_empty(&bc));
|
||||||
bc.clear();
|
bc.clear();
|
||||||
@ -511,7 +511,7 @@ mod test {
|
|||||||
let client = TestBlockChainClient::new();
|
let client = TestBlockChainClient::new();
|
||||||
let nblocks = 200;
|
let nblocks = 200;
|
||||||
client.add_blocks(nblocks, EachBlockWith::Nothing);
|
client.add_blocks(nblocks, EachBlockWith::Nothing);
|
||||||
let blocks: Vec<_> = (0 .. nblocks).map(|i| (&client as &BlockChainClient).block(BlockID::Number(i as BlockNumber)).unwrap()).collect();
|
let blocks: Vec<_> = (0 .. nblocks).map(|i| (&client as &BlockChainClient).block(BlockId::Number(i as BlockNumber)).unwrap()).collect();
|
||||||
let headers: Vec<_> = blocks.iter().map(|b| Rlp::new(b).at(0).as_raw().to_vec()).collect();
|
let headers: Vec<_> = blocks.iter().map(|b| Rlp::new(b).at(0).as_raw().to_vec()).collect();
|
||||||
let hashes: Vec<_> = headers.iter().map(|h| HeaderView::new(h).sha3()).collect();
|
let hashes: Vec<_> = headers.iter().map(|h| HeaderView::new(h).sha3()).collect();
|
||||||
let heads: Vec<_> = hashes.iter().enumerate().filter_map(|(i, h)| if i % 20 == 0 { Some(h.clone()) } else { None }).collect();
|
let heads: Vec<_> = hashes.iter().enumerate().filter_map(|(i, h)| if i % 20 == 0 { Some(h.clone()) } else { None }).collect();
|
||||||
@ -564,7 +564,7 @@ mod test {
|
|||||||
let client = TestBlockChainClient::new();
|
let client = TestBlockChainClient::new();
|
||||||
let nblocks = 200;
|
let nblocks = 200;
|
||||||
client.add_blocks(nblocks, EachBlockWith::Nothing);
|
client.add_blocks(nblocks, EachBlockWith::Nothing);
|
||||||
let blocks: Vec<_> = (0 .. nblocks).map(|i| (&client as &BlockChainClient).block(BlockID::Number(i as BlockNumber)).unwrap()).collect();
|
let blocks: Vec<_> = (0 .. nblocks).map(|i| (&client as &BlockChainClient).block(BlockId::Number(i as BlockNumber)).unwrap()).collect();
|
||||||
let headers: Vec<_> = blocks.iter().map(|b| Rlp::new(b).at(0).as_raw().to_vec()).collect();
|
let headers: Vec<_> = blocks.iter().map(|b| Rlp::new(b).at(0).as_raw().to_vec()).collect();
|
||||||
let hashes: Vec<_> = headers.iter().map(|h| HeaderView::new(h).sha3()).collect();
|
let hashes: Vec<_> = headers.iter().map(|h| HeaderView::new(h).sha3()).collect();
|
||||||
let heads: Vec<_> = hashes.iter().enumerate().filter_map(|(i, h)| if i % 20 == 0 { Some(h.clone()) } else { None }).collect();
|
let heads: Vec<_> = hashes.iter().enumerate().filter_map(|(i, h)| if i % 20 == 0 { Some(h.clone()) } else { None }).collect();
|
||||||
@ -586,7 +586,7 @@ mod test {
|
|||||||
let client = TestBlockChainClient::new();
|
let client = TestBlockChainClient::new();
|
||||||
let nblocks = 200;
|
let nblocks = 200;
|
||||||
client.add_blocks(nblocks, EachBlockWith::Nothing);
|
client.add_blocks(nblocks, EachBlockWith::Nothing);
|
||||||
let blocks: Vec<_> = (0 .. nblocks).map(|i| (&client as &BlockChainClient).block(BlockID::Number(i as BlockNumber)).unwrap()).collect();
|
let blocks: Vec<_> = (0 .. nblocks).map(|i| (&client as &BlockChainClient).block(BlockId::Number(i as BlockNumber)).unwrap()).collect();
|
||||||
let headers: Vec<_> = blocks.iter().map(|b| Rlp::new(b).at(0).as_raw().to_vec()).collect();
|
let headers: Vec<_> = blocks.iter().map(|b| Rlp::new(b).at(0).as_raw().to_vec()).collect();
|
||||||
let hashes: Vec<_> = headers.iter().map(|h| HeaderView::new(h).sha3()).collect();
|
let hashes: Vec<_> = headers.iter().map(|h| HeaderView::new(h).sha3()).collect();
|
||||||
let heads: Vec<_> = hashes.iter().enumerate().filter_map(|(i, h)| if i % 20 == 0 { Some(h.clone()) } else { None }).collect();
|
let heads: Vec<_> = hashes.iter().enumerate().filter_map(|(i, h)| if i % 20 == 0 { Some(h.clone()) } else { None }).collect();
|
||||||
|
@ -94,7 +94,7 @@ use rlp::*;
|
|||||||
use network::*;
|
use network::*;
|
||||||
use ethcore::views::{HeaderView};
|
use ethcore::views::{HeaderView};
|
||||||
use ethcore::header::{BlockNumber, Header as BlockHeader};
|
use ethcore::header::{BlockNumber, Header as BlockHeader};
|
||||||
use ethcore::client::{BlockChainClient, BlockStatus, BlockID, BlockChainInfo, BlockImportError};
|
use ethcore::client::{BlockChainClient, BlockStatus, BlockId, BlockChainInfo, BlockImportError};
|
||||||
use ethcore::error::*;
|
use ethcore::error::*;
|
||||||
use ethcore::snapshot::{ManifestData, RestorationStatus};
|
use ethcore::snapshot::{ManifestData, RestorationStatus};
|
||||||
use sync_io::SyncIo;
|
use sync_io::SyncIo;
|
||||||
@ -934,7 +934,7 @@ impl ChainSync {
|
|||||||
io.disable_peer(peer_id);
|
io.disable_peer(peer_id);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
match io.chain().block_status(BlockID::Hash(hash.clone())) {
|
match io.chain().block_status(BlockId::Hash(hash.clone())) {
|
||||||
BlockStatus::InChain => {
|
BlockStatus::InChain => {
|
||||||
trace!(target: "sync", "New block hash already in chain {:?}", hash);
|
trace!(target: "sync", "New block hash already in chain {:?}", hash);
|
||||||
},
|
},
|
||||||
@ -1155,7 +1155,7 @@ impl ChainSync {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let have_latest = io.chain().block_status(BlockID::Hash(peer_latest)) != BlockStatus::Unknown;
|
let have_latest = io.chain().block_status(BlockId::Hash(peer_latest)) != BlockStatus::Unknown;
|
||||||
if !have_latest && (higher_difficulty || force || self.state == SyncState::NewBlocks) {
|
if !have_latest && (higher_difficulty || force || self.state == SyncState::NewBlocks) {
|
||||||
// check if got new blocks to download
|
// check if got new blocks to download
|
||||||
trace!(target: "sync", "Syncing with {}, force={}, td={:?}, our td={}, state={:?}", peer_id, force, peer_difficulty, syncing_difficulty, self.state);
|
trace!(target: "sync", "Syncing with {}, force={}, td={:?}, our td={}, state={:?}", peer_id, force, peer_difficulty, syncing_difficulty, self.state);
|
||||||
@ -1450,11 +1450,11 @@ impl ChainSync {
|
|||||||
// id is a hash
|
// id is a hash
|
||||||
let hash: H256 = try!(r.val_at(0));
|
let hash: H256 = try!(r.val_at(0));
|
||||||
trace!(target: "sync", "{} -> GetBlockHeaders (hash: {}, max: {}, skip: {}, reverse:{})", peer_id, hash, max_headers, skip, reverse);
|
trace!(target: "sync", "{} -> GetBlockHeaders (hash: {}, max: {}, skip: {}, reverse:{})", peer_id, hash, max_headers, skip, reverse);
|
||||||
match io.chain().block_header(BlockID::Hash(hash)) {
|
match io.chain().block_header(BlockId::Hash(hash)) {
|
||||||
Some(hdr) => {
|
Some(hdr) => {
|
||||||
let number = From::from(HeaderView::new(&hdr).number());
|
let number = From::from(HeaderView::new(&hdr).number());
|
||||||
debug_assert_eq!(HeaderView::new(&hdr).sha3(), hash);
|
debug_assert_eq!(HeaderView::new(&hdr).sha3(), hash);
|
||||||
if max_headers == 1 || io.chain().block_hash(BlockID::Number(number)) != Some(hash) {
|
if max_headers == 1 || io.chain().block_hash(BlockId::Number(number)) != Some(hash) {
|
||||||
// Non canonical header or single header requested
|
// Non canonical header or single header requested
|
||||||
// TODO: handle single-step reverse hashchains of non-canon hashes
|
// TODO: handle single-step reverse hashchains of non-canon hashes
|
||||||
trace!(target:"sync", "Returning single header: {:?}", hash);
|
trace!(target:"sync", "Returning single header: {:?}", hash);
|
||||||
@ -1487,7 +1487,7 @@ impl ChainSync {
|
|||||||
trace!(target: "sync", "{}: Returning cached fork header", peer_id);
|
trace!(target: "sync", "{}: Returning cached fork header", peer_id);
|
||||||
data.extend_from_slice(hdr);
|
data.extend_from_slice(hdr);
|
||||||
count += 1;
|
count += 1;
|
||||||
} else if let Some(mut hdr) = io.chain().block_header(BlockID::Number(number)) {
|
} else if let Some(mut hdr) = io.chain().block_header(BlockId::Number(number)) {
|
||||||
data.append(&mut hdr);
|
data.append(&mut hdr);
|
||||||
count += 1;
|
count += 1;
|
||||||
} else {
|
} else {
|
||||||
@ -1521,7 +1521,7 @@ impl ChainSync {
|
|||||||
let mut added = 0usize;
|
let mut added = 0usize;
|
||||||
let mut data = Bytes::new();
|
let mut data = Bytes::new();
|
||||||
for i in 0..count {
|
for i in 0..count {
|
||||||
if let Some(mut hdr) = io.chain().block_body(BlockID::Hash(try!(r.val_at::<H256>(i)))) {
|
if let Some(mut hdr) = io.chain().block_body(BlockId::Hash(try!(r.val_at::<H256>(i)))) {
|
||||||
data.append(&mut hdr);
|
data.append(&mut hdr);
|
||||||
added += 1;
|
added += 1;
|
||||||
}
|
}
|
||||||
@ -1678,7 +1678,7 @@ impl ChainSync {
|
|||||||
|
|
||||||
pub fn on_packet(&mut self, io: &mut SyncIo, peer: PeerId, packet_id: u8, data: &[u8]) {
|
pub fn on_packet(&mut self, io: &mut SyncIo, peer: PeerId, packet_id: u8, data: &[u8]) {
|
||||||
if packet_id != STATUS_PACKET && !self.peers.contains_key(&peer) {
|
if packet_id != STATUS_PACKET && !self.peers.contains_key(&peer) {
|
||||||
debug!(target:"sync", "Unexpected packet from unregistered peer: {}:{}", peer, io.peer_info(peer));
|
debug!(target:"sync", "Unexpected packet {} from unregistered peer: {}:{}", packet_id, peer, io.peer_info(peer));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let rlp = UntrustedRlp::new(data);
|
let rlp = UntrustedRlp::new(data);
|
||||||
@ -1778,7 +1778,7 @@ impl ChainSync {
|
|||||||
let mut rlp_stream = RlpStream::new_list(blocks.len());
|
let mut rlp_stream = RlpStream::new_list(blocks.len());
|
||||||
for block_hash in blocks {
|
for block_hash in blocks {
|
||||||
let mut hash_rlp = RlpStream::new_list(2);
|
let mut hash_rlp = RlpStream::new_list(2);
|
||||||
let number = HeaderView::new(&chain.block_header(BlockID::Hash(block_hash.clone()))
|
let number = HeaderView::new(&chain.block_header(BlockId::Hash(block_hash.clone()))
|
||||||
.expect("chain.tree_route and chain.find_uncles only return hahses of blocks that are in the blockchain. qed.")).number();
|
.expect("chain.tree_route and chain.find_uncles only return hahses of blocks that are in the blockchain. qed.")).number();
|
||||||
hash_rlp.append(&block_hash);
|
hash_rlp.append(&block_hash);
|
||||||
hash_rlp.append(&number);
|
hash_rlp.append(&number);
|
||||||
@ -1795,7 +1795,7 @@ impl ChainSync {
|
|||||||
/// creates latest block rlp for the given client
|
/// creates latest block rlp for the given client
|
||||||
fn create_latest_block_rlp(chain: &BlockChainClient) -> Bytes {
|
fn create_latest_block_rlp(chain: &BlockChainClient) -> Bytes {
|
||||||
let mut rlp_stream = RlpStream::new_list(2);
|
let mut rlp_stream = RlpStream::new_list(2);
|
||||||
rlp_stream.append_raw(&chain.block(BlockID::Hash(chain.chain_info().best_block_hash)).expect("Best block always exists"), 1);
|
rlp_stream.append_raw(&chain.block(BlockId::Hash(chain.chain_info().best_block_hash)).expect("Best block always exists"), 1);
|
||||||
rlp_stream.append(&chain.chain_info().total_difficulty);
|
rlp_stream.append(&chain.chain_info().total_difficulty);
|
||||||
rlp_stream.out()
|
rlp_stream.out()
|
||||||
}
|
}
|
||||||
@ -1803,8 +1803,8 @@ impl ChainSync {
|
|||||||
/// creates latest block rlp for the given client
|
/// creates latest block rlp for the given client
|
||||||
fn create_new_block_rlp(chain: &BlockChainClient, hash: &H256) -> Bytes {
|
fn create_new_block_rlp(chain: &BlockChainClient, hash: &H256) -> Bytes {
|
||||||
let mut rlp_stream = RlpStream::new_list(2);
|
let mut rlp_stream = RlpStream::new_list(2);
|
||||||
rlp_stream.append_raw(&chain.block(BlockID::Hash(hash.clone())).expect("Block has just been sealed; qed"), 1);
|
rlp_stream.append_raw(&chain.block(BlockId::Hash(hash.clone())).expect("Block has just been sealed; qed"), 1);
|
||||||
rlp_stream.append(&chain.block_total_difficulty(BlockID::Hash(hash.clone())).expect("Block has just been sealed; qed."));
|
rlp_stream.append(&chain.block_total_difficulty(BlockId::Hash(hash.clone())).expect("Block has just been sealed; qed."));
|
||||||
rlp_stream.out()
|
rlp_stream.out()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1812,7 +1812,7 @@ impl ChainSync {
|
|||||||
fn get_lagging_peers(&mut self, chain_info: &BlockChainInfo, io: &SyncIo) -> Vec<PeerId> {
|
fn get_lagging_peers(&mut self, chain_info: &BlockChainInfo, io: &SyncIo) -> Vec<PeerId> {
|
||||||
let latest_hash = chain_info.best_block_hash;
|
let latest_hash = chain_info.best_block_hash;
|
||||||
self.peers.iter_mut().filter_map(|(&id, ref mut peer_info)|
|
self.peers.iter_mut().filter_map(|(&id, ref mut peer_info)|
|
||||||
match io.chain().block_status(BlockID::Hash(peer_info.latest_hash.clone())) {
|
match io.chain().block_status(BlockId::Hash(peer_info.latest_hash.clone())) {
|
||||||
BlockStatus::InChain => {
|
BlockStatus::InChain => {
|
||||||
if peer_info.latest_hash != latest_hash {
|
if peer_info.latest_hash != latest_hash {
|
||||||
Some(id)
|
Some(id)
|
||||||
@ -1863,7 +1863,7 @@ impl ChainSync {
|
|||||||
fn propagate_new_hashes(&mut self, chain_info: &BlockChainInfo, io: &mut SyncIo, peers: &[PeerId]) -> usize {
|
fn propagate_new_hashes(&mut self, chain_info: &BlockChainInfo, io: &mut SyncIo, peers: &[PeerId]) -> usize {
|
||||||
trace!(target: "sync", "Sending NewHashes to {:?}", peers);
|
trace!(target: "sync", "Sending NewHashes to {:?}", peers);
|
||||||
let mut sent = 0;
|
let mut sent = 0;
|
||||||
let last_parent = HeaderView::new(&io.chain().block_header(BlockID::Hash(chain_info.best_block_hash.clone()))
|
let last_parent = HeaderView::new(&io.chain().block_header(BlockId::Hash(chain_info.best_block_hash.clone()))
|
||||||
.expect("Best block always exists")).parent_hash();
|
.expect("Best block always exists")).parent_hash();
|
||||||
for peer_id in peers {
|
for peer_id in peers {
|
||||||
sent += match ChainSync::create_new_hashes_rlp(io.chain(), &last_parent, &chain_info.best_block_hash) {
|
sent += match ChainSync::create_new_hashes_rlp(io.chain(), &last_parent, &chain_info.best_block_hash) {
|
||||||
@ -2125,7 +2125,7 @@ mod tests {
|
|||||||
|
|
||||||
let mut client = TestBlockChainClient::new();
|
let mut client = TestBlockChainClient::new();
|
||||||
client.add_blocks(100, EachBlockWith::Nothing);
|
client.add_blocks(100, EachBlockWith::Nothing);
|
||||||
let blocks: Vec<_> = (0 .. 100).map(|i| (&client as &BlockChainClient).block(BlockID::Number(i as BlockNumber)).unwrap()).collect();
|
let blocks: Vec<_> = (0 .. 100).map(|i| (&client as &BlockChainClient).block(BlockId::Number(i as BlockNumber)).unwrap()).collect();
|
||||||
let headers: Vec<_> = blocks.iter().map(|b| Rlp::new(b).at(0).as_raw().to_vec()).collect();
|
let headers: Vec<_> = blocks.iter().map(|b| Rlp::new(b).at(0).as_raw().to_vec()).collect();
|
||||||
let hashes: Vec<_> = headers.iter().map(|h| HeaderView::new(h).sha3()).collect();
|
let hashes: Vec<_> = headers.iter().map(|h| HeaderView::new(h).sha3()).collect();
|
||||||
|
|
||||||
@ -2298,7 +2298,7 @@ mod tests {
|
|||||||
let mut client = TestBlockChainClient::new();
|
let mut client = TestBlockChainClient::new();
|
||||||
client.add_blocks(100, EachBlockWith::Uncle);
|
client.add_blocks(100, EachBlockWith::Uncle);
|
||||||
let mut queue = VecDeque::new();
|
let mut queue = VecDeque::new();
|
||||||
let hash = client.block_hash(BlockID::Number(99)).unwrap();
|
let hash = client.block_hash(BlockId::Number(99)).unwrap();
|
||||||
let mut sync = dummy_sync_with_peer(client.block_hash_delta_minus(5), &client);
|
let mut sync = dummy_sync_with_peer(client.block_hash_delta_minus(5), &client);
|
||||||
let chain_info = client.chain_info();
|
let chain_info = client.chain_info();
|
||||||
let ss = TestSnapshotService::new();
|
let ss = TestSnapshotService::new();
|
||||||
@ -2556,7 +2556,7 @@ mod tests {
|
|||||||
|
|
||||||
// Add some balance to clients and reset nonces
|
// Add some balance to clients and reset nonces
|
||||||
for h in &[good_blocks[0], retracted_blocks[0]] {
|
for h in &[good_blocks[0], retracted_blocks[0]] {
|
||||||
let block = client.block(BlockID::Hash(*h)).unwrap();
|
let block = client.block(BlockId::Hash(*h)).unwrap();
|
||||||
let view = BlockView::new(&block);
|
let view = BlockView::new(&block);
|
||||||
client.set_balance(view.transactions()[0].sender().unwrap(), U256::from(1_000_000_000));
|
client.set_balance(view.transactions()[0].sender().unwrap(), U256::from(1_000_000_000));
|
||||||
client.set_nonce(view.transactions()[0].sender().unwrap(), U256::from(0));
|
client.set_nonce(view.transactions()[0].sender().unwrap(), U256::from(0));
|
||||||
@ -2575,7 +2575,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
// We need to update nonce status (because we say that the block has been imported)
|
// We need to update nonce status (because we say that the block has been imported)
|
||||||
for h in &[good_blocks[0]] {
|
for h in &[good_blocks[0]] {
|
||||||
let block = client.block(BlockID::Hash(*h)).unwrap();
|
let block = client.block(BlockId::Hash(*h)).unwrap();
|
||||||
let view = BlockView::new(&block);
|
let view = BlockView::new(&block);
|
||||||
client.set_nonce(view.transactions()[0].sender().unwrap(), U256::from(1));
|
client.set_nonce(view.transactions()[0].sender().unwrap(), U256::from(1));
|
||||||
}
|
}
|
||||||
|
@ -131,6 +131,10 @@ impl<'s, 'h> SyncIo for NetSyncIo<'s, 'h> {
|
|||||||
fn protocol_version(&self, protocol: &ProtocolId, peer_id: PeerId) -> u8 {
|
fn protocol_version(&self, protocol: &ProtocolId, peer_id: PeerId) -> u8 {
|
||||||
self.network.protocol_version(*protocol, peer_id).unwrap_or(0)
|
self.network.protocol_version(*protocol, peer_id).unwrap_or(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn peer_info(&self, peer_id: PeerId) -> String {
|
||||||
|
self.network.peer_client_version(peer_id)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use util::*;
|
use util::*;
|
||||||
use ethcore::client::{TestBlockChainClient, BlockChainClient, BlockID, EachBlockWith};
|
use ethcore::client::{TestBlockChainClient, BlockChainClient, BlockId, EachBlockWith};
|
||||||
use chain::{SyncState};
|
use chain::{SyncState};
|
||||||
use super::helpers::*;
|
use super::helpers::*;
|
||||||
use SyncConfig;
|
use SyncConfig;
|
||||||
@ -27,7 +27,7 @@ fn two_peers() {
|
|||||||
net.peer(1).chain.add_blocks(1000, EachBlockWith::Uncle);
|
net.peer(1).chain.add_blocks(1000, EachBlockWith::Uncle);
|
||||||
net.peer(2).chain.add_blocks(1000, EachBlockWith::Uncle);
|
net.peer(2).chain.add_blocks(1000, EachBlockWith::Uncle);
|
||||||
net.sync();
|
net.sync();
|
||||||
assert!(net.peer(0).chain.block(BlockID::Number(1000)).is_some());
|
assert!(net.peer(0).chain.block(BlockId::Number(1000)).is_some());
|
||||||
assert_eq!(*net.peer(0).chain.blocks.read(), *net.peer(1).chain.blocks.read());
|
assert_eq!(*net.peer(0).chain.blocks.read(), *net.peer(1).chain.blocks.read());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,7 +37,7 @@ fn long_chain() {
|
|||||||
let mut net = TestNet::new(2);
|
let mut net = TestNet::new(2);
|
||||||
net.peer(1).chain.add_blocks(50000, EachBlockWith::Nothing);
|
net.peer(1).chain.add_blocks(50000, EachBlockWith::Nothing);
|
||||||
net.sync();
|
net.sync();
|
||||||
assert!(net.peer(0).chain.block(BlockID::Number(50000)).is_some());
|
assert!(net.peer(0).chain.block(BlockId::Number(50000)).is_some());
|
||||||
assert_eq!(*net.peer(0).chain.blocks.read(), *net.peer(1).chain.blocks.read());
|
assert_eq!(*net.peer(0).chain.blocks.read(), *net.peer(1).chain.blocks.read());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,7 +71,7 @@ fn empty_blocks() {
|
|||||||
net.peer(2).chain.add_blocks(5, with);
|
net.peer(2).chain.add_blocks(5, with);
|
||||||
}
|
}
|
||||||
net.sync();
|
net.sync();
|
||||||
assert!(net.peer(0).chain.block(BlockID::Number(1000)).is_some());
|
assert!(net.peer(0).chain.block(BlockId::Number(1000)).is_some());
|
||||||
assert_eq!(*net.peer(0).chain.blocks.read(), *net.peer(1).chain.blocks.read());
|
assert_eq!(*net.peer(0).chain.blocks.read(), *net.peer(1).chain.blocks.read());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -123,13 +123,13 @@ fn net_hard_fork() {
|
|||||||
let ref_client = TestBlockChainClient::new();
|
let ref_client = TestBlockChainClient::new();
|
||||||
ref_client.add_blocks(50, EachBlockWith::Uncle);
|
ref_client.add_blocks(50, EachBlockWith::Uncle);
|
||||||
{
|
{
|
||||||
let mut net = TestNet::new_with_fork(2, Some((50, ref_client.block_hash(BlockID::Number(50)).unwrap())));
|
let mut net = TestNet::new_with_fork(2, Some((50, ref_client.block_hash(BlockId::Number(50)).unwrap())));
|
||||||
net.peer(0).chain.add_blocks(100, EachBlockWith::Uncle);
|
net.peer(0).chain.add_blocks(100, EachBlockWith::Uncle);
|
||||||
net.sync();
|
net.sync();
|
||||||
assert_eq!(net.peer(1).chain.chain_info().best_block_number, 100);
|
assert_eq!(net.peer(1).chain.chain_info().best_block_number, 100);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
let mut net = TestNet::new_with_fork(2, Some((50, ref_client.block_hash(BlockID::Number(50)).unwrap())));
|
let mut net = TestNet::new_with_fork(2, Some((50, ref_client.block_hash(BlockId::Number(50)).unwrap())));
|
||||||
net.peer(0).chain.add_blocks(100, EachBlockWith::Nothing);
|
net.peer(0).chain.add_blocks(100, EachBlockWith::Nothing);
|
||||||
net.sync();
|
net.sync();
|
||||||
assert_eq!(net.peer(1).chain.chain_info().best_block_number, 0);
|
assert_eq!(net.peer(1).chain.chain_info().best_block_number, 0);
|
||||||
|
@ -22,7 +22,7 @@ use std::sync::atomic::{AtomicUsize, AtomicBool, Ordering as AtomicOrdering};
|
|||||||
use std::ops::*;
|
use std::ops::*;
|
||||||
use std::cmp::min;
|
use std::cmp::min;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::io::{Read, Write};
|
use std::io::{Read, Write, ErrorKind};
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use ethkey::{KeyPair, Secret, Random, Generator};
|
use ethkey::{KeyPair, Secret, Random, Generator};
|
||||||
use mio::*;
|
use mio::*;
|
||||||
@ -381,8 +381,6 @@ pub struct Host {
|
|||||||
impl Host {
|
impl Host {
|
||||||
/// Create a new instance
|
/// Create a new instance
|
||||||
pub fn new(mut config: NetworkConfiguration, stats: Arc<NetworkStats>) -> Result<Host, NetworkError> {
|
pub fn new(mut config: NetworkConfiguration, stats: Arc<NetworkStats>) -> Result<Host, NetworkError> {
|
||||||
trace!(target: "host", "Creating new Host object");
|
|
||||||
|
|
||||||
let mut listen_address = match config.listen_address {
|
let mut listen_address = match config.listen_address {
|
||||||
None => SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::new(0, 0, 0, 0), DEFAULT_PORT)),
|
None => SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::new(0, 0, 0, 0), DEFAULT_PORT)),
|
||||||
Some(addr) => addr,
|
Some(addr) => addr,
|
||||||
@ -405,6 +403,7 @@ impl Host {
|
|||||||
// Setup the server socket
|
// Setup the server socket
|
||||||
let tcp_listener = try!(TcpListener::bind(&listen_address));
|
let tcp_listener = try!(TcpListener::bind(&listen_address));
|
||||||
listen_address = SocketAddr::new(listen_address.ip(), try!(tcp_listener.local_addr()).port());
|
listen_address = SocketAddr::new(listen_address.ip(), try!(tcp_listener.local_addr()).port());
|
||||||
|
debug!(target: "network", "Listening at {:?}", listen_address);
|
||||||
let udp_port = config.udp_port.unwrap_or(listen_address.port());
|
let udp_port = config.udp_port.unwrap_or(listen_address.port());
|
||||||
let local_endpoint = NodeEndpoint { address: listen_address, udp_port: udp_port };
|
let local_endpoint = NodeEndpoint { address: listen_address, udp_port: udp_port };
|
||||||
|
|
||||||
@ -707,7 +706,10 @@ impl Host {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
match TcpStream::connect(&address) {
|
match TcpStream::connect(&address) {
|
||||||
Ok(socket) => socket,
|
Ok(socket) => {
|
||||||
|
trace!(target: "network", "Connecting to {:?}", address);
|
||||||
|
socket
|
||||||
|
},
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
debug!(target: "network", "Can't connect to address {:?}: {:?}", address, e);
|
debug!(target: "network", "Can't connect to address {:?}: {:?}", address, e);
|
||||||
return;
|
return;
|
||||||
@ -749,7 +751,9 @@ impl Host {
|
|||||||
let socket = match self.tcp_listener.lock().accept() {
|
let socket = match self.tcp_listener.lock().accept() {
|
||||||
Ok((sock, _addr)) => sock,
|
Ok((sock, _addr)) => sock,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
debug!(target: "network", "Error accepting connection: {:?}", e);
|
if e.kind() != ErrorKind::WouldBlock {
|
||||||
|
debug!(target: "network", "Error accepting connection: {:?}", e);
|
||||||
|
}
|
||||||
break
|
break
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -435,16 +435,16 @@ impl Session {
|
|||||||
|
|
||||||
// map to protocol
|
// map to protocol
|
||||||
let protocol = self.info.capabilities[i].protocol;
|
let protocol = self.info.capabilities[i].protocol;
|
||||||
let pid = packet_id - self.info.capabilities[i].id_offset;
|
let protocol_packet_id = packet_id - self.info.capabilities[i].id_offset;
|
||||||
|
|
||||||
match *self.protocol_states.entry(protocol).or_insert_with(|| ProtocolState::Pending(Vec::new())) {
|
match *self.protocol_states.entry(protocol).or_insert_with(|| ProtocolState::Pending(Vec::new())) {
|
||||||
ProtocolState::Connected => {
|
ProtocolState::Connected => {
|
||||||
trace!(target: "network", "Packet {} mapped to {:?}:{}, i={}, capabilities={:?}", packet_id, protocol, pid, i, self.info.capabilities);
|
trace!(target: "network", "Packet {} mapped to {:?}:{}, i={}, capabilities={:?}", packet_id, protocol, protocol_packet_id, i, self.info.capabilities);
|
||||||
Ok(SessionData::Packet { data: packet.data, protocol: protocol, packet_id: pid } )
|
Ok(SessionData::Packet { data: packet.data, protocol: protocol, packet_id: protocol_packet_id } )
|
||||||
}
|
}
|
||||||
ProtocolState::Pending(ref mut pending) => {
|
ProtocolState::Pending(ref mut pending) => {
|
||||||
trace!(target: "network", "Packet {} deferred until protocol connection event completion", packet_id);
|
trace!(target: "network", "Packet {} deferred until protocol connection event completion", packet_id);
|
||||||
pending.push((packet.data, packet_id));
|
pending.push((packet.data, protocol_packet_id));
|
||||||
|
|
||||||
Ok(SessionData::Continue)
|
Ok(SessionData::Continue)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user