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)
|
||||
}
|
||||
|
||||
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 {
|
||||
|
||||
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());
|
||||
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 {
|
||||
|
@ -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));
|
||||
self.add_to_queue(
|
||||
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);
|
||||
ConfirmationPayload::Transaction(request)
|
||||
@ -251,7 +251,7 @@ impl<C, M> EthSigning for EthSigningUnsafeClient<C, M> where
|
||||
ready.ready(self.active()
|
||||
.and_then(|_| from_params::<(TransactionRequest, )>(params))
|
||||
.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::types::{H160 as RpcH160};
|
||||
use v1::helpers::errors;
|
||||
use v1::helpers::params::expect_no_params;
|
||||
use ethcore::account_provider::AccountProvider;
|
||||
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 {
|
||||
|
||||
fn accounts(&self, params: Params) -> Result<Value, Error> {
|
||||
fn accounts(&self) -> Result<Vec<RpcH160>, Error> {
|
||||
try!(self.active());
|
||||
try!(expect_no_params(params));
|
||||
|
||||
let store = take_weak!(self.accounts);
|
||||
let accounts = try!(store.accounts().map_err(|e| errors::internal("Could not fetch accounts.", e)));
|
||||
Ok(to_value(&accounts.into_iter().map(Into::into).collect::<Vec<RpcH160>>()))
|
||||
let accounts = try!(store.accounts().map_err(|e| errors::account("Could not fetch accounts.", e)));
|
||||
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!(expect_no_params(params));
|
||||
let store = take_weak!(self.accounts);
|
||||
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");
|
||||
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![
|
||||
"name".to_owned() => to_value(&v.name),
|
||||
"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))
|
||||
}).collect::<BTreeMap<_, _>>()))
|
||||
}).collect())
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,6 @@ use ethkey::{Brain, Generator};
|
||||
use v1::traits::PersonalAccounts;
|
||||
use v1::types::{H160 as RpcH160, H256 as RpcH256, TransactionRequest};
|
||||
use v1::helpers::errors;
|
||||
use v1::helpers::params::expect_no_params;
|
||||
use v1::helpers::dispatch::sign_and_dispatch;
|
||||
use ethcore::account_provider::AccountProvider;
|
||||
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 {
|
||||
|
||||
fn new_account(&self, params: Params) -> Result<Value, Error> {
|
||||
fn new_account(&self, pass: String) -> Result<RpcH160, Error> {
|
||||
try!(self.active());
|
||||
from_params::<(String, )>(params).and_then(
|
||||
|(pass, )| {
|
||||
let store = take_weak!(self.accounts);
|
||||
match store.new_account(&pass) {
|
||||
Ok(address) => Ok(to_value(&RpcH160::from(address))),
|
||||
Err(e) => Err(errors::account("Could not create account.", e)),
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
store.new_account(&pass)
|
||||
.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());
|
||||
from_params::<(String, String, )>(params).and_then(
|
||||
|(phrase, pass, )| {
|
||||
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))),
|
||||
Err(e) => Err(errors::account("Could not create account.", e)),
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
store.insert_account(*Brain::new(phrase).generate().unwrap().secret(), &pass)
|
||||
.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());
|
||||
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) => Ok(to_value(&RpcH160::from(address))),
|
||||
Err(e) => Err(errors::account("Could not create account.", e)),
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
store.import_presale(json.as_bytes(), &pass)
|
||||
.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());
|
||||
from_params::<(RpcH256, String, )>(params).and_then(
|
||||
|(secret, pass, )| {
|
||||
let store = take_weak!(self.accounts);
|
||||
match store.insert_account(secret.into(), &pass) {
|
||||
Ok(address) => Ok(to_value(&RpcH160::from(address))),
|
||||
Err(e) => Err(errors::account("Could not create account.", e)),
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
store.insert_account(secret.into(), &pass)
|
||||
.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());
|
||||
from_params::<(RpcH160, String, Option<u64>)>(params).and_then(
|
||||
|(account, account_pass, duration)| {
|
||||
let account: Address = account.into();
|
||||
let store = take_weak!(self.accounts);
|
||||
|
||||
let r = match (self.allow_perm_unlock, duration) {
|
||||
(false, _) => store.unlock_account_temporarily(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),
|
||||
};
|
||||
match r {
|
||||
Ok(_) => Ok(Value::Bool(true)),
|
||||
Err(_) => Ok(Value::Bool(false)),
|
||||
Ok(_) => Ok(true),
|
||||
// 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());
|
||||
from_params::<(RpcH160, String)>(params).and_then(
|
||||
|(account, password)| {
|
||||
let account: Address = account.into();
|
||||
|
||||
take_weak!(self.accounts)
|
||||
.test_password(&account, password)
|
||||
.map(|b| Value::Bool(b))
|
||||
.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());
|
||||
from_params::<(RpcH160, String, String)>(params).and_then(
|
||||
|(account, password, new_password)| {
|
||||
let account: Address = account.into();
|
||||
take_weak!(self.accounts)
|
||||
.change_password(&account, password, new_password)
|
||||
.map(|_| Value::Null)
|
||||
.map(|_| true)
|
||||
.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());
|
||||
from_params::<(TransactionRequest, String)>(params)
|
||||
.and_then(|(request, password)| {
|
||||
|
||||
sign_and_dispatch(
|
||||
&*take_weak!(self.client),
|
||||
&*take_weak!(self.miner),
|
||||
@ -165,43 +138,47 @@ impl<C: 'static, M: 'static> PersonalAccounts for PersonalAccountsClient<C, M> w
|
||||
request.into(),
|
||||
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());
|
||||
let store = take_weak!(self.accounts);
|
||||
from_params::<(RpcH160, String)>(params).and_then(|(addr, name)| {
|
||||
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());
|
||||
let store = take_weak!(self.accounts);
|
||||
from_params::<(RpcH160, String)>(params).and_then(|(addr, meta)| {
|
||||
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> {
|
||||
from_params::<(Vec<RpcH160>,)>(params).and_then(|(addresses,)| {
|
||||
fn import_geth_accounts(&self, addresses: Vec<RpcH160>) -> Result<Vec<RpcH160>, Error> {
|
||||
let store = take_weak!(self.accounts);
|
||||
Ok(to_value(&try!(store
|
||||
|
||||
store
|
||||
.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))
|
||||
).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!(expect_no_params(params));
|
||||
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::types::{TransactionModification, ConfirmationRequest, U256};
|
||||
use v1::helpers::{errors, SignerService, SigningQueue, ConfirmationPayload};
|
||||
use v1::helpers::params::expect_no_params;
|
||||
use v1::helpers::dispatch::{sign_and_dispatch, sign, decrypt};
|
||||
|
||||
/// 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 {
|
||||
|
||||
fn requests_to_confirm(&self, params: Params) -> Result<Value, Error> {
|
||||
fn requests_to_confirm(&self) -> Result<Vec<ConfirmationRequest>, Error> {
|
||||
try!(self.active());
|
||||
try!(expect_no_params(params));
|
||||
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
|
||||
// might be better to replace it in future
|
||||
from_params::<(U256, TransactionModification, String)>(params).and_then(
|
||||
|(id, modification, pass)| {
|
||||
fn confirm_request(&self, id: U256, modification: TransactionModification, pass: String) -> Result<Value, Error> {
|
||||
try!(self.active());
|
||||
|
||||
let id = id.into();
|
||||
let accounts = take_weak!(self.accounts);
|
||||
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 {
|
||||
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) => {
|
||||
sign(&*accounts, address, Some(pass), hash)
|
||||
@ -102,26 +104,20 @@ impl<C: 'static, M: 'static> PersonalSigner for SignerClient<C, M> where C: Mini
|
||||
result
|
||||
}).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());
|
||||
from_params::<(U256, )>(params).and_then(
|
||||
|(id, )| {
|
||||
let signer = take_weak!(self.signer);
|
||||
|
||||
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!(expect_no_params(params));
|
||||
let signer = take_weak!(self.signer);
|
||||
|
||||
signer.generate_token()
|
||||
.map(|token| to_value(&token))
|
||||
.map_err(|e| errors::token(e))
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,6 @@ use jsonrpc_core::*;
|
||||
use util::version;
|
||||
use v1::traits::Web3;
|
||||
use v1::types::{H256, Bytes};
|
||||
use v1::helpers::params::expect_no_params;
|
||||
use util::sha3::Hashable;
|
||||
|
||||
/// Web3 rpc implementation.
|
||||
@ -31,18 +30,11 @@ impl Web3Client {
|
||||
}
|
||||
|
||||
impl Web3 for Web3Client {
|
||||
fn client_version(&self, params: Params) -> Result<Value, Error> {
|
||||
try!(expect_no_params(params));
|
||||
Ok(Value::String(version().to_owned().replace("Parity/", "Parity//")))
|
||||
fn client_version(&self) -> Result<String, Error> {
|
||||
Ok(version().to_owned().replace("Parity/", "Parity//"))
|
||||
}
|
||||
|
||||
fn sha3(&self, params: Params) -> Result<Value, Error> {
|
||||
from_params::<(Bytes,)>(params).map(
|
||||
|(data,)| {
|
||||
let Bytes(ref vec) = data;
|
||||
let sha3 = vec.sha3();
|
||||
to_value(&H256::from(sha3))
|
||||
}
|
||||
)
|
||||
fn sha3(&self, data: Bytes) -> Result<H256, Error> {
|
||||
Ok(data.0.sha3().into())
|
||||
}
|
||||
}
|
||||
|
@ -119,7 +119,7 @@ fn should_be_able_to_set_name() {
|
||||
let address = accounts[0];
|
||||
|
||||
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);
|
||||
assert_eq!(res, Some(response.into()));
|
||||
|
||||
@ -140,7 +140,7 @@ fn should_be_able_to_set_meta() {
|
||||
let address = accounts[0];
|
||||
|
||||
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);
|
||||
assert_eq!(res, Some(response.into()));
|
||||
|
||||
|
@ -15,117 +15,104 @@
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Personal rpc interface.
|
||||
use std::sync::Arc;
|
||||
use jsonrpc_core::*;
|
||||
use std::collections::BTreeMap;
|
||||
use jsonrpc_core::{Value, Error};
|
||||
|
||||
/// Personal rpc interface. Safe (read-only) functions.
|
||||
pub trait Personal: Sized + Send + Sync + 'static {
|
||||
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.
|
||||
pub trait Personal {
|
||||
/// 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.
|
||||
fn accounts_info(&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));
|
||||
delegate.add_method("personal_listAccounts", Personal::accounts);
|
||||
delegate.add_method("personal_accountsInfo", Personal::accounts_info);
|
||||
|
||||
delegate
|
||||
#[rpc(name = "personal_accountsInfo")]
|
||||
fn accounts_info(&self) -> Result<BTreeMap<String, Value>, Error>;
|
||||
}
|
||||
}
|
||||
|
||||
/// Personal rpc methods altering stored accounts or their settings.
|
||||
pub trait PersonalAccounts: Sized + Send + Sync + 'static {
|
||||
build_rpc_trait! {
|
||||
/// Personal rpc methods altering stored accounts or their settings.
|
||||
pub trait PersonalAccounts {
|
||||
|
||||
/// Creates new account (it becomes new current unlocked 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.
|
||||
/// 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.
|
||||
/// 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.
|
||||
/// 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)
|
||||
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`.
|
||||
/// 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.
|
||||
/// 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.
|
||||
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.
|
||||
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.
|
||||
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.
|
||||
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.
|
||||
fn geth_accounts(&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));
|
||||
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
|
||||
#[rpc(name = "personal_listGethAccounts")]
|
||||
fn geth_accounts(&self) -> Result<Vec<H160>, Error>;
|
||||
}
|
||||
}
|
||||
|
||||
/// Personal extension for confirmations rpc interface.
|
||||
pub trait PersonalSigner: Sized + Send + Sync + 'static {
|
||||
build_rpc_trait! {
|
||||
/// Personal extension for confirmations rpc interface.
|
||||
pub trait PersonalSigner {
|
||||
|
||||
/// 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.
|
||||
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.
|
||||
fn reject_request(&self, _: Params) -> Result<Value, Error>;
|
||||
#[rpc(name = "personal_rejectRequest")]
|
||||
fn reject_request(&self, U256) -> Result<bool, Error>;
|
||||
|
||||
/// Generates new authorization token.
|
||||
fn generate_token(&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));
|
||||
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
|
||||
#[rpc(name = "personal_generateAuthorizationToken")]
|
||||
fn generate_token(&self) -> Result<String, Error>;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15,22 +15,21 @@
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Web3 rpc interface.
|
||||
use std::sync::Arc;
|
||||
use jsonrpc_core::*;
|
||||
use jsonrpc_core::Error;
|
||||
|
||||
/// Web3 rpc interface.
|
||||
pub trait Web3: Sized + Send + Sync + 'static {
|
||||
use v1::helpers::auto_args::Wrap;
|
||||
use v1::types::{H256, Bytes};
|
||||
|
||||
|
||||
build_rpc_trait! {
|
||||
/// Web3 rpc interface.
|
||||
pub trait Web3 {
|
||||
/// 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
|
||||
fn sha3(&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));
|
||||
delegate.add_method("web3_clientVersion", Web3::client_version);
|
||||
delegate.add_method("web3_sha3", Web3::sha3);
|
||||
delegate
|
||||
#[rpc(name = "web3_sha3")]
|
||||
fn sha3(&self, Bytes) -> Result<H256, Error>;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user