Wallet rpcs (#1898)

* Add wallet RPCs.

* Add wordlist file.

* Add standard brain wallet tests.

* Allow import of JSON wallets.

* Address grumble.
This commit is contained in:
Gav Wood
2016-08-10 17:57:40 +02:00
committed by Arkadiy Paronyan
parent c32244ea4a
commit 286b67d54b
18 changed files with 7685 additions and 6 deletions

View File

@@ -19,6 +19,7 @@ use util::{RotatingLogger};
use util::misc::version_data;
use std::sync::{Arc, Weak};
use std::collections::{BTreeMap};
use ethstore::random_phrase;
use ethcore::client::{MiningBlockChainClient};
use jsonrpc_core::*;
use ethcore::miner::MinerService;
@@ -165,4 +166,11 @@ impl<C, M> Ethcore for EthcoreClient<C, M> where M: MinerService + 'static, C: M
Some(ref queue) => to_value(&queue.len()),
}
}
fn generate_secret_phrase(&self, params: Params) -> Result<Value, Error> {
try!(self.active());
try!(expect_no_params(params));
to_value(&random_phrase(12))
}
}

View File

@@ -24,7 +24,7 @@ use v1::helpers::{errors, TransactionRequest as TRequest};
use v1::helpers::params::expect_no_params;
use v1::helpers::dispatch::unlock_sign_and_dispatch;
use ethcore::account_provider::AccountProvider;
use util::Address;
use util::{Address, KeyPair};
use ethcore::client::MiningBlockChainClient;
use ethcore::miner::MinerService;
@@ -89,6 +89,32 @@ impl<C: 'static, M: 'static> Personal for PersonalClient<C, M> where C: MiningBl
)
}
fn new_account_from_phrase(&self, params: Params) -> Result<Value, Error> {
try!(self.active());
from_params::<(String, String, )>(params).and_then(
|(phrase, pass, )| {
let store = take_weak!(self.accounts);
match store.insert_account(*KeyPair::from_phrase(&phrase).secret(), &pass) {
Ok(address) => to_value(&RpcH160::from(address)),
Err(e) => Err(errors::account("Could not create account.", e)),
}
}
)
}
fn new_account_from_wallet(&self, params: Params) -> Result<Value, Error> {
try!(self.active());
from_params::<(String, String, )>(params).and_then(
|(json, pass, )| {
let store = take_weak!(self.accounts);
match store.import_presale(json.as_bytes(), &pass).or_else(|_| store.import_wallet(json.as_bytes(), &pass)) {
Ok(address) => to_value(&RpcH160::from(address)),
Err(e) => Err(errors::account("Could not create account.", e)),
}
}
)
}
fn unlock_account(&self, params: Params) -> Result<Value, Error> {
try!(self.active());
from_params::<(RpcH160, String, Option<u64>)>(params).and_then(