From 0db3607273ac5619ed0f06041abb34bd14576bd3 Mon Sep 17 00:00:00 2001 From: arkpar Date: Thu, 9 Feb 2017 11:14:41 +0100 Subject: [PATCH] structs for RPC types --- ethcore/src/account_provider/mod.rs | 4 ++-- hw/src/ledger.rs | 4 ++-- rpc/src/v1/impls/parity.rs | 20 +++++--------------- rpc/src/v1/traits/parity.rs | 5 +++-- rpc/src/v1/types/mod.rs.in | 2 ++ 5 files changed, 14 insertions(+), 21 deletions(-) diff --git a/ethcore/src/account_provider/mod.rs b/ethcore/src/account_provider/mod.rs index e1f636bcbca..975d2cbc953 100755 --- a/ethcore/src/account_provider/mod.rs +++ b/ethcore/src/account_provider/mod.rs @@ -321,7 +321,7 @@ impl AccountProvider { /// Returns each account along with name and meta. pub fn accounts_info(&self) -> Result, Error> { - let r: HashMap = 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(); @@ -330,7 +330,7 @@ impl AccountProvider { /// Returns each hardware account along with name and meta. pub fn hardware_accounts_info(&self) -> Result, Error> { - let r: HashMap = self.hardware_accounts()? + let r = self.hardware_accounts()? .into_iter() .map(|address| (address.clone(), self.account_meta(address).ok().unwrap_or_default())) .collect(); diff --git a/hw/src/ledger.rs b/hw/src/ledger.rs index ba2f1e0748d..9c3c31d8864 100644 --- a/hw/src/ledger.rs +++ b/hw/src/ledger.rs @@ -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.")); } @@ -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]) diff --git a/rpc/src/v1/impls/parity.rs b/rpc/src/v1/impls/parity.rs index 7895ab686bc..3b22673950a 100644 --- a/rpc/src/v1/impls/parity.rs +++ b/rpc/src/v1/impls/parity.rs @@ -45,6 +45,7 @@ use v1::types::{ TransactionStats, LocalTransactionStatus, BlockNumber, ConsensusCapability, VersionInfo, OperationsInfo, DappId, ChainStatus, + AccountInfo, HwAccountInfo }; /// Parity implementation. @@ -111,7 +112,7 @@ impl Parity for ParityClient where { type Metadata = Metadata; - fn accounts_info(&self, dapp: Trailing) -> Result>, Error> { + fn accounts_info(&self, dapp: Trailing) -> Result, Error> { let dapp = dapp.0; let store = take_weak!(self.accounts); @@ -128,28 +129,17 @@ impl Parity for ParityClient 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>, Error> { + fn hardware_accounts_info(&self) -> Result, 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() ) } diff --git a/rpc/src/v1/traits/parity.rs b/rpc/src/v1/traits/parity.rs index 3128b56e855..d5ecbd5e616 100644 --- a/rpc/src/v1/traits/parity.rs +++ b/rpc/src/v1/traits/parity.rs @@ -28,6 +28,7 @@ use v1::types::{ TransactionStats, LocalTransactionStatus, BlockNumber, ConsensusCapability, VersionInfo, OperationsInfo, DappId, ChainStatus, + AccountInfo, HwAccountInfo, }; build_rpc_trait! { @@ -37,11 +38,11 @@ build_rpc_trait! { /// Returns accounts information. #[rpc(name = "parity_accountsInfo")] - fn accounts_info(&self, Trailing) -> Result>, Error>; + fn accounts_info(&self, Trailing) -> Result, Error>; /// Returns hardware accounts information. #[rpc(name = "parity_hardwareAccountsInfo")] - fn hardware_accounts_info(&self) -> Result>, Error>; + fn hardware_accounts_info(&self) -> Result, Error>; /// Returns default account for dapp. #[rpc(meta, name = "parity_defaultAccount")] diff --git a/rpc/src/v1/types/mod.rs.in b/rpc/src/v1/types/mod.rs.in index a823a010402..268b57e4c8d 100644 --- a/rpc/src/v1/types/mod.rs.in +++ b/rpc/src/v1/types/mod.rs.in @@ -14,6 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . +mod account_info; mod bytes; mod block; mod block_number; @@ -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};