Moving personal_ to autoargs (#3000)
This commit is contained in:
parent
547871f933
commit
ff90fac125
@ -60,7 +60,7 @@ pub fn decrypt(accounts: &AccountProvider, address: Address, password: Option<St
|
|||||||
.map(to_value)
|
.map(to_value)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn sign_and_dispatch<C, M>(client: &C, miner: &M, accounts: &AccountProvider, request: TransactionRequest, password: Option<String>) -> Result<Value, Error>
|
pub fn sign_and_dispatch<C, M>(client: &C, miner: &M, accounts: &AccountProvider, request: TransactionRequest, password: Option<String>) -> Result<RpcH256, Error>
|
||||||
where C: MiningBlockChainClient, M: MinerService {
|
where C: MiningBlockChainClient, M: MinerService {
|
||||||
|
|
||||||
let address = request.from;
|
let address = request.from;
|
||||||
@ -72,7 +72,7 @@ pub fn sign_and_dispatch<C, M>(client: &C, miner: &M, accounts: &AccountProvider
|
|||||||
};
|
};
|
||||||
|
|
||||||
trace!(target: "miner", "send_transaction: dispatching tx: {}", ::rlp::encode(&signed_transaction).to_vec().pretty());
|
trace!(target: "miner", "send_transaction: dispatching tx: {}", ::rlp::encode(&signed_transaction).to_vec().pretty());
|
||||||
dispatch_transaction(&*client, &*miner, signed_transaction).map(to_value)
|
dispatch_transaction(&*client, &*miner, signed_transaction)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn prepare_transaction<C, M>(client: &C, miner: &M, request: TransactionRequest) -> Transaction where C: MiningBlockChainClient, M: MinerService {
|
fn prepare_transaction<C, M>(client: &C, miner: &M, request: TransactionRequest) -> Transaction where C: MiningBlockChainClient, M: MinerService {
|
||||||
|
@ -122,7 +122,7 @@ impl<C, M> EthSigningQueueClient<C, M> where C: MiningBlockChainClient, M: Miner
|
|||||||
let (client, miner) = (take_weak!(self.client), take_weak!(self.miner));
|
let (client, miner) = (take_weak!(self.client), take_weak!(self.miner));
|
||||||
self.add_to_queue(
|
self.add_to_queue(
|
||||||
request.from,
|
request.from,
|
||||||
|accounts| sign_and_dispatch(&*client, &*miner, accounts, request.clone(), None),
|
|accounts| sign_and_dispatch(&*client, &*miner, accounts, request.clone(), None).map(to_value),
|
||||||
|| {
|
|| {
|
||||||
let request = fill_optional_fields(request.clone(), &*client, &*miner);
|
let request = fill_optional_fields(request.clone(), &*client, &*miner);
|
||||||
ConfirmationPayload::Transaction(request)
|
ConfirmationPayload::Transaction(request)
|
||||||
@ -251,7 +251,7 @@ impl<C, M> EthSigning for EthSigningUnsafeClient<C, M> where
|
|||||||
ready.ready(self.active()
|
ready.ready(self.active()
|
||||||
.and_then(|_| from_params::<(TransactionRequest, )>(params))
|
.and_then(|_| from_params::<(TransactionRequest, )>(params))
|
||||||
.and_then(|(request, )| {
|
.and_then(|(request, )| {
|
||||||
sign_and_dispatch(&*take_weak!(self.client), &*take_weak!(self.miner), &*take_weak!(self.accounts), request.into(), None)
|
sign_and_dispatch(&*take_weak!(self.client), &*take_weak!(self.miner), &*take_weak!(self.accounts), request.into(), None).map(to_value)
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,7 +21,6 @@ use jsonrpc_core::*;
|
|||||||
use v1::traits::Personal;
|
use v1::traits::Personal;
|
||||||
use v1::types::{H160 as RpcH160};
|
use v1::types::{H160 as RpcH160};
|
||||||
use v1::helpers::errors;
|
use v1::helpers::errors;
|
||||||
use v1::helpers::params::expect_no_params;
|
|
||||||
use ethcore::account_provider::AccountProvider;
|
use ethcore::account_provider::AccountProvider;
|
||||||
use ethcore::client::MiningBlockChainClient;
|
use ethcore::client::MiningBlockChainClient;
|
||||||
|
|
||||||
@ -49,22 +48,21 @@ impl<C> PersonalClient<C> where C: MiningBlockChainClient {
|
|||||||
|
|
||||||
impl<C: 'static> Personal for PersonalClient<C> where C: MiningBlockChainClient {
|
impl<C: 'static> Personal for PersonalClient<C> where C: MiningBlockChainClient {
|
||||||
|
|
||||||
fn accounts(&self, params: Params) -> Result<Value, Error> {
|
fn accounts(&self) -> Result<Vec<RpcH160>, Error> {
|
||||||
try!(self.active());
|
try!(self.active());
|
||||||
try!(expect_no_params(params));
|
|
||||||
|
|
||||||
let store = take_weak!(self.accounts);
|
let store = take_weak!(self.accounts);
|
||||||
let accounts = try!(store.accounts().map_err(|e| errors::internal("Could not fetch accounts.", e)));
|
let accounts = try!(store.accounts().map_err(|e| errors::account("Could not fetch accounts.", e)));
|
||||||
Ok(to_value(&accounts.into_iter().map(Into::into).collect::<Vec<RpcH160>>()))
|
Ok(accounts.into_iter().map(Into::into).collect::<Vec<RpcH160>>())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn accounts_info(&self, params: Params) -> Result<Value, Error> {
|
fn accounts_info(&self) -> Result<BTreeMap<String, Value>, Error> {
|
||||||
try!(self.active());
|
try!(self.active());
|
||||||
try!(expect_no_params(params));
|
|
||||||
let store = take_weak!(self.accounts);
|
let store = take_weak!(self.accounts);
|
||||||
let info = try!(store.accounts_info().map_err(|e| errors::account("Could not fetch account info.", e)));
|
let info = try!(store.accounts_info().map_err(|e| errors::account("Could not fetch account info.", e)));
|
||||||
let other = store.addresses_info().expect("addresses_info always returns Ok; qed");
|
let other = store.addresses_info().expect("addresses_info always returns Ok; qed");
|
||||||
Ok(Value::Object(info.into_iter().chain(other.into_iter()).map(|(a, v)| {
|
|
||||||
|
Ok(info.into_iter().chain(other.into_iter()).map(|(a, v)| {
|
||||||
let m = map![
|
let m = map![
|
||||||
"name".to_owned() => to_value(&v.name),
|
"name".to_owned() => to_value(&v.name),
|
||||||
"meta".to_owned() => to_value(&v.meta),
|
"meta".to_owned() => to_value(&v.meta),
|
||||||
@ -75,6 +73,6 @@ impl<C: 'static> Personal for PersonalClient<C> where C: MiningBlockChainClient
|
|||||||
}
|
}
|
||||||
];
|
];
|
||||||
(format!("0x{}", a.hex()), Value::Object(m))
|
(format!("0x{}", a.hex()), Value::Object(m))
|
||||||
}).collect::<BTreeMap<_, _>>()))
|
}).collect())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,6 @@ use ethkey::{Brain, Generator};
|
|||||||
use v1::traits::PersonalAccounts;
|
use v1::traits::PersonalAccounts;
|
||||||
use v1::types::{H160 as RpcH160, H256 as RpcH256, TransactionRequest};
|
use v1::types::{H160 as RpcH160, H256 as RpcH256, TransactionRequest};
|
||||||
use v1::helpers::errors;
|
use v1::helpers::errors;
|
||||||
use v1::helpers::params::expect_no_params;
|
|
||||||
use v1::helpers::dispatch::sign_and_dispatch;
|
use v1::helpers::dispatch::sign_and_dispatch;
|
||||||
use ethcore::account_provider::AccountProvider;
|
use ethcore::account_provider::AccountProvider;
|
||||||
use ethcore::client::MiningBlockChainClient;
|
use ethcore::client::MiningBlockChainClient;
|
||||||
@ -56,64 +55,48 @@ impl<C, M> PersonalAccountsClient<C, M> where C: MiningBlockChainClient, M: Mine
|
|||||||
|
|
||||||
impl<C: 'static, M: 'static> PersonalAccounts for PersonalAccountsClient<C, M> where C: MiningBlockChainClient, M: MinerService {
|
impl<C: 'static, M: 'static> PersonalAccounts for PersonalAccountsClient<C, M> where C: MiningBlockChainClient, M: MinerService {
|
||||||
|
|
||||||
fn new_account(&self, params: Params) -> Result<Value, Error> {
|
fn new_account(&self, pass: String) -> Result<RpcH160, Error> {
|
||||||
try!(self.active());
|
try!(self.active());
|
||||||
from_params::<(String, )>(params).and_then(
|
|
||||||
|(pass, )| {
|
|
||||||
let store = take_weak!(self.accounts);
|
let store = take_weak!(self.accounts);
|
||||||
match store.new_account(&pass) {
|
|
||||||
Ok(address) => Ok(to_value(&RpcH160::from(address))),
|
store.new_account(&pass)
|
||||||
Err(e) => Err(errors::account("Could not create account.", e)),
|
.map(Into::into)
|
||||||
}
|
.map_err(|e| errors::account("Could not create account.", e))
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn new_account_from_phrase(&self, params: Params) -> Result<Value, Error> {
|
fn new_account_from_phrase(&self, phrase: String, pass: String) -> Result<RpcH160, Error> {
|
||||||
try!(self.active());
|
try!(self.active());
|
||||||
from_params::<(String, String, )>(params).and_then(
|
|
||||||
|(phrase, pass, )| {
|
|
||||||
let store = take_weak!(self.accounts);
|
let store = take_weak!(self.accounts);
|
||||||
match store.insert_account(*Brain::new(phrase).generate().unwrap().secret(), &pass) {
|
|
||||||
Ok(address) => Ok(to_value(&RpcH160::from(address))),
|
store.insert_account(*Brain::new(phrase).generate().unwrap().secret(), &pass)
|
||||||
Err(e) => Err(errors::account("Could not create account.", e)),
|
.map(Into::into)
|
||||||
}
|
.map_err(|e| errors::account("Could not create account.", e))
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn new_account_from_wallet(&self, params: Params) -> Result<Value, Error> {
|
fn new_account_from_wallet(&self, json: String, pass: String) -> Result<RpcH160, Error> {
|
||||||
try!(self.active());
|
try!(self.active());
|
||||||
from_params::<(String, String, )>(params).and_then(
|
|
||||||
|(json, pass, )| {
|
|
||||||
let store = take_weak!(self.accounts);
|
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) => Ok(to_value(&RpcH160::from(address))),
|
store.import_presale(json.as_bytes(), &pass)
|
||||||
Err(e) => Err(errors::account("Could not create account.", e)),
|
.or_else(|_| store.import_wallet(json.as_bytes(), &pass))
|
||||||
}
|
.map(Into::into)
|
||||||
}
|
.map_err(|e| errors::account("Could not create account.", e))
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn new_account_from_secret(&self, params: Params) -> Result<Value, Error> {
|
fn new_account_from_secret(&self, secret: RpcH256, pass: String) -> Result<RpcH160, Error> {
|
||||||
try!(self.active());
|
try!(self.active());
|
||||||
from_params::<(RpcH256, String, )>(params).and_then(
|
|
||||||
|(secret, pass, )| {
|
|
||||||
let store = take_weak!(self.accounts);
|
let store = take_weak!(self.accounts);
|
||||||
match store.insert_account(secret.into(), &pass) {
|
|
||||||
Ok(address) => Ok(to_value(&RpcH160::from(address))),
|
store.insert_account(secret.into(), &pass)
|
||||||
Err(e) => Err(errors::account("Could not create account.", e)),
|
.map(Into::into)
|
||||||
}
|
.map_err(|e| errors::account("Could not create account.", e))
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn unlock_account(&self, params: Params) -> Result<Value, Error> {
|
fn unlock_account(&self, account: RpcH160, account_pass: String, duration: Option<u64>) -> Result<bool, Error> {
|
||||||
try!(self.active());
|
try!(self.active());
|
||||||
from_params::<(RpcH160, String, Option<u64>)>(params).and_then(
|
|
||||||
|(account, account_pass, duration)| {
|
|
||||||
let account: Address = account.into();
|
let account: Address = account.into();
|
||||||
let store = take_weak!(self.accounts);
|
let store = take_weak!(self.accounts);
|
||||||
|
|
||||||
let r = match (self.allow_perm_unlock, duration) {
|
let r = match (self.allow_perm_unlock, duration) {
|
||||||
(false, _) => store.unlock_account_temporarily(account, account_pass),
|
(false, _) => store.unlock_account_temporarily(account, account_pass),
|
||||||
(true, Some(0)) => store.unlock_account_permanently(account, account_pass),
|
(true, Some(0)) => store.unlock_account_permanently(account, account_pass),
|
||||||
@ -121,43 +104,33 @@ impl<C: 'static, M: 'static> PersonalAccounts for PersonalAccountsClient<C, M> w
|
|||||||
(true, None) => store.unlock_account_timed(account, account_pass, 300_000),
|
(true, None) => store.unlock_account_timed(account, account_pass, 300_000),
|
||||||
};
|
};
|
||||||
match r {
|
match r {
|
||||||
Ok(_) => Ok(Value::Bool(true)),
|
Ok(_) => Ok(true),
|
||||||
Err(_) => Ok(Value::Bool(false)),
|
// TODO [ToDr] Proper error here?
|
||||||
|
Err(_) => Ok(false),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn test_password(&self, params: Params) -> Result<Value, Error> {
|
fn test_password(&self, account: RpcH160, password: String) -> Result<bool, Error> {
|
||||||
try!(self.active());
|
try!(self.active());
|
||||||
from_params::<(RpcH160, String)>(params).and_then(
|
|
||||||
|(account, password)| {
|
|
||||||
let account: Address = account.into();
|
let account: Address = account.into();
|
||||||
|
|
||||||
take_weak!(self.accounts)
|
take_weak!(self.accounts)
|
||||||
.test_password(&account, password)
|
.test_password(&account, password)
|
||||||
.map(|b| Value::Bool(b))
|
|
||||||
.map_err(|e| errors::account("Could not fetch account info.", e))
|
.map_err(|e| errors::account("Could not fetch account info.", e))
|
||||||
}
|
}
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn change_password(&self, params: Params) -> Result<Value, Error> {
|
fn change_password(&self, account: RpcH160, password: String, new_password: String) -> Result<bool, Error> {
|
||||||
try!(self.active());
|
try!(self.active());
|
||||||
from_params::<(RpcH160, String, String)>(params).and_then(
|
|
||||||
|(account, password, new_password)| {
|
|
||||||
let account: Address = account.into();
|
let account: Address = account.into();
|
||||||
take_weak!(self.accounts)
|
take_weak!(self.accounts)
|
||||||
.change_password(&account, password, new_password)
|
.change_password(&account, password, new_password)
|
||||||
.map(|_| Value::Null)
|
.map(|_| true)
|
||||||
.map_err(|e| errors::account("Could not fetch account info.", e))
|
.map_err(|e| errors::account("Could not fetch account info.", e))
|
||||||
}
|
}
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn sign_and_send_transaction(&self, params: Params) -> Result<Value, Error> {
|
fn sign_and_send_transaction(&self, request: TransactionRequest, password: String) -> Result<RpcH256, Error> {
|
||||||
try!(self.active());
|
try!(self.active());
|
||||||
from_params::<(TransactionRequest, String)>(params)
|
|
||||||
.and_then(|(request, password)| {
|
|
||||||
sign_and_dispatch(
|
sign_and_dispatch(
|
||||||
&*take_weak!(self.client),
|
&*take_weak!(self.client),
|
||||||
&*take_weak!(self.miner),
|
&*take_weak!(self.miner),
|
||||||
@ -165,43 +138,47 @@ impl<C: 'static, M: 'static> PersonalAccounts for PersonalAccountsClient<C, M> w
|
|||||||
request.into(),
|
request.into(),
|
||||||
Some(password)
|
Some(password)
|
||||||
)
|
)
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_account_name(&self, params: Params) -> Result<Value, Error> {
|
fn set_account_name(&self, addr: RpcH160, name: String) -> Result<bool, Error> {
|
||||||
try!(self.active());
|
try!(self.active());
|
||||||
let store = take_weak!(self.accounts);
|
let store = take_weak!(self.accounts);
|
||||||
from_params::<(RpcH160, String)>(params).and_then(|(addr, name)| {
|
|
||||||
let addr: Address = addr.into();
|
let addr: Address = addr.into();
|
||||||
store.set_account_name(addr.clone(), name.clone()).or_else(|_| store.set_address_name(addr, name)).expect("set_address_name always returns Ok; qed");
|
|
||||||
Ok(Value::Null)
|
store.set_account_name(addr.clone(), name.clone())
|
||||||
})
|
.or_else(|_| store.set_address_name(addr, name))
|
||||||
|
.expect("set_address_name always returns Ok; qed");
|
||||||
|
Ok(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_account_meta(&self, params: Params) -> Result<Value, Error> {
|
fn set_account_meta(&self, addr: RpcH160, meta: String) -> Result<bool, Error> {
|
||||||
try!(self.active());
|
try!(self.active());
|
||||||
let store = take_weak!(self.accounts);
|
let store = take_weak!(self.accounts);
|
||||||
from_params::<(RpcH160, String)>(params).and_then(|(addr, meta)| {
|
|
||||||
let addr: Address = addr.into();
|
let addr: Address = addr.into();
|
||||||
store.set_account_meta(addr.clone(), meta.clone()).or_else(|_| store.set_address_meta(addr, meta)).expect("set_address_meta always returns Ok; qed");
|
|
||||||
Ok(Value::Null)
|
store.set_account_meta(addr.clone(), meta.clone())
|
||||||
})
|
.or_else(|_| store.set_address_meta(addr, meta))
|
||||||
|
.expect("set_address_meta always returns Ok; qed");
|
||||||
|
Ok(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn import_geth_accounts(&self, params: Params) -> Result<Value, Error> {
|
fn import_geth_accounts(&self, addresses: Vec<RpcH160>) -> Result<Vec<RpcH160>, Error> {
|
||||||
from_params::<(Vec<RpcH160>,)>(params).and_then(|(addresses,)| {
|
|
||||||
let store = take_weak!(self.accounts);
|
let store = take_weak!(self.accounts);
|
||||||
Ok(to_value(&try!(store
|
|
||||||
|
store
|
||||||
.import_geth_accounts(addresses.into_iter().map(Into::into).collect(), false)
|
.import_geth_accounts(addresses.into_iter().map(Into::into).collect(), false)
|
||||||
|
.map(|imported| imported.into_iter().map(Into::into).collect())
|
||||||
.map_err(|e| errors::account("Couldn't import Geth accounts", e))
|
.map_err(|e| errors::account("Couldn't import Geth accounts", e))
|
||||||
).into_iter().map(Into::into).collect::<Vec<RpcH160>>()))
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn geth_accounts(&self, params: Params) -> Result<Value, Error> {
|
fn geth_accounts(&self) -> Result<Vec<RpcH160>, Error> {
|
||||||
try!(self.active());
|
try!(self.active());
|
||||||
try!(expect_no_params(params));
|
|
||||||
let store = take_weak!(self.accounts);
|
let store = take_weak!(self.accounts);
|
||||||
Ok(to_value(&store.list_geth_accounts(false).into_iter().map(Into::into).collect::<Vec<RpcH160>>()))
|
|
||||||
|
Ok(store.list_geth_accounts(false)
|
||||||
|
.into_iter()
|
||||||
|
.map(Into::into)
|
||||||
|
.collect()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,6 @@ use ethcore::miner::MinerService;
|
|||||||
use v1::traits::PersonalSigner;
|
use v1::traits::PersonalSigner;
|
||||||
use v1::types::{TransactionModification, ConfirmationRequest, U256};
|
use v1::types::{TransactionModification, ConfirmationRequest, U256};
|
||||||
use v1::helpers::{errors, SignerService, SigningQueue, ConfirmationPayload};
|
use v1::helpers::{errors, SignerService, SigningQueue, ConfirmationPayload};
|
||||||
use v1::helpers::params::expect_no_params;
|
|
||||||
use v1::helpers::dispatch::{sign_and_dispatch, sign, decrypt};
|
use v1::helpers::dispatch::{sign_and_dispatch, sign, decrypt};
|
||||||
|
|
||||||
/// Transactions confirmation (personal) rpc implementation.
|
/// Transactions confirmation (personal) rpc implementation.
|
||||||
@ -61,19 +60,22 @@ impl<C: 'static, M: 'static> SignerClient<C, M> where C: MiningBlockChainClient,
|
|||||||
|
|
||||||
impl<C: 'static, M: 'static> PersonalSigner for SignerClient<C, M> where C: MiningBlockChainClient, M: MinerService {
|
impl<C: 'static, M: 'static> PersonalSigner for SignerClient<C, M> where C: MiningBlockChainClient, M: MinerService {
|
||||||
|
|
||||||
fn requests_to_confirm(&self, params: Params) -> Result<Value, Error> {
|
fn requests_to_confirm(&self) -> Result<Vec<ConfirmationRequest>, Error> {
|
||||||
try!(self.active());
|
try!(self.active());
|
||||||
try!(expect_no_params(params));
|
|
||||||
let signer = take_weak!(self.signer);
|
let signer = take_weak!(self.signer);
|
||||||
Ok(to_value(&signer.requests().into_iter().map(From::from).collect::<Vec<ConfirmationRequest>>()))
|
|
||||||
|
Ok(signer.requests()
|
||||||
|
.into_iter()
|
||||||
|
.map(Into::into)
|
||||||
|
.collect()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn confirm_request(&self, params: Params) -> Result<Value, Error> {
|
|
||||||
try!(self.active());
|
|
||||||
// TODO [ToDr] TransactionModification is redundant for some calls
|
// TODO [ToDr] TransactionModification is redundant for some calls
|
||||||
// might be better to replace it in future
|
// might be better to replace it in future
|
||||||
from_params::<(U256, TransactionModification, String)>(params).and_then(
|
fn confirm_request(&self, id: U256, modification: TransactionModification, pass: String) -> Result<Value, Error> {
|
||||||
|(id, modification, pass)| {
|
try!(self.active());
|
||||||
|
|
||||||
let id = id.into();
|
let id = id.into();
|
||||||
let accounts = take_weak!(self.accounts);
|
let accounts = take_weak!(self.accounts);
|
||||||
let signer = take_weak!(self.signer);
|
let signer = take_weak!(self.signer);
|
||||||
@ -87,7 +89,7 @@ impl<C: 'static, M: 'static> PersonalSigner for SignerClient<C, M> where C: Mini
|
|||||||
if let Some(gas_price) = modification.gas_price {
|
if let Some(gas_price) = modification.gas_price {
|
||||||
request.gas_price = gas_price.into();
|
request.gas_price = gas_price.into();
|
||||||
}
|
}
|
||||||
sign_and_dispatch(&*client, &*miner, &*accounts, request.into(), Some(pass))
|
sign_and_dispatch(&*client, &*miner, &*accounts, request.into(), Some(pass)).map(to_value)
|
||||||
},
|
},
|
||||||
ConfirmationPayload::Sign(address, hash) => {
|
ConfirmationPayload::Sign(address, hash) => {
|
||||||
sign(&*accounts, address, Some(pass), hash)
|
sign(&*accounts, address, Some(pass), hash)
|
||||||
@ -102,26 +104,20 @@ impl<C: 'static, M: 'static> PersonalSigner for SignerClient<C, M> where C: Mini
|
|||||||
result
|
result
|
||||||
}).unwrap_or_else(|| Err(errors::invalid_params("Unknown RequestID", id)))
|
}).unwrap_or_else(|| Err(errors::invalid_params("Unknown RequestID", id)))
|
||||||
}
|
}
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn reject_request(&self, params: Params) -> Result<Value, Error> {
|
fn reject_request(&self, id: U256) -> Result<bool, Error> {
|
||||||
try!(self.active());
|
try!(self.active());
|
||||||
from_params::<(U256, )>(params).and_then(
|
|
||||||
|(id, )| {
|
|
||||||
let signer = take_weak!(self.signer);
|
let signer = take_weak!(self.signer);
|
||||||
|
|
||||||
let res = signer.request_rejected(id.into());
|
let res = signer.request_rejected(id.into());
|
||||||
Ok(to_value(&res.is_some()))
|
Ok(res.is_some())
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn generate_token(&self, params: Params) -> Result<Value, Error> {
|
fn generate_token(&self) -> Result<String, Error> {
|
||||||
try!(self.active());
|
try!(self.active());
|
||||||
try!(expect_no_params(params));
|
|
||||||
let signer = take_weak!(self.signer);
|
let signer = take_weak!(self.signer);
|
||||||
|
|
||||||
signer.generate_token()
|
signer.generate_token()
|
||||||
.map(|token| to_value(&token))
|
|
||||||
.map_err(|e| errors::token(e))
|
.map_err(|e| errors::token(e))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,6 @@ use jsonrpc_core::*;
|
|||||||
use util::version;
|
use util::version;
|
||||||
use v1::traits::Web3;
|
use v1::traits::Web3;
|
||||||
use v1::types::{H256, Bytes};
|
use v1::types::{H256, Bytes};
|
||||||
use v1::helpers::params::expect_no_params;
|
|
||||||
use util::sha3::Hashable;
|
use util::sha3::Hashable;
|
||||||
|
|
||||||
/// Web3 rpc implementation.
|
/// Web3 rpc implementation.
|
||||||
@ -31,18 +30,11 @@ impl Web3Client {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Web3 for Web3Client {
|
impl Web3 for Web3Client {
|
||||||
fn client_version(&self, params: Params) -> Result<Value, Error> {
|
fn client_version(&self) -> Result<String, Error> {
|
||||||
try!(expect_no_params(params));
|
Ok(version().to_owned().replace("Parity/", "Parity//"))
|
||||||
Ok(Value::String(version().to_owned().replace("Parity/", "Parity//")))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sha3(&self, params: Params) -> Result<Value, Error> {
|
fn sha3(&self, data: Bytes) -> Result<H256, Error> {
|
||||||
from_params::<(Bytes,)>(params).map(
|
Ok(data.0.sha3().into())
|
||||||
|(data,)| {
|
|
||||||
let Bytes(ref vec) = data;
|
|
||||||
let sha3 = vec.sha3();
|
|
||||||
to_value(&H256::from(sha3))
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -119,7 +119,7 @@ fn should_be_able_to_set_name() {
|
|||||||
let address = accounts[0];
|
let address = accounts[0];
|
||||||
|
|
||||||
let request = format!(r#"{{"jsonrpc": "2.0", "method": "personal_setAccountName", "params": ["0x{}", "Test"], "id": 1}}"#, address.hex());
|
let request = format!(r#"{{"jsonrpc": "2.0", "method": "personal_setAccountName", "params": ["0x{}", "Test"], "id": 1}}"#, address.hex());
|
||||||
let response = r#"{"jsonrpc":"2.0","result":null,"id":1}"#;
|
let response = r#"{"jsonrpc":"2.0","result":true,"id":1}"#;
|
||||||
let res = tester.io.handle_request_sync(&request);
|
let res = tester.io.handle_request_sync(&request);
|
||||||
assert_eq!(res, Some(response.into()));
|
assert_eq!(res, Some(response.into()));
|
||||||
|
|
||||||
@ -140,7 +140,7 @@ fn should_be_able_to_set_meta() {
|
|||||||
let address = accounts[0];
|
let address = accounts[0];
|
||||||
|
|
||||||
let request = format!(r#"{{"jsonrpc": "2.0", "method": "personal_setAccountMeta", "params": ["0x{}", "{{foo: 69}}"], "id": 1}}"#, address.hex());
|
let request = format!(r#"{{"jsonrpc": "2.0", "method": "personal_setAccountMeta", "params": ["0x{}", "{{foo: 69}}"], "id": 1}}"#, address.hex());
|
||||||
let response = r#"{"jsonrpc":"2.0","result":null,"id":1}"#;
|
let response = r#"{"jsonrpc":"2.0","result":true,"id":1}"#;
|
||||||
let res = tester.io.handle_request_sync(&request);
|
let res = tester.io.handle_request_sync(&request);
|
||||||
assert_eq!(res, Some(response.into()));
|
assert_eq!(res, Some(response.into()));
|
||||||
|
|
||||||
|
@ -15,117 +15,104 @@
|
|||||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
//! Personal rpc interface.
|
//! Personal rpc interface.
|
||||||
use std::sync::Arc;
|
use std::collections::BTreeMap;
|
||||||
use jsonrpc_core::*;
|
use jsonrpc_core::{Value, Error};
|
||||||
|
|
||||||
|
use v1::helpers::auto_args::Wrap;
|
||||||
|
use v1::types::{H160, H256, U256, TransactionRequest, TransactionModification, ConfirmationRequest};
|
||||||
|
|
||||||
|
build_rpc_trait! {
|
||||||
/// Personal rpc interface. Safe (read-only) functions.
|
/// Personal rpc interface. Safe (read-only) functions.
|
||||||
pub trait Personal: Sized + Send + Sync + 'static {
|
pub trait Personal {
|
||||||
|
|
||||||
/// Lists all stored accounts
|
/// Lists all stored accounts
|
||||||
fn accounts(&self, _: Params) -> Result<Value, Error>;
|
#[rpc(name = "personal_listAccounts")]
|
||||||
|
fn accounts(&self) -> Result<Vec<H160>, Error>;
|
||||||
|
|
||||||
/// Returns accounts information.
|
/// Returns accounts information.
|
||||||
fn accounts_info(&self, _: Params) -> Result<Value, Error>;
|
#[rpc(name = "personal_accountsInfo")]
|
||||||
|
fn accounts_info(&self) -> Result<BTreeMap<String, 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));
|
|
||||||
delegate.add_method("personal_listAccounts", Personal::accounts);
|
|
||||||
delegate.add_method("personal_accountsInfo", Personal::accounts_info);
|
|
||||||
|
|
||||||
delegate
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
build_rpc_trait! {
|
||||||
/// Personal rpc methods altering stored accounts or their settings.
|
/// Personal rpc methods altering stored accounts or their settings.
|
||||||
pub trait PersonalAccounts: Sized + Send + Sync + 'static {
|
pub trait PersonalAccounts {
|
||||||
|
|
||||||
/// Creates new account (it becomes new current unlocked account)
|
/// Creates new account (it becomes new current unlocked account)
|
||||||
/// Param is the password for the account.
|
/// Param is the password for the account.
|
||||||
fn new_account(&self, _: Params) -> Result<Value, Error>;
|
#[rpc(name = "personal_newAccount")]
|
||||||
|
fn new_account(&self, String) -> Result<H160, Error>;
|
||||||
|
|
||||||
/// Creates new account from the given phrase using standard brainwallet mechanism.
|
/// Creates new account from the given phrase using standard brainwallet mechanism.
|
||||||
/// Second parameter is password for the new account.
|
/// Second parameter is password for the new account.
|
||||||
fn new_account_from_phrase(&self, _: Params) -> Result<Value, Error>;
|
#[rpc(name = "personal_newAccountFromPhrase")]
|
||||||
|
fn new_account_from_phrase(&self, String, String) -> Result<H160, Error>;
|
||||||
|
|
||||||
/// Creates new account from the given JSON wallet.
|
/// Creates new account from the given JSON wallet.
|
||||||
/// Second parameter is password for the wallet and the new account.
|
/// Second parameter is password for the wallet and the new account.
|
||||||
fn new_account_from_wallet(&self, params: Params) -> Result<Value, Error>;
|
#[rpc(name = "personal_newAccountFromWallet")]
|
||||||
|
fn new_account_from_wallet(&self, String, String) -> Result<H160, Error>;
|
||||||
|
|
||||||
/// Creates new account from the given raw secret.
|
/// Creates new account from the given raw secret.
|
||||||
/// Second parameter is password for the new account.
|
/// Second parameter is password for the new account.
|
||||||
fn new_account_from_secret(&self, params: Params) -> Result<Value, Error>;
|
#[rpc(name = "personal_newAccountFromSecret")]
|
||||||
|
fn new_account_from_secret(&self, H256, String) -> Result<H160, Error>;
|
||||||
|
|
||||||
/// Unlocks specified account for use (can only be one unlocked account at one moment)
|
/// Unlocks specified account for use (can only be one unlocked account at one moment)
|
||||||
fn unlock_account(&self, _: Params) -> Result<Value, Error>;
|
#[rpc(name = "personal_unlockAccount")]
|
||||||
|
fn unlock_account(&self, H160, String, Option<u64>) -> Result<bool, Error>;
|
||||||
|
|
||||||
/// Returns true if given `password` would unlock given `account`.
|
/// Returns true if given `password` would unlock given `account`.
|
||||||
/// Arguments: `account`, `password`.
|
/// Arguments: `account`, `password`.
|
||||||
fn test_password(&self, _: Params) -> Result<Value, Error>;
|
#[rpc(name = "personal_testPassword")]
|
||||||
|
fn test_password(&self, H160, String) -> Result<bool, Error>;
|
||||||
|
|
||||||
/// Changes an account's password.
|
/// Changes an account's password.
|
||||||
/// Arguments: `account`, `password`, `new_password`.
|
/// Arguments: `account`, `password`, `new_password`.
|
||||||
fn change_password(&self, _: Params) -> Result<Value, Error>;
|
#[rpc(name = "personal_changePassword")]
|
||||||
|
fn change_password(&self, H160, String, String) -> Result<bool, Error>;
|
||||||
|
|
||||||
/// Sends transaction and signs it in single call. The account is not unlocked in such case.
|
/// Sends transaction and signs it in single call. The account is not unlocked in such case.
|
||||||
fn sign_and_send_transaction(&self, _: Params) -> Result<Value, Error>;
|
#[rpc(name = "personal_signAndSendTransaction")]
|
||||||
|
fn sign_and_send_transaction(&self, TransactionRequest, String) -> Result<H256, Error>;
|
||||||
|
|
||||||
/// Set an account's name.
|
/// Set an account's name.
|
||||||
fn set_account_name(&self, _: Params) -> Result<Value, Error>;
|
#[rpc(name = "personal_setAccountName")]
|
||||||
|
fn set_account_name(&self, H160, String) -> Result<bool, Error>;
|
||||||
|
|
||||||
/// Set an account's metadata string.
|
/// Set an account's metadata string.
|
||||||
fn set_account_meta(&self, _: Params) -> Result<Value, Error>;
|
#[rpc(name = "personal_setAccountMeta")]
|
||||||
|
fn set_account_meta(&self, H160, String) -> Result<bool, Error>;
|
||||||
|
|
||||||
/// Imports a number of Geth accounts, with the list provided as the argument.
|
/// Imports a number of Geth accounts, with the list provided as the argument.
|
||||||
fn import_geth_accounts(&self, _: Params) -> Result<Value, Error>;
|
#[rpc(name = "personal_importGethAccounts")]
|
||||||
|
fn import_geth_accounts(&self, Vec<H160>) -> Result<Vec<H160>, Error>;
|
||||||
|
|
||||||
/// Returns the accounts available for importing from Geth.
|
/// Returns the accounts available for importing from Geth.
|
||||||
fn geth_accounts(&self, _: Params) -> Result<Value, Error>;
|
#[rpc(name = "personal_listGethAccounts")]
|
||||||
|
fn geth_accounts(&self) -> Result<Vec<H160>, Error>;
|
||||||
/// Should be used to convert object to io delegate.
|
|
||||||
fn to_delegate(self) -> IoDelegate<Self> {
|
|
||||||
let mut delegate = IoDelegate::new(Arc::new(self));
|
|
||||||
delegate.add_method("personal_newAccount", PersonalAccounts::new_account);
|
|
||||||
delegate.add_method("personal_newAccountFromPhrase", PersonalAccounts::new_account_from_phrase);
|
|
||||||
delegate.add_method("personal_newAccountFromWallet", PersonalAccounts::new_account_from_wallet);
|
|
||||||
delegate.add_method("personal_newAccountFromSecret", PersonalAccounts::new_account_from_secret);
|
|
||||||
delegate.add_method("personal_unlockAccount", PersonalAccounts::unlock_account);
|
|
||||||
delegate.add_method("personal_testPassword", PersonalAccounts::test_password);
|
|
||||||
delegate.add_method("personal_changePassword", PersonalAccounts::change_password);
|
|
||||||
delegate.add_method("personal_signAndSendTransaction", PersonalAccounts::sign_and_send_transaction);
|
|
||||||
delegate.add_method("personal_setAccountName", PersonalAccounts::set_account_name);
|
|
||||||
delegate.add_method("personal_setAccountMeta", PersonalAccounts::set_account_meta);
|
|
||||||
delegate.add_method("personal_importGethAccounts", PersonalAccounts::import_geth_accounts);
|
|
||||||
delegate.add_method("personal_listGethAccounts", PersonalAccounts::geth_accounts);
|
|
||||||
|
|
||||||
delegate
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
build_rpc_trait! {
|
||||||
/// Personal extension for confirmations rpc interface.
|
/// Personal extension for confirmations rpc interface.
|
||||||
pub trait PersonalSigner: Sized + Send + Sync + 'static {
|
pub trait PersonalSigner {
|
||||||
|
|
||||||
/// Returns a list of items to confirm.
|
/// Returns a list of items to confirm.
|
||||||
fn requests_to_confirm(&self, _: Params) -> Result<Value, Error>;
|
#[rpc(name = "personal_requestsToConfirm")]
|
||||||
|
fn requests_to_confirm(&self) -> Result<Vec<ConfirmationRequest>, Error>;
|
||||||
|
|
||||||
/// Confirm specific request.
|
/// Confirm specific request.
|
||||||
fn confirm_request(&self, _: Params) -> Result<Value, Error>;
|
#[rpc(name = "personal_confirmRequest")]
|
||||||
|
fn confirm_request(&self, U256, TransactionModification, String) -> Result<Value, Error>;
|
||||||
|
|
||||||
/// Reject the confirmation request.
|
/// Reject the confirmation request.
|
||||||
fn reject_request(&self, _: Params) -> Result<Value, Error>;
|
#[rpc(name = "personal_rejectRequest")]
|
||||||
|
fn reject_request(&self, U256) -> Result<bool, Error>;
|
||||||
|
|
||||||
/// Generates new authorization token.
|
/// Generates new authorization token.
|
||||||
fn generate_token(&self, _: Params) -> Result<Value, Error>;
|
#[rpc(name = "personal_generateAuthorizationToken")]
|
||||||
|
fn generate_token(&self) -> Result<String, Error>;
|
||||||
/// Should be used to convert object to io delegate.
|
|
||||||
fn to_delegate(self) -> IoDelegate<Self> {
|
|
||||||
let mut delegate = IoDelegate::new(Arc::new(self));
|
|
||||||
delegate.add_method("personal_requestsToConfirm", PersonalSigner::requests_to_confirm);
|
|
||||||
delegate.add_method("personal_confirmRequest", PersonalSigner::confirm_request);
|
|
||||||
delegate.add_method("personal_rejectRequest", PersonalSigner::reject_request);
|
|
||||||
delegate.add_method("personal_generateAuthorizationToken", PersonalSigner::generate_token);
|
|
||||||
|
|
||||||
delegate
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,22 +15,21 @@
|
|||||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
//! Web3 rpc interface.
|
//! Web3 rpc interface.
|
||||||
use std::sync::Arc;
|
use jsonrpc_core::Error;
|
||||||
use jsonrpc_core::*;
|
|
||||||
|
|
||||||
|
use v1::helpers::auto_args::Wrap;
|
||||||
|
use v1::types::{H256, Bytes};
|
||||||
|
|
||||||
|
|
||||||
|
build_rpc_trait! {
|
||||||
/// Web3 rpc interface.
|
/// Web3 rpc interface.
|
||||||
pub trait Web3: Sized + Send + Sync + 'static {
|
pub trait Web3 {
|
||||||
/// Returns current client version.
|
/// Returns current client version.
|
||||||
fn client_version(&self, _: Params) -> Result<Value, Error>;
|
#[rpc(name = "web3_clientVersion")]
|
||||||
|
fn client_version(&self) -> Result<String, Error>;
|
||||||
|
|
||||||
/// Returns sha3 of the given data
|
/// Returns sha3 of the given data
|
||||||
fn sha3(&self, _: Params) -> Result<Value, Error>;
|
#[rpc(name = "web3_sha3")]
|
||||||
|
fn sha3(&self, Bytes) -> Result<H256, Error>;
|
||||||
/// Should be used to convert object to io delegate.
|
|
||||||
fn to_delegate(self) -> IoDelegate<Self> {
|
|
||||||
let mut delegate = IoDelegate::new(Arc::new(self));
|
|
||||||
delegate.add_method("web3_clientVersion", Web3::client_version);
|
|
||||||
delegate.add_method("web3_sha3", Web3::sha3);
|
|
||||||
delegate
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user