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

Commit

Permalink
structs for RPC types
Browse files Browse the repository at this point in the history
  • Loading branch information
arkpar committed Feb 9, 2017
1 parent 4c444d4 commit cfc7b61
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 21 deletions.
4 changes: 2 additions & 2 deletions ethcore/src/account_provider/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ impl AccountProvider {

/// Returns each account along with name and meta.
pub fn accounts_info(&self) -> Result<HashMap<Address, AccountMeta>, Error> {
let r: HashMap<Address, AccountMeta> = self.sstore.accounts()?
let r = self.sstore.accounts()?
.into_iter()
.map(|a| (a.address.clone(), self.account_meta(a.address).ok().unwrap_or_default()))
.collect();
Expand All @@ -330,7 +330,7 @@ impl AccountProvider {

/// Returns each hardware account along with name and meta.
pub fn hardware_accounts_info(&self) -> Result<HashMap<Address, AccountMeta>, Error> {
let r: HashMap<Address, AccountMeta> = self.hardware_accounts()?
let r = self.hardware_accounts()?
.into_iter()
.map(|address| (address.clone(), self.account_meta(address).ok().unwrap_or_default()))
.collect();
Expand Down
4 changes: 2 additions & 2 deletions hw/src/ledger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ impl Manager {
}

let (major, minor, patch) = (ver[1], ver[2], ver[3]);
if major <= 1 && minor == 0 && patch < 3 {
if major < 1 || (major == 1 && minor == 0 && patch < 3) {
return Err(Error::Protocol("App version 1.0.3 is required."));
}

Expand All @@ -173,7 +173,7 @@ impl Manager {
KeyPath::EthereumClassic => etc_path,
};
let key_and_address = Self::send_apdu(handle, commands::GET_ETH_PUBLIC_ADDRESS, 0, 0, derivation_path)?;
if key_and_address.len() != 107 { // 1 + 65 PK + 1 + 20 Addr
if key_and_address.len() != 107 { // 1 + 65 PK + 1 + 40 Addr (ascii-hex)
return Err(Error::Protocol("Key packet size mismatch"));
}
let address_string = ::std::str::from_utf8(&key_and_address[67..107])
Expand Down
20 changes: 5 additions & 15 deletions rpc/src/v1/impls/parity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ use v1::types::{
TransactionStats, LocalTransactionStatus,
BlockNumber, ConsensusCapability, VersionInfo,
OperationsInfo, DappId, ChainStatus,
AccountInfo, HwAccountInfo
};

/// Parity implementation.
Expand Down Expand Up @@ -111,7 +112,7 @@ impl<C, M, S: ?Sized, U> Parity for ParityClient<C, M, S, U> where
{
type Metadata = Metadata;

fn accounts_info(&self, dapp: Trailing<DappId>) -> Result<BTreeMap<String, BTreeMap<String, String>>, Error> {
fn accounts_info(&self, dapp: Trailing<DappId>) -> Result<BTreeMap<H160, AccountInfo>, Error> {
let dapp = dapp.0;

let store = take_weak!(self.accounts);
Expand All @@ -128,28 +129,17 @@ impl<C, M, S: ?Sized, U> Parity for ParityClient<C, M, S, U> where
.into_iter()
.chain(other.into_iter())
.filter(|&(ref a, _)| dapp_accounts.contains(a))
.map(|(a, v)| {
let m = map![
"name".to_owned() => v.name
];
(format!("0x{}", a.hex()), m)
})
.map(|(a, v)| (H160::from(a), AccountInfo { name: v.name }))
.collect()
)
}

fn hardware_accounts_info(&self) -> Result<BTreeMap<String, BTreeMap<String, String>>, Error> {
fn hardware_accounts_info(&self) -> Result<BTreeMap<H160, HwAccountInfo>, Error> {
let store = take_weak!(self.accounts);
let info = store.hardware_accounts_info().map_err(|e| errors::account("Could not fetch account info.", e))?;
Ok(info
.into_iter()
.map(|(a, v)| {
let m = map![
"name".to_owned() => v.name,
"manufacturer".to_owned() => v.meta
];
(format!("0x{}", a.hex()), m)
})
.map(|(a, v)| (H160::from(a), HwAccountInfo { name: v.name, manufacturer: v.meta }))
.collect()
)
}
Expand Down
5 changes: 3 additions & 2 deletions rpc/src/v1/traits/parity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use v1::types::{
TransactionStats, LocalTransactionStatus,
BlockNumber, ConsensusCapability, VersionInfo,
OperationsInfo, DappId, ChainStatus,
AccountInfo, HwAccountInfo,
};

build_rpc_trait! {
Expand All @@ -37,11 +38,11 @@ build_rpc_trait! {

/// Returns accounts information.
#[rpc(name = "parity_accountsInfo")]
fn accounts_info(&self, Trailing<DappId>) -> Result<BTreeMap<String, BTreeMap<String, String>>, Error>;
fn accounts_info(&self, Trailing<DappId>) -> Result<BTreeMap<H160, AccountInfo>, Error>;

/// Returns hardware accounts information.
#[rpc(name = "parity_hardwareAccountsInfo")]
fn hardware_accounts_info(&self) -> Result<BTreeMap<String, BTreeMap<String, String>>, Error>;
fn hardware_accounts_info(&self) -> Result<BTreeMap<H160, HwAccountInfo>, Error>;

/// Returns default account for dapp.
#[rpc(meta, name = "parity_defaultAccount")]
Expand Down
33 changes: 33 additions & 0 deletions rpc/src/v1/types/account_info.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright 2015-2017 Parity Technologies (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/>.

use serde::{Serialize};

/// Account information.
#[derive(Debug, Default, Clone, PartialEq, Serialize)]
pub struct AccountInfo {
/// Account name
pub name: String,
}

/// Hardware wallet information.
#[derive(Debug, Default, Clone, PartialEq, Serialize)]
pub struct HwAccountInfo {
/// Device name.
pub name: String,
/// Device manufacturer.
pub manufacturer: String,
}
2 changes: 2 additions & 0 deletions rpc/src/v1/types/mod.rs.in
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.

mod account_info;
mod bytes;
mod block;
mod block_number;
Expand Down Expand Up @@ -65,3 +66,4 @@ pub use self::uint::{U128, U256};
pub use self::work::Work;
pub use self::histogram::Histogram;
pub use self::consensus_status::*;
pub use self::account_info::{AccountInfo, HwAccountInfo};

0 comments on commit cfc7b61

Please sign in to comment.