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:
committed by
Arkadiy Paronyan
parent
c32244ea4a
commit
286b67d54b
@@ -30,6 +30,7 @@ extern crate jsonrpc_http_server;
|
||||
extern crate ethcore_util as util;
|
||||
extern crate ethcore_io as io;
|
||||
extern crate ethcore;
|
||||
extern crate ethstore;
|
||||
extern crate ethsync;
|
||||
extern crate transient_hashmap;
|
||||
extern crate json_ipc_server as ipc;
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -67,6 +67,9 @@ pub trait Ethcore: Sized + Send + Sync + 'static {
|
||||
/// Returns error when signer is disabled
|
||||
fn unsigned_transactions_count(&self, _: Params) -> Result<Value, Error>;
|
||||
|
||||
/// Returns a cryptographically random phrase sufficient for securely seeding a secret key.
|
||||
fn generate_secret_phrase(&self, _: Params) -> Result<Value, Error>;
|
||||
|
||||
/// Should be used to convert object to io delegate.
|
||||
fn to_delegate(self) -> IoDelegate<Self> {
|
||||
let mut delegate = IoDelegate::new(Arc::new(self));
|
||||
@@ -86,6 +89,7 @@ pub trait Ethcore: Sized + Send + Sync + 'static {
|
||||
delegate.add_method("ethcore_defaultExtraData", Ethcore::default_extra_data);
|
||||
delegate.add_method("ethcore_gasPriceStatistics", Ethcore::gas_price_statistics);
|
||||
delegate.add_method("ethcore_unsignedTransactionsCount", Ethcore::unsigned_transactions_count);
|
||||
delegate.add_method("ethcore_generateSecretPhrase", Ethcore::generate_secret_phrase);
|
||||
|
||||
delegate
|
||||
}
|
||||
|
||||
@@ -25,8 +25,17 @@ pub trait Personal: Sized + Send + Sync + 'static {
|
||||
fn accounts(&self, _: Params) -> Result<Value, Error>;
|
||||
|
||||
/// Creates new account (it becomes new current unlocked account)
|
||||
/// Param is the password for the account.
|
||||
fn new_account(&self, _: Params) -> Result<Value, Error>;
|
||||
|
||||
/// Creates new account from the given phrase using standard brainwallet mechanism.
|
||||
/// Second parameter is password for the new account.
|
||||
fn new_account_from_phrase(&self, _: Params) -> Result<Value, Error>;
|
||||
|
||||
/// Creates new account from the given JSON wallet.
|
||||
/// Second parameter is password for the wallet and the new account.
|
||||
fn new_account_from_wallet(&self, params: Params) -> Result<Value, Error>;
|
||||
|
||||
/// Unlocks specified account for use (can only be one unlocked account at one moment)
|
||||
fn unlock_account(&self, _: Params) -> Result<Value, Error>;
|
||||
|
||||
@@ -51,6 +60,8 @@ pub trait Personal: Sized + Send + Sync + 'static {
|
||||
delegate.add_method("personal_signerEnabled", Personal::signer_enabled);
|
||||
delegate.add_method("personal_listAccounts", Personal::accounts);
|
||||
delegate.add_method("personal_newAccount", Personal::new_account);
|
||||
delegate.add_method("personal_newAccountFromPhrase", Personal::new_account_from_phrase);
|
||||
delegate.add_method("personal_newAccountFromWallet", Personal::new_account_from_wallet);
|
||||
delegate.add_method("personal_unlockAccount", Personal::unlock_account);
|
||||
delegate.add_method("personal_signAndSendTransaction", Personal::sign_and_send_transaction);
|
||||
delegate.add_method("personal_setAccountName", Personal::set_account_name);
|
||||
|
||||
Reference in New Issue
Block a user