light client RPC dependencies
This commit is contained in:
@@ -28,12 +28,13 @@ use ethcore::miner::{Miner, ExternalMiner};
|
||||
use ethcore::snapshot::SnapshotService;
|
||||
use ethcore_rpc::{Metadata, NetworkSettings};
|
||||
use ethcore_rpc::informant::{ActivityNotifier, Middleware, RpcStats, ClientNotifier};
|
||||
use ethcore_rpc::dispatch::FullDispatcher;
|
||||
use ethsync::{ManageNetwork, SyncProvider};
|
||||
use ethcore_rpc::dispatch::{FullDispatcher, LightDispatcher};
|
||||
use ethsync::{ManageNetwork, SyncProvider, LightSync};
|
||||
use hash_fetch::fetch::Client as FetchClient;
|
||||
use jsonrpc_core::{MetaIoHandler};
|
||||
use light::{TransactionQueue as LightTransactionQueue, Cache as LightDataCache};
|
||||
use updater::Updater;
|
||||
use util::RotatingLogger;
|
||||
use util::{Mutex, RwLock, RotatingLogger};
|
||||
|
||||
#[derive(Debug, PartialEq, Clone, Eq, Hash)]
|
||||
pub enum Api {
|
||||
@@ -271,6 +272,114 @@ impl Dependencies for FullDependencies {
|
||||
}
|
||||
}
|
||||
|
||||
/// Light client notifier. Doesn't do anything yet, but might in the future.
|
||||
pub struct LightClientNotifier;
|
||||
|
||||
impl ActivityNotifier for LightClientNotifier {
|
||||
fn active(&self) {}
|
||||
}
|
||||
|
||||
/// RPC dependencies for a light client.
|
||||
pub struct LightDependencies {
|
||||
pub signer_service: Arc<SignerService>,
|
||||
pub client: Arc<::light::client::Client>,
|
||||
pub sync: Arc<LightSync>,
|
||||
pub net: Arc<ManageNetwork>,
|
||||
pub secret_store: Arc<AccountProvider>,
|
||||
pub logger: Arc<RotatingLogger>,
|
||||
pub settings: Arc<NetworkSettings>,
|
||||
pub on_demand: Arc<::light::on_demand::OnDemand>,
|
||||
pub cache: Arc<Mutex<LightDataCache>>,
|
||||
pub transaction_queue: Arc<RwLock<LightTransactionQueue>>,
|
||||
pub updater: Arc<Updater>,
|
||||
pub dapps_interface: Option<String>,
|
||||
pub dapps_port: Option<u16>,
|
||||
pub fetch: FetchClient,
|
||||
pub geth_compatibility: bool,
|
||||
}
|
||||
|
||||
impl Dependencies for LightDependencies {
|
||||
type Notifier = LightClientNotifier;
|
||||
|
||||
fn activity_notifier(&self) -> Self::Notifier { LightClientNotifier }
|
||||
fn extend_with_set(&self, handler: &mut MetaIoHandler<Metadata, Middleware<Self::Notifier>>, apis: &[Api]) {
|
||||
use ethcore_rpc::v1::*;
|
||||
|
||||
let dispatcher = LightDispatcher::new(
|
||||
self.sync.clone(),
|
||||
self.client.clone(),
|
||||
self.on_demand.clone(),
|
||||
self.cache.clone(),
|
||||
self.transaction_queue.clone(),
|
||||
);
|
||||
|
||||
for api in apis {
|
||||
match *api {
|
||||
Api::Web3 => {
|
||||
handler.extend_with(Web3Client::new().to_delegate());
|
||||
},
|
||||
Api::Net => {
|
||||
handler.extend_with(light::NetClient::new(self.sync.clone()).to_delegate());
|
||||
},
|
||||
Api::Eth => {
|
||||
let client = light::EthClient::new(
|
||||
self.sync.clone(),
|
||||
self.client.clone(),
|
||||
self.on_demand.clone(),
|
||||
self.transaction_queue.clone(),
|
||||
self.secret_store.clone(),
|
||||
self.cache.clone(),
|
||||
);
|
||||
handler.extend_with(client.to_delegate());
|
||||
|
||||
// TODO: filters and signing methods.
|
||||
},
|
||||
Api::Personal => {
|
||||
handler.extend_with(PersonalClient::new(&self.secret_store, dispatcher.clone(), self.geth_compatibility).to_delegate());
|
||||
},
|
||||
Api::Signer => {
|
||||
handler.extend_with(SignerClient::new(&self.secret_store, dispatcher.clone(), &self.signer_service).to_delegate());
|
||||
},
|
||||
Api::Parity => {
|
||||
let signer = match self.signer_service.is_enabled() {
|
||||
true => Some(self.signer_service.clone()),
|
||||
false => None,
|
||||
};
|
||||
handler.extend_with(light::ParityClient::new(
|
||||
Arc::new(dispatcher.clone()),
|
||||
self.secret_store.clone(),
|
||||
self.logger.clone(),
|
||||
self.settings.clone(),
|
||||
signer,
|
||||
self.dapps_interface.clone(),
|
||||
self.dapps_port,
|
||||
).to_delegate());
|
||||
|
||||
// TODO
|
||||
//add_signing_methods!(EthSigning, handler, self);
|
||||
//add_signing_methods!(ParitySigning, handler, self);
|
||||
},
|
||||
Api::ParityAccounts => {
|
||||
handler.extend_with(ParityAccountsClient::new(&self.secret_store).to_delegate());
|
||||
},
|
||||
Api::ParitySet => {
|
||||
handler.extend_with(light::ParitySetClient::new(
|
||||
self.sync.clone(),
|
||||
self.fetch.clone(),
|
||||
).to_delegate())
|
||||
},
|
||||
Api::Traces => {
|
||||
handler.extend_with(light::TracesClient.to_delegate())
|
||||
},
|
||||
Api::Rpc => {
|
||||
let modules = to_modules(&apis);
|
||||
handler.extend_with(RpcClient::new(modules).to_delegate());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ApiSet {
|
||||
pub fn list_apis(&self) -> HashSet<Api> {
|
||||
let mut safe_list = vec![Api::Web3, Api::Net, Api::Eth, Api::Parity, Api::Traces, Api::Rpc]
|
||||
|
||||
Reference in New Issue
Block a user