Merge pull request #1912 from ethcore/rpc-address-from-phrase

RPC for deriving address from phrase.
This commit is contained in:
Tomasz Drwięga 2016-08-11 10:49:36 +02:00 committed by GitHub
commit 07844d611e
2 changed files with 13 additions and 2 deletions

View File

@ -15,7 +15,7 @@
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
//! Ethcore-specific rpc implementation.
use util::{RotatingLogger};
use util::{RotatingLogger, KeyPair};
use util::misc::version_data;
use std::sync::{Arc, Weak};
use std::collections::{BTreeMap};
@ -24,7 +24,7 @@ use ethcore::client::{MiningBlockChainClient};
use jsonrpc_core::*;
use ethcore::miner::MinerService;
use v1::traits::Ethcore;
use v1::types::{Bytes, U256};
use v1::types::{Bytes, U256, H160};
use v1::helpers::{errors, SigningQueue, ConfirmationsQueue, NetworkSettings};
use v1::helpers::params::expect_no_params;
@ -173,4 +173,11 @@ impl<C, M> Ethcore for EthcoreClient<C, M> where M: MinerService + 'static, C: M
to_value(&random_phrase(12))
}
fn phrase_to_address(&self, params: Params) -> Result<Value, Error> {
try!(self.active());
from_params::<(String,)>(params).and_then(|(phrase,)|
to_value(&H160::from(KeyPair::from_phrase(&phrase).address()))
)
}
}

View File

@ -70,6 +70,9 @@ pub trait Ethcore: Sized + Send + Sync + 'static {
/// Returns a cryptographically random phrase sufficient for securely seeding a secret key.
fn generate_secret_phrase(&self, _: Params) -> Result<Value, Error>;
/// Returns whatever address would be derived from the given phrase if it were to seed a brainwallet.
fn phrase_to_address(&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));
@ -90,6 +93,7 @@ pub trait Ethcore: Sized + Send + Sync + 'static {
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.add_method("ethcore_phraseToAddress", Ethcore::phrase_to_address);
delegate
}