[contract-client] refactor (#7978)
* Refactor usage of registry contract * remove unsed file * Rename methods & fix comments * refactor contract_client: * Intoduced separate traits for asyncronous and syncronous contract clients * Removed registrar from ethcore::client * s/ContractClient/AsyncContractClient * make the tests compile and pass * omit changes in ethcore * Use only one trait for ContractClient * Use an associated type in the trait to determine syncronous or asyncronous communication * Export the types from contract-client crate * Document that "A" in the hash correspons to a DNS A Record A.K.A Address Record * contract_client -> registrar * address review feedback
This commit is contained in:
committed by
André Silva
parent
66f3c50842
commit
e0f71b0c17
@@ -24,7 +24,7 @@ use ethcore::client::{Client, BlockChainClient, BlockId, CallContract};
|
||||
use ethsync::LightSync;
|
||||
use futures::{Future, future, IntoFuture};
|
||||
use hash_fetch::fetch::Client as FetchClient;
|
||||
use hash_fetch::urlhint::ContractClient;
|
||||
use registrar::{RegistrarClient, Asynchronous};
|
||||
use light::client::LightChainClient;
|
||||
use light::on_demand::{self, OnDemand};
|
||||
use node_health::{SyncStatus, NodeHealth};
|
||||
@@ -78,13 +78,15 @@ impl FullRegistrar {
|
||||
}
|
||||
}
|
||||
|
||||
impl ContractClient for FullRegistrar {
|
||||
fn registrar(&self) -> Result<Address, String> {
|
||||
impl RegistrarClient for FullRegistrar {
|
||||
type Call = Asynchronous;
|
||||
|
||||
fn registrar_address(&self) -> Result<Address, String> {
|
||||
self.client.registrar_address()
|
||||
.ok_or_else(|| "Registrar not defined.".into())
|
||||
}
|
||||
|
||||
fn call(&self, address: Address, data: Bytes) -> Box<Future<Item = Bytes, Error = String> + Send> {
|
||||
fn call_contract(&self, address: Address, data: Bytes) -> Self::Call {
|
||||
Box::new(self.client.call_contract(BlockId::Latest, address, data).into_future())
|
||||
}
|
||||
}
|
||||
@@ -99,8 +101,10 @@ pub struct LightRegistrar<T> {
|
||||
pub sync: Arc<LightSync>,
|
||||
}
|
||||
|
||||
impl<T: LightChainClient + 'static> ContractClient for LightRegistrar<T> {
|
||||
fn registrar(&self) -> Result<Address, String> {
|
||||
impl<T: LightChainClient + 'static> RegistrarClient for LightRegistrar<T> {
|
||||
type Call = Box<Future<Item = Bytes, Error = String> + Send>;
|
||||
|
||||
fn registrar_address(&self) -> Result<Address, String> {
|
||||
self.client.engine().additional_params().get("registrar")
|
||||
.ok_or_else(|| "Registrar not defined.".into())
|
||||
.and_then(|registrar| {
|
||||
@@ -108,7 +112,7 @@ impl<T: LightChainClient + 'static> ContractClient for LightRegistrar<T> {
|
||||
})
|
||||
}
|
||||
|
||||
fn call(&self, address: Address, data: Bytes) -> Box<Future<Item = Bytes, Error = String> + Send> {
|
||||
fn call_contract(&self, address: Address, data: Bytes) -> Self::Call {
|
||||
let header = self.client.best_block_header();
|
||||
let env_info = self.client.env_info(BlockId::Hash(header.hash()))
|
||||
.ok_or_else(|| format!("Cannot fetch env info for header {}", header.hash()));
|
||||
@@ -154,7 +158,7 @@ impl<T: LightChainClient + 'static> ContractClient for LightRegistrar<T> {
|
||||
pub struct Dependencies {
|
||||
pub node_health: NodeHealth,
|
||||
pub sync_status: Arc<SyncStatus>,
|
||||
pub contract_client: Arc<ContractClient>,
|
||||
pub contract_client: Arc<RegistrarClient<Call=Asynchronous>>,
|
||||
pub fetch: FetchClient,
|
||||
pub signer: Arc<SignerService>,
|
||||
pub ui_address: Option<(String, u16)>,
|
||||
|
||||
@@ -76,6 +76,7 @@ extern crate rpc_cli;
|
||||
extern crate node_filter;
|
||||
extern crate keccak_hash as hash;
|
||||
extern crate journaldb;
|
||||
extern crate registrar;
|
||||
|
||||
#[macro_use]
|
||||
extern crate log as rlog;
|
||||
|
||||
Reference in New Issue
Block a user