diff --git a/ethcore/src/light/client.rs b/ethcore/src/light/client.rs new file mode 100644 index 000000000..de79ad922 --- /dev/null +++ b/ethcore/src/light/client.rs @@ -0,0 +1,95 @@ +// 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 . + +//! Light client implementation. Used for raw data queries as well as the header +//! sync. + +use std::sync::Arc; + +use engines::Engine; +use ids::BlockID; +use miner::TransactionQueue; +use service::ClientIoMessage; +use block_import_error::BlockImportError; +use block_status::BlockStatus; +use verification::queue::{Config as QueueConfig, HeaderQueue, QueueInfo, Status}; +use transaction::SignedTransaction; + +use super::provider::{CHTProofRequest, Provider, ProofRequest}; + +use io::IoChannel; +use util::hash::H256; +use util::Bytes; + +/// A light client. +pub struct Client { + engine: Arc, + header_queue: HeaderQueue, + message_channel: IoChannel, + transaction_queue: TransactionQueue, +} + +impl Client { + /// Import a header as rlp-encoded bytes. + fn import_header(&self, bytes: Bytes) -> Result { + 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) + fn is_known(&self, id: BlockID) -> bool { + false + } + + /// Fetch a vector of all pending transactions. + fn pending_transactions(&self) -> Vec { + self.transaction_queue.top_transactions() + } + + /// Inquire about the status of a given block. + fn status(&self, id: BlockID) -> BlockStatus { + BlockStatus::Unknown + } +} + +// stub implementation, can be partially implemented using LRU-caches +// but will almost definitely never be able to provide complete responses. +impl Provider for Client { + fn block_headers(&self, _block: H256, _skip: usize, _max: usize, _reverse: bool) -> Vec { + vec![] + } + + fn block_bodies(&self, _blocks: Vec) -> Vec { + vec![] + } + + fn receipts(&self, _blocks: Vec) -> Vec { + vec![] + } + + fn proofs(&self, _requests: Vec<(H256, ProofRequest)>) -> Vec { + vec![] + } + + fn code(&self, _accounts: Vec<(H256, H256)>) -> Vec { + vec![] + } + + fn header_proofs(&self, _requests: Vec) -> Vec { + vec![] + } +} \ No newline at end of file diff --git a/ethcore/src/light/mod.rs b/ethcore/src/light/mod.rs new file mode 100644 index 000000000..100548b46 --- /dev/null +++ b/ethcore/src/light/mod.rs @@ -0,0 +1,18 @@ +//! Light client logic and implementation. +//! +//! A "light" client stores very little chain-related data locally +//! unlike a full node, which stores all blocks, headers, receipts, and more. +//! +//! This enables the client to have a much lower resource footprint in +//! exchange for the cost of having to ask the network for state data +//! while responding to queries. This makes a light client unsuitable for +//! low-latency applications, but perfectly suitable for simple everyday +//! use-cases like sending transactions from a personal account. +//! +//! It starts by performing a header-only sync, verifying every header in +//! the chain. + +mod provider; +mod client; + +pub use self::provider::{CHTProofRequest, ProofRequest, Provider}; \ No newline at end of file diff --git a/util/fetch/src/lib.rs b/util/fetch/src/lib.rs index 8ec9e0ddd..7ab38604b 100644 --- a/util/fetch/src/lib.rs +++ b/util/fetch/src/lib.rs @@ -26,4 +26,4 @@ extern crate rand; pub mod client; pub mod fetch_file; -pub use self::client::{Client, Fetch, FetchError, FetchResult}; +pub use self::client::{Client, Fetch, FetchError, FetchResult}; \ No newline at end of file