Prioritize accounts over address book
This commit is contained in:
parent
e73569c84d
commit
2c254e3b32
@ -59,7 +59,7 @@ extern crate stats;
|
||||
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
#[macro_use]
|
||||
#[cfg_attr(test, macro_use)]
|
||||
extern crate ethcore_util as util;
|
||||
#[macro_use]
|
||||
extern crate jsonrpc_macros;
|
||||
|
@ -16,7 +16,7 @@
|
||||
|
||||
//! Account management (personal) rpc implementation
|
||||
use std::sync::Arc;
|
||||
use std::collections::BTreeMap;
|
||||
use std::collections::btree_map::{BTreeMap, Entry};
|
||||
use util::Address;
|
||||
|
||||
use ethkey::{Brain, Generator, Secret};
|
||||
@ -27,7 +27,7 @@ use jsonrpc_core::Error;
|
||||
use v1::helpers::errors;
|
||||
use v1::helpers::accounts::unwrap_provider;
|
||||
use v1::traits::ParityAccounts;
|
||||
use v1::types::{H160 as RpcH160, H256 as RpcH256, H520 as RpcH520, DappId, Derive, DeriveHierarchical, DeriveHash};
|
||||
use v1::types::{H160 as RpcH160, H256 as RpcH256, H520 as RpcH520, DappId, Derive, DeriveHierarchical, DeriveHash, ExtAccountInfo};
|
||||
|
||||
/// Account management (personal) rpc implementation.
|
||||
pub struct ParityAccountsClient {
|
||||
@ -50,26 +50,36 @@ impl ParityAccountsClient {
|
||||
}
|
||||
|
||||
impl ParityAccounts for ParityAccountsClient {
|
||||
fn all_accounts_info(&self) -> Result<BTreeMap<RpcH160, BTreeMap<String, String>>, Error> {
|
||||
fn all_accounts_info(&self) -> Result<BTreeMap<RpcH160, ExtAccountInfo>, Error> {
|
||||
let store = self.account_provider()?;
|
||||
let info = store.accounts_info().map_err(|e| errors::account("Could not fetch account info.", e))?;
|
||||
let other = store.addresses_info();
|
||||
|
||||
Ok(info
|
||||
.into_iter()
|
||||
.chain(other.into_iter())
|
||||
.map(|(address, v)| {
|
||||
let mut m = map![
|
||||
"name".to_owned() => v.name,
|
||||
"meta".to_owned() => v.meta
|
||||
];
|
||||
if let &Some(ref uuid) = &v.uuid {
|
||||
m.insert("uuid".to_owned(), format!("{}", uuid));
|
||||
}
|
||||
(address.into(), m)
|
||||
})
|
||||
.collect()
|
||||
)
|
||||
let account_iter = info
|
||||
.into_iter()
|
||||
.chain(other.into_iter())
|
||||
.map(|(address, v)| (address.into(), ExtAccountInfo {
|
||||
name: v.name,
|
||||
meta: v.meta,
|
||||
uuid: v.uuid.map(|uuid| uuid.to_string())
|
||||
}));
|
||||
|
||||
let mut accounts: BTreeMap<RpcH160, ExtAccountInfo> = BTreeMap::new();
|
||||
|
||||
for (address, account) in account_iter {
|
||||
match accounts.entry(address) {
|
||||
/// Insert only if occupied entry isn't already an account with UUID
|
||||
Entry::Occupied(ref mut occupied) if occupied.get().uuid.is_none() => {
|
||||
occupied.insert(account);
|
||||
},
|
||||
Entry::Vacant(vacant) => {
|
||||
vacant.insert(account);
|
||||
},
|
||||
_ => {}
|
||||
};
|
||||
}
|
||||
|
||||
Ok(accounts)
|
||||
}
|
||||
|
||||
fn new_account_from_phrase(&self, phrase: String, pass: String) -> Result<RpcH160, Error> {
|
||||
|
@ -19,14 +19,14 @@ use std::collections::BTreeMap;
|
||||
|
||||
use jsonrpc_core::Error;
|
||||
use ethstore::KeyFile;
|
||||
use v1::types::{H160, H256, H520, DappId, DeriveHash, DeriveHierarchical};
|
||||
use v1::types::{H160, H256, H520, DappId, DeriveHash, DeriveHierarchical, ExtAccountInfo};
|
||||
|
||||
build_rpc_trait! {
|
||||
/// Personal Parity rpc interface.
|
||||
pub trait ParityAccounts {
|
||||
/// Returns accounts information.
|
||||
#[rpc(name = "parity_allAccountsInfo")]
|
||||
fn all_accounts_info(&self) -> Result<BTreeMap<H160, BTreeMap<String, String>>, Error>;
|
||||
fn all_accounts_info(&self) -> Result<BTreeMap<H160, ExtAccountInfo>, Error>;
|
||||
|
||||
/// Creates new account from the given phrase using standard brainwallet mechanism.
|
||||
/// Second parameter is password for the new account.
|
||||
|
@ -21,6 +21,18 @@ pub struct AccountInfo {
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
/// Extended account information (used by `parity_allAccountInfo`).
|
||||
#[derive(Debug, Default, Clone, PartialEq, Serialize)]
|
||||
pub struct ExtAccountInfo {
|
||||
/// Account name
|
||||
pub name: String,
|
||||
/// Account meta JSON
|
||||
pub meta: String,
|
||||
/// Account UUID (`None` for address book entries)
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub uuid: Option<String>,
|
||||
}
|
||||
|
||||
/// Hardware wallet information.
|
||||
#[derive(Debug, Default, Clone, PartialEq, Serialize)]
|
||||
pub struct HwAccountInfo {
|
||||
@ -29,3 +41,4 @@ pub struct HwAccountInfo {
|
||||
/// Device manufacturer.
|
||||
pub manufacturer: String,
|
||||
}
|
||||
|
||||
|
@ -46,7 +46,7 @@ mod work;
|
||||
|
||||
pub mod pubsub;
|
||||
|
||||
pub use self::account_info::{AccountInfo, HwAccountInfo};
|
||||
pub use self::account_info::{AccountInfo, ExtAccountInfo, HwAccountInfo};
|
||||
pub use self::bytes::Bytes;
|
||||
pub use self::block::{RichBlock, Block, BlockTransactions, Header, RichHeader, Rich};
|
||||
pub use self::block_number::BlockNumber;
|
||||
|
Loading…
Reference in New Issue
Block a user