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