diff --git a/rpc/src/v1/helpers/dispatch.rs b/rpc/src/v1/helpers/dispatch.rs index eb206713d..1944d9035 100644 --- a/rpc/src/v1/helpers/dispatch.rs +++ b/rpc/src/v1/helpers/dispatch.rs @@ -60,7 +60,7 @@ pub fn decrypt(accounts: &AccountProvider, address: Address, password: Option(client: &C, miner: &M, accounts: &AccountProvider, request: TransactionRequest, password: Option) -> Result +pub fn sign_and_dispatch(client: &C, miner: &M, accounts: &AccountProvider, request: TransactionRequest, password: Option) -> Result where C: MiningBlockChainClient, M: MinerService { let address = request.from; @@ -72,7 +72,7 @@ pub fn sign_and_dispatch(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(client: &C, miner: &M, request: TransactionRequest) -> Transaction where C: MiningBlockChainClient, M: MinerService { diff --git a/rpc/src/v1/impls/eth_signing.rs b/rpc/src/v1/impls/eth_signing.rs index e8b81d0c8..dd71af6a5 100644 --- a/rpc/src/v1/impls/eth_signing.rs +++ b/rpc/src/v1/impls/eth_signing.rs @@ -122,7 +122,7 @@ impl EthSigningQueueClient 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 EthSigning for EthSigningUnsafeClient 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) })) } diff --git a/rpc/src/v1/impls/personal.rs b/rpc/src/v1/impls/personal.rs index aacf90c91..bace56db1 100644 --- a/rpc/src/v1/impls/personal.rs +++ b/rpc/src/v1/impls/personal.rs @@ -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 PersonalClient where C: MiningBlockChainClient { impl Personal for PersonalClient where C: MiningBlockChainClient { - fn accounts(&self, params: Params) -> Result { + fn accounts(&self) -> Result, 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::>())) + let accounts = try!(store.accounts().map_err(|e| errors::account("Could not fetch accounts.", e))); + Ok(accounts.into_iter().map(Into::into).collect::>()) } - fn accounts_info(&self, params: Params) -> Result { + fn accounts_info(&self) -> Result, 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 Personal for PersonalClient where C: MiningBlockChainClient } ]; (format!("0x{}", a.hex()), Value::Object(m)) - }).collect::>())) + }).collect()) } } diff --git a/rpc/src/v1/impls/personal_accounts.rs b/rpc/src/v1/impls/personal_accounts.rs index 6e777f537..56c92fc64 100644 --- a/rpc/src/v1/impls/personal_accounts.rs +++ b/rpc/src/v1/impls/personal_accounts.rs @@ -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,152 +55,130 @@ impl PersonalAccountsClient where C: MiningBlockChainClient, M: Mine impl PersonalAccounts for PersonalAccountsClient where C: MiningBlockChainClient, M: MinerService { - fn new_account(&self, params: Params) -> Result { - 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)), - } - } - ) - } - - fn new_account_from_phrase(&self, params: Params) -> Result { - 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)), - } - } - ) - } - - fn new_account_from_wallet(&self, params: Params) -> Result { - 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)), - } - } - ) - } - - fn new_account_from_secret(&self, params: Params) -> Result { - 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)), - } - } - ) - } - - fn unlock_account(&self, params: Params) -> Result { - try!(self.active()); - from_params::<(RpcH160, String, Option)>(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), - (true, Some(d)) => store.unlock_account_timed(account, account_pass, d as u32 * 1000), - (true, None) => store.unlock_account_timed(account, account_pass, 300_000), - }; - match r { - Ok(_) => Ok(Value::Bool(true)), - Err(_) => Ok(Value::Bool(false)), - } - } - ) - } - - fn test_password(&self, params: Params) -> Result { - 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 { - 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_err(|e| errors::account("Could not fetch account info.", e)) - } - ) - } - - fn sign_and_send_transaction(&self, params: Params) -> Result { - try!(self.active()); - from_params::<(TransactionRequest, String)>(params) - .and_then(|(request, password)| { - sign_and_dispatch( - &*take_weak!(self.client), - &*take_weak!(self.miner), - &*take_weak!(self.accounts), - request.into(), - Some(password) - ) - }) - } - - fn set_account_name(&self, params: Params) -> Result { + fn new_account(&self, pass: String) -> Result { 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.new_account(&pass) + .map(Into::into) + .map_err(|e| errors::account("Could not create account.", e)) } - fn set_account_meta(&self, params: Params) -> Result { + fn new_account_from_phrase(&self, phrase: String, pass: String) -> Result { 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.insert_account(*Brain::new(phrase).generate().unwrap().secret(), &pass) + .map(Into::into) + .map_err(|e| errors::account("Could not create account.", e)) } - fn import_geth_accounts(&self, params: Params) -> Result { - from_params::<(Vec,)>(params).and_then(|(addresses,)| { - let store = take_weak!(self.accounts); - Ok(to_value(&try!(store - .import_geth_accounts(addresses.into_iter().map(Into::into).collect(), false) - .map_err(|e| errors::account("Couldn't import Geth accounts", e)) - ).into_iter().map(Into::into).collect::>())) - }) - } - - fn geth_accounts(&self, params: Params) -> Result { + fn new_account_from_wallet(&self, json: String, pass: String) -> Result { 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::>())) + + 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, secret: RpcH256, pass: String) -> Result { + try!(self.active()); + let store = take_weak!(self.accounts); + + store.insert_account(secret.into(), &pass) + .map(Into::into) + .map_err(|e| errors::account("Could not create account.", e)) + } + + fn unlock_account(&self, account: RpcH160, account_pass: String, duration: Option) -> Result { + try!(self.active()); + 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), + (true, Some(d)) => store.unlock_account_timed(account, account_pass, d as u32 * 1000), + (true, None) => store.unlock_account_timed(account, account_pass, 300_000), + }; + match r { + Ok(_) => Ok(true), + // TODO [ToDr] Proper error here? + Err(_) => Ok(false), + } + } + + fn test_password(&self, account: RpcH160, password: String) -> Result { + try!(self.active()); + let account: Address = account.into(); + + take_weak!(self.accounts) + .test_password(&account, password) + .map_err(|e| errors::account("Could not fetch account info.", e)) + } + + fn change_password(&self, account: RpcH160, password: String, new_password: String) -> Result { + try!(self.active()); + let account: Address = account.into(); + take_weak!(self.accounts) + .change_password(&account, password, new_password) + .map(|_| true) + .map_err(|e| errors::account("Could not fetch account info.", e)) + } + + fn sign_and_send_transaction(&self, request: TransactionRequest, password: String) -> Result { + try!(self.active()); + + sign_and_dispatch( + &*take_weak!(self.client), + &*take_weak!(self.miner), + &*take_weak!(self.accounts), + request.into(), + Some(password) + ) + } + + fn set_account_name(&self, addr: RpcH160, name: String) -> Result { + try!(self.active()); + let store = take_weak!(self.accounts); + 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(true) + } + + fn set_account_meta(&self, addr: RpcH160, meta: String) -> Result { + try!(self.active()); + let store = take_weak!(self.accounts); + 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(true) + } + + fn import_geth_accounts(&self, addresses: Vec) -> Result, Error> { + let store = take_weak!(self.accounts); + + 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)) + } + + fn geth_accounts(&self) -> Result, Error> { + try!(self.active()); + let store = take_weak!(self.accounts); + + Ok(store.list_geth_accounts(false) + .into_iter() + .map(Into::into) + .collect() + ) } } diff --git a/rpc/src/v1/impls/personal_signer.rs b/rpc/src/v1/impls/personal_signer.rs index b3a93736a..95db21e9f 100644 --- a/rpc/src/v1/impls/personal_signer.rs +++ b/rpc/src/v1/impls/personal_signer.rs @@ -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,67 +60,64 @@ impl SignerClient where C: MiningBlockChainClient, impl PersonalSigner for SignerClient where C: MiningBlockChainClient, M: MinerService { - fn requests_to_confirm(&self, params: Params) -> Result { + fn requests_to_confirm(&self) -> Result, 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::>())) + + Ok(signer.requests() + .into_iter() + .map(Into::into) + .collect() + ) } - fn confirm_request(&self, params: Params) -> Result { + // TODO [ToDr] TransactionModification is redundant for some calls + // might be better to replace it in future + fn confirm_request(&self, id: U256, modification: TransactionModification, pass: String) -> Result { 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)| { - let id = id.into(); - let accounts = take_weak!(self.accounts); - let signer = take_weak!(self.signer); - let client = take_weak!(self.client); - let miner = take_weak!(self.miner); - signer.peek(&id).map(|confirmation| { - let result = match confirmation.payload { - ConfirmationPayload::Transaction(mut request) => { - // apply modification - if let Some(gas_price) = modification.gas_price { - request.gas_price = gas_price.into(); - } - sign_and_dispatch(&*client, &*miner, &*accounts, request.into(), Some(pass)) - }, - ConfirmationPayload::Sign(address, hash) => { - sign(&*accounts, address, Some(pass), hash) - }, - ConfirmationPayload::Decrypt(address, msg) => { - decrypt(&*accounts, address, Some(pass), msg) - }, - }; - if let Ok(ref response) = result { - signer.request_confirmed(id, Ok(response.clone())); + let id = id.into(); + let accounts = take_weak!(self.accounts); + let signer = take_weak!(self.signer); + let client = take_weak!(self.client); + let miner = take_weak!(self.miner); + + signer.peek(&id).map(|confirmation| { + let result = match confirmation.payload { + ConfirmationPayload::Transaction(mut request) => { + // apply modification + if let Some(gas_price) = modification.gas_price { + request.gas_price = gas_price.into(); } - result - }).unwrap_or_else(|| Err(errors::invalid_params("Unknown RequestID", id))) + sign_and_dispatch(&*client, &*miner, &*accounts, request.into(), Some(pass)).map(to_value) + }, + ConfirmationPayload::Sign(address, hash) => { + sign(&*accounts, address, Some(pass), hash) + }, + ConfirmationPayload::Decrypt(address, msg) => { + decrypt(&*accounts, address, Some(pass), msg) + }, + }; + if let Ok(ref response) = result { + signer.request_confirmed(id, Ok(response.clone())); } - ) + result + }).unwrap_or_else(|| Err(errors::invalid_params("Unknown RequestID", id))) } - fn reject_request(&self, params: Params) -> Result { + fn reject_request(&self, id: U256) -> Result { 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())) - } - ) - } - - fn generate_token(&self, params: Params) -> Result { - try!(self.active()); - try!(expect_no_params(params)); let signer = take_weak!(self.signer); + + let res = signer.request_rejected(id.into()); + Ok(res.is_some()) + } + + fn generate_token(&self) -> Result { + try!(self.active()); + let signer = take_weak!(self.signer); + signer.generate_token() - .map(|token| to_value(&token)) .map_err(|e| errors::token(e)) } } diff --git a/rpc/src/v1/impls/web3.rs b/rpc/src/v1/impls/web3.rs index 3f987d27e..2e8f99006 100644 --- a/rpc/src/v1/impls/web3.rs +++ b/rpc/src/v1/impls/web3.rs @@ -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 { - try!(expect_no_params(params)); - Ok(Value::String(version().to_owned().replace("Parity/", "Parity//"))) + fn client_version(&self) -> Result { + Ok(version().to_owned().replace("Parity/", "Parity//")) } - fn sha3(&self, params: Params) -> Result { - 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 { + Ok(data.0.sha3().into()) } } diff --git a/rpc/src/v1/tests/mocked/personal.rs b/rpc/src/v1/tests/mocked/personal.rs index 2dd186cca..3bf4a9fa8 100644 --- a/rpc/src/v1/tests/mocked/personal.rs +++ b/rpc/src/v1/tests/mocked/personal.rs @@ -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())); diff --git a/rpc/src/v1/traits/personal.rs b/rpc/src/v1/traits/personal.rs index 8ad1b7ac6..fe5c3cb02 100644 --- a/rpc/src/v1/traits/personal.rs +++ b/rpc/src/v1/traits/personal.rs @@ -15,117 +15,104 @@ // along with Parity. If not, see . //! 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}; - /// Lists all stored accounts - fn accounts(&self, _: Params) -> Result; +build_rpc_trait! { + /// Personal rpc interface. Safe (read-only) functions. + pub trait Personal { + /// Lists all stored accounts + #[rpc(name = "personal_listAccounts")] + fn accounts(&self) -> Result, Error>; - /// Returns accounts information. - fn accounts_info(&self, _: Params) -> Result; - - /// Should be used to convert object to io delegate. - fn to_delegate(self) -> IoDelegate { - let mut delegate = IoDelegate::new(Arc::new(self)); - delegate.add_method("personal_listAccounts", Personal::accounts); - delegate.add_method("personal_accountsInfo", Personal::accounts_info); - - delegate + /// Returns accounts information. + #[rpc(name = "personal_accountsInfo")] + fn accounts_info(&self) -> Result, 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; + /// Creates new account (it becomes new current unlocked account) + /// Param is the password for the account. + #[rpc(name = "personal_newAccount")] + fn new_account(&self, String) -> Result; - /// 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; + /// Creates new account from the given phrase using standard brainwallet mechanism. + /// Second parameter is password for the new account. + #[rpc(name = "personal_newAccountFromPhrase")] + fn new_account_from_phrase(&self, String, String) -> Result; - /// 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; + /// Creates new account from the given JSON wallet. + /// Second parameter is password for the wallet and the new account. + #[rpc(name = "personal_newAccountFromWallet")] + fn new_account_from_wallet(&self, String, String) -> Result; - /// 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; + /// Creates new account from the given raw secret. + /// Second parameter is password for the new account. + #[rpc(name = "personal_newAccountFromSecret")] + fn new_account_from_secret(&self, H256, String) -> Result; - /// Unlocks specified account for use (can only be one unlocked account at one moment) - fn unlock_account(&self, _: Params) -> Result; + /// Unlocks specified account for use (can only be one unlocked account at one moment) + #[rpc(name = "personal_unlockAccount")] + fn unlock_account(&self, H160, String, Option) -> Result; - /// Returns true if given `password` would unlock given `account`. - /// Arguments: `account`, `password`. - fn test_password(&self, _: Params) -> Result; + /// Returns true if given `password` would unlock given `account`. + /// Arguments: `account`, `password`. + #[rpc(name = "personal_testPassword")] + fn test_password(&self, H160, String) -> Result; - /// Changes an account's password. - /// Arguments: `account`, `password`, `new_password`. - fn change_password(&self, _: Params) -> Result; + /// Changes an account's password. + /// Arguments: `account`, `password`, `new_password`. + #[rpc(name = "personal_changePassword")] + fn change_password(&self, H160, String, String) -> Result; - /// Sends transaction and signs it in single call. The account is not unlocked in such case. - fn sign_and_send_transaction(&self, _: Params) -> Result; + /// Sends transaction and signs it in single call. The account is not unlocked in such case. + #[rpc(name = "personal_signAndSendTransaction")] + fn sign_and_send_transaction(&self, TransactionRequest, String) -> Result; - /// Set an account's name. - fn set_account_name(&self, _: Params) -> Result; + /// Set an account's name. + #[rpc(name = "personal_setAccountName")] + fn set_account_name(&self, H160, String) -> Result; - /// Set an account's metadata string. - fn set_account_meta(&self, _: Params) -> Result; + /// Set an account's metadata string. + #[rpc(name = "personal_setAccountMeta")] + fn set_account_meta(&self, H160, String) -> Result; - /// Imports a number of Geth accounts, with the list provided as the argument. - fn import_geth_accounts(&self, _: Params) -> Result; + /// Imports a number of Geth accounts, with the list provided as the argument. + #[rpc(name = "personal_importGethAccounts")] + fn import_geth_accounts(&self, Vec) -> Result, Error>; - /// Returns the accounts available for importing from Geth. - fn geth_accounts(&self, _: Params) -> Result; - - /// Should be used to convert object to io delegate. - fn to_delegate(self) -> IoDelegate { - 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 + /// Returns the accounts available for importing from Geth. + #[rpc(name = "personal_listGethAccounts")] + fn geth_accounts(&self) -> Result, 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; + /// Returns a list of items to confirm. + #[rpc(name = "personal_requestsToConfirm")] + fn requests_to_confirm(&self) -> Result, Error>; - /// Confirm specific request. - fn confirm_request(&self, _: Params) -> Result; + /// Confirm specific request. + #[rpc(name = "personal_confirmRequest")] + fn confirm_request(&self, U256, TransactionModification, String) -> Result; - /// Reject the confirmation request. - fn reject_request(&self, _: Params) -> Result; + /// Reject the confirmation request. + #[rpc(name = "personal_rejectRequest")] + fn reject_request(&self, U256) -> Result; - /// Generates new authorization token. - fn generate_token(&self, _: Params) -> Result; - - /// Should be used to convert object to io delegate. - fn to_delegate(self) -> IoDelegate { - 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 + /// Generates new authorization token. + #[rpc(name = "personal_generateAuthorizationToken")] + fn generate_token(&self) -> Result; } } diff --git a/rpc/src/v1/traits/web3.rs b/rpc/src/v1/traits/web3.rs index 335911025..fc1f50b9b 100644 --- a/rpc/src/v1/traits/web3.rs +++ b/rpc/src/v1/traits/web3.rs @@ -15,22 +15,21 @@ // along with Parity. If not, see . //! Web3 rpc interface. -use std::sync::Arc; -use jsonrpc_core::*; +use jsonrpc_core::Error; -/// Web3 rpc interface. -pub trait Web3: Sized + Send + Sync + 'static { - /// Returns current client version. - fn client_version(&self, _: Params) -> Result; +use v1::helpers::auto_args::Wrap; +use v1::types::{H256, Bytes}; - /// Returns sha3 of the given data - fn sha3(&self, _: Params) -> Result; - /// Should be used to convert object to io delegate. - fn to_delegate(self) -> IoDelegate { - let mut delegate = IoDelegate::new(Arc::new(self)); - delegate.add_method("web3_clientVersion", Web3::client_version); - delegate.add_method("web3_sha3", Web3::sha3); - delegate +build_rpc_trait! { + /// Web3 rpc interface. + pub trait Web3 { + /// Returns current client version. + #[rpc(name = "web3_clientVersion")] + fn client_version(&self) -> Result; + + /// Returns sha3 of the given data + #[rpc(name = "web3_sha3")] + fn sha3(&self, Bytes) -> Result; } }