Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Remove Result wrapper from AccountProvider in RPC impls #8763

Merged
merged 3 commits into from
Jun 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions rpc/src/v1/impls/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,6 @@ impl<C, SN: ?Sized, S: ?Sized, M, EM, T: StateInfo + 'static> EthClient<C, SN, S
}
}

/// Attempt to get the `Arc<AccountProvider>`, errors if provider was not
/// set.
fn account_provider(&self) -> Result<Arc<AccountProvider>> {
Ok(self.accounts.clone())
}

fn rich_block(&self, id: BlockNumberOrId, include_txs: bool) -> Result<Option<RichBlock>> {
let client = &self.client;

Expand Down Expand Up @@ -404,10 +398,9 @@ impl<C, SN: ?Sized, S: ?Sized, M, EM, T: StateInfo + 'static> EthClient<C, SN, S
}

fn dapp_accounts(&self, dapp: DappId) -> Result<Vec<H160>> {
let store = self.account_provider()?;
store
self.accounts
.note_dapp_used(dapp.clone())
.and_then(|_| store.dapp_addresses(dapp))
.and_then(|_| self.accounts.dapp_addresses(dapp))
.map_err(|e| errors::account("Could not fetch accounts.", e))
}

Expand Down
23 changes: 7 additions & 16 deletions rpc/src/v1/impls/parity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,6 @@ impl<C, M, U> ParityClient<C, M, U> where
eip86_transition,
}
}

/// Attempt to get the `Arc<AccountProvider>`, errors if provider was not
/// set.
fn account_provider(&self) -> Result<Arc<AccountProvider>> {
Ok(self.accounts.clone())
}
}

impl<C, M, U, S> Parity for ParityClient<C, M, U> where
Expand All @@ -124,15 +118,14 @@ impl<C, M, U, S> Parity for ParityClient<C, M, U> where
fn accounts_info(&self, dapp: Trailing<DappId>) -> Result<BTreeMap<H160, AccountInfo>> {
let dapp = dapp.unwrap_or_default();

let store = self.account_provider()?;
let dapp_accounts = store
let dapp_accounts = self.accounts
.note_dapp_used(dapp.clone().into())
.and_then(|_| store.dapp_addresses(dapp.into()))
.and_then(|_| self.accounts.dapp_addresses(dapp.into()))
.map_err(|e| errors::account("Could not fetch accounts.", e))?
.into_iter().collect::<HashSet<_>>();

let info = store.accounts_info().map_err(|e| errors::account("Could not fetch account info.", e))?;
let other = store.addresses_info();
let info = self.accounts.accounts_info().map_err(|e| errors::account("Could not fetch account info.", e))?;
let other = self.accounts.addresses_info();

Ok(info
.into_iter()
Expand All @@ -144,8 +137,7 @@ impl<C, M, U, S> Parity for ParityClient<C, M, U> where
}

fn hardware_accounts_info(&self) -> Result<BTreeMap<H160, HwAccountInfo>> {
let store = self.account_provider()?;
let info = store.hardware_accounts_info().map_err(|e| errors::account("Could not fetch account info.", e))?;
let info = self.accounts.hardware_accounts_info().map_err(|e| errors::account("Could not fetch account info.", e))?;
Ok(info
.into_iter()
.map(|(a, v)| (H160::from(a), HwAccountInfo { name: v.name, manufacturer: v.meta }))
Expand All @@ -154,14 +146,13 @@ impl<C, M, U, S> Parity for ParityClient<C, M, U> where
}

fn locked_hardware_accounts_info(&self) -> Result<Vec<String>> {
let store = self.account_provider()?;
Ok(store.locked_hardware_accounts().map_err(|e| errors::account("Error communicating with hardware wallet.", e))?)
self.accounts.locked_hardware_accounts().map_err(|e| errors::account("Error communicating with hardware wallet.", e))
}

fn default_account(&self, meta: Self::Metadata) -> Result<H160> {
let dapp_id = meta.dapp_id();

Ok(self.account_provider()?
Ok(self.accounts
.dapp_default_address(dapp_id.into())
.map(Into::into)
.ok()
Expand Down
Loading