personal is back to the master ver

This commit is contained in:
Nikolay Volf 2016-03-10 19:15:10 +04:00
parent 3b21a5f54c
commit 094ae4e9f9

View File

@ -18,27 +18,28 @@
use std::sync::{Arc, Weak};
use jsonrpc_core::*;
use v1::traits::Personal;
use util::keys::store::*;
use util::Address;
use ethcore::client::Client;
use std::sync::RwLock;
/// Account management (personal) rpc implementation.
pub struct PersonalClient {
client: Weak<Client>,
secret_store: Weak<RwLock<SecretStore>>,
}
impl PersonalClient {
/// Creates new PersonalClient
pub fn new(client: &Arc<Client>) -> Self {
pub fn new(store: &Arc<RwLock<SecretStore>>) -> Self {
PersonalClient {
client: Arc::downgrade(client),
secret_store: Arc::downgrade(store),
}
}
}
impl Personal for PersonalClient {
fn accounts(&self, _: Params) -> Result<Value, Error> {
let client = take_weak!(self.client);
let store = client.secret_store().read().unwrap();
let store_wk = take_weak!(self.secret_store);
let store = store_wk.read().unwrap();
match store.accounts() {
Ok(account_list) => {
Ok(Value::Array(account_list.iter()
@ -53,8 +54,8 @@ impl Personal for PersonalClient {
fn new_account(&self, params: Params) -> Result<Value, Error> {
from_params::<(String, )>(params).and_then(
|(pass, )| {
let client = take_weak!(self.client);
let mut store = client.secret_store().write().unwrap();
let store_wk = take_weak!(self.secret_store);
let mut store = store_wk.write().unwrap();
match store.new_account(&pass) {
Ok(address) => Ok(Value::String(format!("{:?}", address))),
Err(_) => Err(Error::internal_error())
@ -66,8 +67,8 @@ impl Personal for PersonalClient {
fn unlock_account(&self, params: Params) -> Result<Value, Error> {
from_params::<(Address, String, u64)>(params).and_then(
|(account, account_pass, _)|{
let client = take_weak!(self.client);
let store = client.secret_store().read().unwrap();
let store_wk = take_weak!(self.secret_store);
let store = store_wk.read().unwrap();
match store.unlock_account(&account, &account_pass) {
Ok(_) => Ok(Value::Bool(true)),
Err(_) => Ok(Value::Bool(false)),