2016-09-19 11:29:50 +02:00
|
|
|
// Copyright 2015, 2016 Ethcore (UK) Ltd.
|
|
|
|
// This file is part of Parity.
|
|
|
|
|
|
|
|
// Parity is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
|
|
|
// Parity is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
//! Light client implementation. Used for raw data queries as well as the header
|
|
|
|
//! sync.
|
|
|
|
|
|
|
|
use std::sync::Arc;
|
|
|
|
|
2016-12-05 17:09:05 +01:00
|
|
|
use ethcore::engines::Engine;
|
|
|
|
use ethcore::ids::BlockID;
|
|
|
|
use ethcore::service::ClientIoMessage;
|
|
|
|
use ethcore::block_import_error::BlockImportError;
|
|
|
|
use ethcore::block_status::BlockStatus;
|
|
|
|
use ethcore::verification::queue::{HeaderQueue, QueueInfo};
|
|
|
|
use ethcore::transaction::SignedTransaction;
|
|
|
|
use ethcore::blockchain_info::BlockChainInfo;
|
2016-09-19 11:29:50 +02:00
|
|
|
|
|
|
|
use io::IoChannel;
|
|
|
|
use util::hash::H256;
|
2016-11-04 17:19:01 +01:00
|
|
|
use util::{Bytes, Mutex};
|
2016-09-19 11:29:50 +02:00
|
|
|
|
2016-12-05 17:09:05 +01:00
|
|
|
use provider::Provider;
|
|
|
|
use request;
|
2016-11-04 19:40:11 +01:00
|
|
|
|
2016-10-27 15:09:17 +02:00
|
|
|
/// Light client implementation.
|
2016-09-19 11:29:50 +02:00
|
|
|
pub struct Client {
|
|
|
|
engine: Arc<Engine>,
|
|
|
|
header_queue: HeaderQueue,
|
2016-11-04 17:19:01 +01:00
|
|
|
message_channel: Mutex<IoChannel<ClientIoMessage>>,
|
2016-09-19 11:29:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Client {
|
|
|
|
/// Import a header as rlp-encoded bytes.
|
2016-10-05 15:35:31 +02:00
|
|
|
pub fn import_header(&self, bytes: Bytes) -> Result<H256, BlockImportError> {
|
2016-09-19 11:29:50 +02:00
|
|
|
let header = ::rlp::decode(&bytes);
|
|
|
|
|
|
|
|
self.header_queue.import(header).map_err(Into::into)
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Whether the block is already known (but not necessarily part of the canonical chain)
|
2016-11-09 15:36:26 +01:00
|
|
|
pub fn is_known(&self, _id: BlockID) -> bool {
|
2016-09-19 11:29:50 +02:00
|
|
|
false
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Fetch a vector of all pending transactions.
|
2016-10-05 15:35:31 +02:00
|
|
|
pub fn pending_transactions(&self) -> Vec<SignedTransaction> {
|
|
|
|
vec![]
|
2016-09-19 11:29:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Inquire about the status of a given block.
|
2016-11-09 18:05:00 +01:00
|
|
|
pub fn status(&self, _id: BlockID) -> BlockStatus {
|
2016-09-19 11:29:50 +02:00
|
|
|
BlockStatus::Unknown
|
|
|
|
}
|
|
|
|
|
2016-10-05 15:35:31 +02:00
|
|
|
/// Get the header queue info.
|
|
|
|
pub fn queue_info(&self) -> QueueInfo {
|
|
|
|
self.header_queue.queue_info()
|
2016-09-19 11:29:50 +02:00
|
|
|
}
|
2016-11-04 18:40:31 +01:00
|
|
|
}
|
2016-10-27 15:45:59 +02:00
|
|
|
|
2016-11-04 18:40:31 +01:00
|
|
|
// dummy implementation -- may draw from canonical cache further on.
|
|
|
|
impl Provider for Client {
|
|
|
|
fn chain_info(&self) -> BlockChainInfo {
|
2016-11-04 17:19:01 +01:00
|
|
|
unimplemented!()
|
2016-10-27 15:45:59 +02:00
|
|
|
}
|
2016-10-27 15:09:17 +02:00
|
|
|
|
2016-11-09 15:36:26 +01:00
|
|
|
fn reorg_depth(&self, _a: &H256, _b: &H256) -> Option<u64> {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
|
|
|
|
fn earliest_state(&self) -> Option<u64> {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
|
2016-11-04 19:40:11 +01:00
|
|
|
fn block_headers(&self, _req: request::Headers) -> Vec<Bytes> {
|
|
|
|
Vec::new()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn block_bodies(&self, _req: request::Bodies) -> Vec<Bytes> {
|
2016-10-27 15:09:17 +02:00
|
|
|
Vec::new()
|
|
|
|
}
|
|
|
|
|
2016-11-04 19:40:11 +01:00
|
|
|
fn receipts(&self, _req: request::Receipts) -> Vec<Bytes> {
|
2016-10-27 15:09:17 +02:00
|
|
|
Vec::new()
|
|
|
|
}
|
|
|
|
|
2016-11-04 19:40:11 +01:00
|
|
|
fn proofs(&self, _req: request::StateProofs) -> Vec<Bytes> {
|
2016-10-27 15:09:17 +02:00
|
|
|
Vec::new()
|
|
|
|
}
|
|
|
|
|
2016-11-15 14:53:30 +01:00
|
|
|
fn contract_code(&self, _req: request::ContractCodes) -> Vec<Bytes> {
|
2016-10-27 15:09:17 +02:00
|
|
|
Vec::new()
|
|
|
|
}
|
|
|
|
|
2016-11-04 19:40:11 +01:00
|
|
|
fn header_proofs(&self, _req: request::HeaderProofs) -> Vec<Bytes> {
|
2016-10-27 15:09:17 +02:00
|
|
|
Vec::new()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn pending_transactions(&self) -> Vec<SignedTransaction> {
|
|
|
|
Vec::new()
|
|
|
|
}
|
2016-09-19 11:29:50 +02:00
|
|
|
}
|