2017-01-25 18:51:41 +01:00
|
|
|
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
|
2016-10-27 19:26:34 +02:00
|
|
|
// 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/>.
|
|
|
|
|
|
|
|
//! Account management (personal) rpc implementation
|
2017-05-28 14:40:36 +02:00
|
|
|
use std::sync::Arc;
|
2017-06-23 16:29:45 +02:00
|
|
|
use std::collections::btree_map::{BTreeMap, Entry};
|
2018-01-10 13:35:18 +01:00
|
|
|
use ethereum_types::Address;
|
2016-11-06 12:51:53 +01:00
|
|
|
|
2017-01-11 12:16:47 +01:00
|
|
|
use ethkey::{Brain, Generator, Secret};
|
2017-03-23 13:23:03 +01:00
|
|
|
use ethstore::KeyFile;
|
2016-10-27 19:26:34 +02:00
|
|
|
use ethcore::account_provider::AccountProvider;
|
2016-11-06 12:51:53 +01:00
|
|
|
|
2017-11-14 11:38:17 +01:00
|
|
|
use jsonrpc_core::Result;
|
2017-01-30 21:08:36 +01:00
|
|
|
use v1::helpers::errors;
|
2017-03-29 17:07:58 +02:00
|
|
|
use v1::helpers::accounts::unwrap_provider;
|
2016-11-06 12:51:53 +01:00
|
|
|
use v1::traits::ParityAccounts;
|
2017-06-23 16:29:45 +02:00
|
|
|
use v1::types::{H160 as RpcH160, H256 as RpcH256, H520 as RpcH520, DappId, Derive, DeriveHierarchical, DeriveHash, ExtAccountInfo};
|
2016-10-27 19:26:34 +02:00
|
|
|
|
|
|
|
/// Account management (personal) rpc implementation.
|
2017-02-04 22:18:19 +01:00
|
|
|
pub struct ParityAccountsClient {
|
2017-05-28 14:40:36 +02:00
|
|
|
accounts: Option<Arc<AccountProvider>>,
|
2016-10-27 19:26:34 +02:00
|
|
|
}
|
|
|
|
|
2017-02-04 22:18:19 +01:00
|
|
|
impl ParityAccountsClient {
|
2016-10-27 19:26:34 +02:00
|
|
|
/// Creates new PersonalClient
|
2017-03-29 17:07:58 +02:00
|
|
|
pub fn new(store: &Option<Arc<AccountProvider>>) -> Self {
|
2016-11-06 12:51:53 +01:00
|
|
|
ParityAccountsClient {
|
2017-05-28 14:40:36 +02:00
|
|
|
accounts: store.clone(),
|
2016-10-27 19:26:34 +02:00
|
|
|
}
|
|
|
|
}
|
2017-03-29 17:07:58 +02:00
|
|
|
|
|
|
|
/// Attempt to get the `Arc<AccountProvider>`, errors if provider was not
|
2017-05-28 14:40:36 +02:00
|
|
|
/// set.
|
2017-11-14 11:38:17 +01:00
|
|
|
fn account_provider(&self) -> Result<Arc<AccountProvider>> {
|
2017-03-29 17:07:58 +02:00
|
|
|
unwrap_provider(&self.accounts)
|
|
|
|
}
|
2016-10-27 19:26:34 +02:00
|
|
|
}
|
|
|
|
|
2017-02-04 22:18:19 +01:00
|
|
|
impl ParityAccounts for ParityAccountsClient {
|
2017-11-14 11:38:17 +01:00
|
|
|
fn all_accounts_info(&self) -> Result<BTreeMap<RpcH160, ExtAccountInfo>> {
|
2017-03-29 17:07:58 +02:00
|
|
|
let store = self.account_provider()?;
|
2016-12-27 12:53:56 +01:00
|
|
|
let info = store.accounts_info().map_err(|e| errors::account("Could not fetch account info.", e))?;
|
2017-02-03 13:56:48 +01:00
|
|
|
let other = store.addresses_info();
|
|
|
|
|
2017-06-23 16:29:45 +02:00
|
|
|
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) {
|
2017-10-05 12:35:01 +02:00
|
|
|
// Insert only if occupied entry isn't already an account with UUID
|
2017-06-23 16:29:45 +02:00
|
|
|
Entry::Occupied(ref mut occupied) if occupied.get().uuid.is_none() => {
|
|
|
|
occupied.insert(account);
|
|
|
|
},
|
|
|
|
Entry::Vacant(vacant) => {
|
|
|
|
vacant.insert(account);
|
|
|
|
},
|
|
|
|
_ => {}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(accounts)
|
2016-10-27 19:26:34 +02:00
|
|
|
}
|
|
|
|
|
2017-11-14 11:38:17 +01:00
|
|
|
fn new_account_from_phrase(&self, phrase: String, pass: String) -> Result<RpcH160> {
|
2017-03-29 17:07:58 +02:00
|
|
|
let store = self.account_provider()?;
|
2016-10-31 17:11:56 +01:00
|
|
|
|
2017-01-11 12:16:47 +01:00
|
|
|
let brain = Brain::new(phrase).generate().unwrap();
|
|
|
|
store.insert_account(brain.secret().clone(), &pass)
|
2016-10-31 17:11:56 +01:00
|
|
|
.map(Into::into)
|
|
|
|
.map_err(|e| errors::account("Could not create account.", e))
|
2016-10-27 19:26:34 +02:00
|
|
|
}
|
|
|
|
|
2017-11-14 11:38:17 +01:00
|
|
|
fn new_account_from_wallet(&self, json: String, pass: String) -> Result<RpcH160> {
|
2017-03-29 17:07:58 +02:00
|
|
|
let store = self.account_provider()?;
|
2016-10-31 17:11:56 +01:00
|
|
|
|
|
|
|
store.import_presale(json.as_bytes(), &pass)
|
2018-02-14 14:21:58 +01:00
|
|
|
.or_else(|_| store.import_wallet(json.as_bytes(), &pass, true))
|
2016-10-31 17:11:56 +01:00
|
|
|
.map(Into::into)
|
|
|
|
.map_err(|e| errors::account("Could not create account.", e))
|
2016-10-27 19:26:34 +02:00
|
|
|
}
|
|
|
|
|
2017-11-14 11:38:17 +01:00
|
|
|
fn new_account_from_secret(&self, secret: RpcH256, pass: String) -> Result<RpcH160> {
|
2017-03-29 17:07:58 +02:00
|
|
|
let store = self.account_provider()?;
|
2016-10-31 17:11:56 +01:00
|
|
|
|
2017-05-19 17:06:36 +02:00
|
|
|
let secret = Secret::from_unsafe_slice(&secret.0)
|
2017-01-11 12:16:47 +01:00
|
|
|
.map_err(|e| errors::account("Could not create account.", e))?;
|
|
|
|
store.insert_account(secret, &pass)
|
2016-10-31 17:11:56 +01:00
|
|
|
.map(Into::into)
|
|
|
|
.map_err(|e| errors::account("Could not create account.", e))
|
2016-10-28 16:46:25 +02:00
|
|
|
}
|
|
|
|
|
2017-11-14 11:38:17 +01:00
|
|
|
fn test_password(&self, account: RpcH160, password: String) -> Result<bool> {
|
2016-10-31 17:11:56 +01:00
|
|
|
let account: Address = account.into();
|
|
|
|
|
2017-03-29 17:07:58 +02:00
|
|
|
self.account_provider()?
|
2016-11-20 16:17:57 +01:00
|
|
|
.test_password(&account, &password)
|
2016-10-31 17:11:56 +01:00
|
|
|
.map_err(|e| errors::account("Could not fetch account info.", e))
|
2016-10-27 19:26:34 +02:00
|
|
|
}
|
|
|
|
|
2017-11-14 11:38:17 +01:00
|
|
|
fn change_password(&self, account: RpcH160, password: String, new_password: String) -> Result<bool> {
|
2016-10-31 17:11:56 +01:00
|
|
|
let account: Address = account.into();
|
2017-03-29 17:07:58 +02:00
|
|
|
self.account_provider()?
|
2016-10-31 17:11:56 +01:00
|
|
|
.change_password(&account, password, new_password)
|
|
|
|
.map(|_| true)
|
|
|
|
.map_err(|e| errors::account("Could not fetch account info.", e))
|
2016-10-27 19:26:34 +02:00
|
|
|
}
|
|
|
|
|
2017-11-14 11:38:17 +01:00
|
|
|
fn kill_account(&self, account: RpcH160, password: String) -> Result<bool> {
|
2016-11-20 16:17:57 +01:00
|
|
|
let account: Address = account.into();
|
2017-03-29 17:07:58 +02:00
|
|
|
self.account_provider()?
|
2016-11-20 16:17:57 +01:00
|
|
|
.kill_account(&account, &password)
|
|
|
|
.map(|_| true)
|
2016-11-23 20:16:33 +01:00
|
|
|
.map_err(|e| errors::account("Could not delete account.", e))
|
2016-11-20 16:17:57 +01:00
|
|
|
}
|
|
|
|
|
2017-11-14 11:38:17 +01:00
|
|
|
fn remove_address(&self, addr: RpcH160) -> Result<bool> {
|
2017-03-29 17:07:58 +02:00
|
|
|
let store = self.account_provider()?;
|
2016-12-07 16:53:46 +01:00
|
|
|
let addr: Address = addr.into();
|
|
|
|
|
2017-02-03 13:56:48 +01:00
|
|
|
store.remove_address(addr);
|
2016-12-07 16:53:46 +01:00
|
|
|
Ok(true)
|
|
|
|
}
|
|
|
|
|
2017-11-14 11:38:17 +01:00
|
|
|
fn set_account_name(&self, addr: RpcH160, name: String) -> Result<bool> {
|
2017-03-29 17:07:58 +02:00
|
|
|
let store = self.account_provider()?;
|
2016-10-31 17:11:56 +01:00
|
|
|
let addr: Address = addr.into();
|
|
|
|
|
|
|
|
store.set_account_name(addr.clone(), name.clone())
|
2017-02-03 13:56:48 +01:00
|
|
|
.unwrap_or_else(|_| store.set_address_name(addr, name));
|
2016-10-31 17:11:56 +01:00
|
|
|
Ok(true)
|
2016-10-27 19:26:34 +02:00
|
|
|
}
|
|
|
|
|
2017-11-14 11:38:17 +01:00
|
|
|
fn set_account_meta(&self, addr: RpcH160, meta: String) -> Result<bool> {
|
2017-03-29 17:07:58 +02:00
|
|
|
let store = self.account_provider()?;
|
2016-10-31 17:11:56 +01:00
|
|
|
let addr: Address = addr.into();
|
|
|
|
|
|
|
|
store.set_account_meta(addr.clone(), meta.clone())
|
2017-02-03 13:56:48 +01:00
|
|
|
.unwrap_or_else(|_| store.set_address_meta(addr, meta));
|
2016-10-31 17:11:56 +01:00
|
|
|
Ok(true)
|
2016-10-27 19:26:34 +02:00
|
|
|
}
|
|
|
|
|
2017-11-14 11:38:17 +01:00
|
|
|
fn set_dapp_addresses(&self, dapp: DappId, addresses: Option<Vec<RpcH160>>) -> Result<bool> {
|
2017-03-29 17:07:58 +02:00
|
|
|
let store = self.account_provider()?;
|
2017-02-20 16:33:12 +01:00
|
|
|
|
|
|
|
store.set_dapp_addresses(dapp.into(), addresses.map(into_vec))
|
|
|
|
.map_err(|e| errors::account("Couldn't set dapp addresses.", e))
|
|
|
|
.map(|_| true)
|
2016-11-06 12:51:53 +01:00
|
|
|
}
|
|
|
|
|
2017-11-14 11:38:17 +01:00
|
|
|
fn dapp_addresses(&self, dapp: DappId) -> Result<Vec<RpcH160>> {
|
2017-03-29 17:07:58 +02:00
|
|
|
let store = self.account_provider()?;
|
2016-11-22 11:56:27 +01:00
|
|
|
|
2017-02-20 16:33:12 +01:00
|
|
|
store.dapp_addresses(dapp.into())
|
|
|
|
.map_err(|e| errors::account("Couldn't get dapp addresses.", e))
|
|
|
|
.map(into_vec)
|
|
|
|
}
|
|
|
|
|
2017-11-14 11:38:17 +01:00
|
|
|
fn set_dapp_default_address(&self, dapp: DappId, address: RpcH160) -> Result<bool> {
|
2017-03-29 17:07:58 +02:00
|
|
|
let store = self.account_provider()?;
|
2017-02-20 16:33:12 +01:00
|
|
|
|
|
|
|
store.set_dapp_default_address(dapp.into(), address.into())
|
|
|
|
.map_err(|e| errors::account("Couldn't set dapp default address.", e))
|
2016-11-22 11:56:27 +01:00
|
|
|
.map(|_| true)
|
|
|
|
}
|
|
|
|
|
2017-11-14 11:38:17 +01:00
|
|
|
fn dapp_default_address(&self, dapp: DappId) -> Result<RpcH160> {
|
2017-03-29 17:07:58 +02:00
|
|
|
let store = self.account_provider()?;
|
2016-12-10 12:34:20 +01:00
|
|
|
|
2017-02-20 16:33:12 +01:00
|
|
|
store.dapp_default_address(dapp.into())
|
|
|
|
.map_err(|e| errors::account("Couldn't get dapp default address.", e))
|
|
|
|
.map(Into::into)
|
2016-12-10 12:34:20 +01:00
|
|
|
}
|
|
|
|
|
2017-11-14 11:38:17 +01:00
|
|
|
fn set_new_dapps_addresses(&self, addresses: Option<Vec<RpcH160>>) -> Result<bool> {
|
2017-03-29 17:07:58 +02:00
|
|
|
let store = self.account_provider()?;
|
2016-12-10 12:34:20 +01:00
|
|
|
|
|
|
|
store
|
2017-02-20 16:33:12 +01:00
|
|
|
.set_new_dapps_addresses(addresses.map(into_vec))
|
|
|
|
.map_err(|e| errors::account("Couldn't set dapps addresses.", e))
|
2016-12-10 12:34:20 +01:00
|
|
|
.map(|_| true)
|
|
|
|
}
|
|
|
|
|
2017-11-14 11:38:17 +01:00
|
|
|
fn new_dapps_addresses(&self) -> Result<Option<Vec<RpcH160>>> {
|
2017-03-29 17:07:58 +02:00
|
|
|
let store = self.account_provider()?;
|
2016-12-10 12:34:20 +01:00
|
|
|
|
2017-02-20 16:33:12 +01:00
|
|
|
store.new_dapps_addresses()
|
|
|
|
.map_err(|e| errors::account("Couldn't get dapps addresses.", e))
|
2016-12-10 12:34:20 +01:00
|
|
|
.map(|accounts| accounts.map(into_vec))
|
|
|
|
}
|
|
|
|
|
2017-11-14 11:38:17 +01:00
|
|
|
fn set_new_dapps_default_address(&self, address: RpcH160) -> Result<bool> {
|
2017-03-29 17:07:58 +02:00
|
|
|
let store = self.account_provider()?;
|
2017-02-20 16:33:12 +01:00
|
|
|
|
|
|
|
store.set_new_dapps_default_address(address.into())
|
|
|
|
.map_err(|e| errors::account("Couldn't set new dapps default address.", e))
|
|
|
|
.map(|_| true)
|
|
|
|
}
|
|
|
|
|
2017-11-14 11:38:17 +01:00
|
|
|
fn new_dapps_default_address(&self) -> Result<RpcH160> {
|
2017-03-29 17:07:58 +02:00
|
|
|
let store = self.account_provider()?;
|
2017-02-20 16:33:12 +01:00
|
|
|
|
|
|
|
store.new_dapps_default_address()
|
|
|
|
.map_err(|e| errors::account("Couldn't get new dapps default address.", e))
|
|
|
|
.map(Into::into)
|
|
|
|
}
|
|
|
|
|
2017-11-14 11:38:17 +01:00
|
|
|
fn recent_dapps(&self) -> Result<BTreeMap<DappId, u64>> {
|
2017-03-29 17:07:58 +02:00
|
|
|
let store = self.account_provider()?;
|
2016-12-10 12:34:20 +01:00
|
|
|
|
|
|
|
store.recent_dapps()
|
|
|
|
.map_err(|e| errors::account("Couldn't get recent dapps.", e))
|
2017-01-30 10:59:46 +01:00
|
|
|
.map(|map| map.into_iter().map(|(k, v)| (k.into(), v)).collect())
|
2016-12-10 12:34:20 +01:00
|
|
|
}
|
|
|
|
|
2017-11-14 11:38:17 +01:00
|
|
|
fn import_geth_accounts(&self, addresses: Vec<RpcH160>) -> Result<Vec<RpcH160>> {
|
2017-03-29 17:07:58 +02:00
|
|
|
let store = self.account_provider()?;
|
2016-10-31 17:11:56 +01:00
|
|
|
|
|
|
|
store
|
2016-12-10 12:34:20 +01:00
|
|
|
.import_geth_accounts(into_vec(addresses), false)
|
|
|
|
.map(into_vec)
|
2016-10-31 17:11:56 +01:00
|
|
|
.map_err(|e| errors::account("Couldn't import Geth accounts", e))
|
2016-10-27 19:26:34 +02:00
|
|
|
}
|
|
|
|
|
2017-11-14 11:38:17 +01:00
|
|
|
fn geth_accounts(&self) -> Result<Vec<RpcH160>> {
|
2017-03-29 17:07:58 +02:00
|
|
|
let store = self.account_provider()?;
|
2016-10-31 17:11:56 +01:00
|
|
|
|
2016-12-10 12:34:20 +01:00
|
|
|
Ok(into_vec(store.list_geth_accounts(false)))
|
2016-10-27 19:26:34 +02:00
|
|
|
}
|
2017-02-05 16:17:56 +01:00
|
|
|
|
2017-11-14 11:38:17 +01:00
|
|
|
fn create_vault(&self, name: String, password: String) -> Result<bool> {
|
2017-03-29 17:07:58 +02:00
|
|
|
self.account_provider()?
|
2017-02-05 16:17:56 +01:00
|
|
|
.create_vault(&name, &password)
|
|
|
|
.map_err(|e| errors::account("Could not create vault.", e))
|
|
|
|
.map(|_| true)
|
|
|
|
}
|
|
|
|
|
2017-11-14 11:38:17 +01:00
|
|
|
fn open_vault(&self, name: String, password: String) -> Result<bool> {
|
2017-03-29 17:07:58 +02:00
|
|
|
self.account_provider()?
|
2017-02-05 16:17:56 +01:00
|
|
|
.open_vault(&name, &password)
|
|
|
|
.map_err(|e| errors::account("Could not open vault.", e))
|
|
|
|
.map(|_| true)
|
|
|
|
}
|
|
|
|
|
2017-11-14 11:38:17 +01:00
|
|
|
fn close_vault(&self, name: String) -> Result<bool> {
|
2017-03-29 17:07:58 +02:00
|
|
|
self.account_provider()?
|
2017-02-05 16:17:56 +01:00
|
|
|
.close_vault(&name)
|
|
|
|
.map_err(|e| errors::account("Could not close vault.", e))
|
|
|
|
.map(|_| true)
|
|
|
|
}
|
|
|
|
|
2017-11-14 11:38:17 +01:00
|
|
|
fn list_vaults(&self) -> Result<Vec<String>> {
|
2017-03-29 17:07:58 +02:00
|
|
|
self.account_provider()?
|
2017-02-05 16:17:56 +01:00
|
|
|
.list_vaults()
|
|
|
|
.map_err(|e| errors::account("Could not list vaults.", e))
|
|
|
|
}
|
|
|
|
|
2017-11-14 11:38:17 +01:00
|
|
|
fn list_opened_vaults(&self) -> Result<Vec<String>> {
|
2017-03-29 17:07:58 +02:00
|
|
|
self.account_provider()?
|
2017-02-05 16:17:56 +01:00
|
|
|
.list_opened_vaults()
|
|
|
|
.map_err(|e| errors::account("Could not list vaults.", e))
|
|
|
|
}
|
|
|
|
|
2017-11-14 11:38:17 +01:00
|
|
|
fn change_vault_password(&self, name: String, new_password: String) -> Result<bool> {
|
2017-03-29 17:07:58 +02:00
|
|
|
self.account_provider()?
|
2017-02-05 16:17:56 +01:00
|
|
|
.change_vault_password(&name, &new_password)
|
|
|
|
.map_err(|e| errors::account("Could not change vault password.", e))
|
|
|
|
.map(|_| true)
|
|
|
|
}
|
|
|
|
|
2017-11-14 11:38:17 +01:00
|
|
|
fn change_vault(&self, address: RpcH160, new_vault: String) -> Result<bool> {
|
2017-03-29 17:07:58 +02:00
|
|
|
self.account_provider()?
|
2017-02-05 16:17:56 +01:00
|
|
|
.change_vault(address.into(), &new_vault)
|
|
|
|
.map_err(|e| errors::account("Could not change vault.", e))
|
|
|
|
.map(|_| true)
|
|
|
|
}
|
2017-02-08 13:53:39 +01:00
|
|
|
|
2017-11-14 11:38:17 +01:00
|
|
|
fn get_vault_meta(&self, name: String) -> Result<String> {
|
2017-03-29 17:07:58 +02:00
|
|
|
self.account_provider()?
|
2017-02-08 13:53:39 +01:00
|
|
|
.get_vault_meta(&name)
|
|
|
|
.map_err(|e| errors::account("Could not get vault metadata.", e))
|
|
|
|
}
|
|
|
|
|
2017-11-14 11:38:17 +01:00
|
|
|
fn set_vault_meta(&self, name: String, meta: String) -> Result<bool> {
|
2017-03-29 17:07:58 +02:00
|
|
|
self.account_provider()?
|
2017-02-08 13:53:39 +01:00
|
|
|
.set_vault_meta(&name, &meta)
|
|
|
|
.map_err(|e| errors::account("Could not update vault metadata.", e))
|
|
|
|
.map(|_| true)
|
|
|
|
}
|
2017-02-15 16:56:15 +01:00
|
|
|
|
2017-11-14 11:38:17 +01:00
|
|
|
fn derive_key_index(&self, addr: RpcH160, password: String, derivation: DeriveHierarchical, save_as_account: bool) -> Result<RpcH160> {
|
2017-02-15 16:56:15 +01:00
|
|
|
let addr: Address = addr.into();
|
2017-03-29 17:07:58 +02:00
|
|
|
self.account_provider()?
|
2017-02-15 16:56:15 +01:00
|
|
|
.derive_account(
|
|
|
|
&addr,
|
|
|
|
Some(password),
|
|
|
|
Derive::from(derivation).to_derivation()
|
|
|
|
.map_err(|c| errors::account("Could not parse derivation request: {:?}", c))?,
|
|
|
|
save_as_account)
|
|
|
|
.map(Into::into)
|
|
|
|
.map_err(|e| errors::account("Could not derive account.", e))
|
|
|
|
}
|
|
|
|
|
2017-11-14 11:38:17 +01:00
|
|
|
fn derive_key_hash(&self, addr: RpcH160, password: String, derivation: DeriveHash, save_as_account: bool) -> Result<RpcH160> {
|
2017-02-15 16:56:15 +01:00
|
|
|
let addr: Address = addr.into();
|
2017-03-29 17:07:58 +02:00
|
|
|
self.account_provider()?
|
2017-02-15 16:56:15 +01:00
|
|
|
.derive_account(
|
|
|
|
&addr,
|
|
|
|
Some(password),
|
|
|
|
Derive::from(derivation).to_derivation()
|
|
|
|
.map_err(|c| errors::account("Could not parse derivation request: {:?}", c))?,
|
|
|
|
save_as_account)
|
|
|
|
.map(Into::into)
|
|
|
|
.map_err(|e| errors::account("Could not derive account.", e))
|
|
|
|
}
|
2017-03-23 13:23:03 +01:00
|
|
|
|
2017-11-14 11:38:17 +01:00
|
|
|
fn export_account(&self, addr: RpcH160, password: String) -> Result<KeyFile> {
|
2017-03-23 13:23:03 +01:00
|
|
|
let addr = addr.into();
|
2017-03-29 17:07:58 +02:00
|
|
|
self.account_provider()?
|
2017-03-23 13:23:03 +01:00
|
|
|
.export_account(
|
|
|
|
&addr,
|
|
|
|
password,
|
|
|
|
)
|
|
|
|
.map(Into::into)
|
|
|
|
.map_err(|e| errors::account("Could not export account.", e))
|
|
|
|
}
|
2017-04-12 12:15:13 +02:00
|
|
|
|
2017-11-14 11:38:17 +01:00
|
|
|
fn sign_message(&self, addr: RpcH160, password: String, message: RpcH256) -> Result<RpcH520> {
|
2017-04-12 12:15:13 +02:00
|
|
|
self.account_provider()?
|
|
|
|
.sign(
|
|
|
|
addr.into(),
|
|
|
|
Some(password),
|
|
|
|
message.into()
|
|
|
|
)
|
|
|
|
.map(Into::into)
|
|
|
|
.map_err(|e| errors::account("Could not sign message.", e))
|
|
|
|
}
|
2017-09-14 19:28:43 +02:00
|
|
|
|
2017-11-14 11:38:17 +01:00
|
|
|
fn hardware_pin_matrix_ack(&self, path: String, pin: String) -> Result<bool> {
|
2017-09-14 19:28:43 +02:00
|
|
|
let store = self.account_provider()?;
|
|
|
|
Ok(store.hardware_pin_matrix_ack(&path, &pin).map_err(|e| errors::account("Error communicating with hardware wallet.", e))?)
|
|
|
|
}
|
2016-10-27 19:26:34 +02:00
|
|
|
}
|
2016-12-10 12:34:20 +01:00
|
|
|
|
|
|
|
fn into_vec<A, B>(a: Vec<A>) -> Vec<B> where
|
|
|
|
A: Into<B>
|
|
|
|
{
|
|
|
|
a.into_iter().map(Into::into).collect()
|
|
|
|
}
|