2016-03-04 12:46:54 +01:00
|
|
|
// Copyright 2015, 2016 Ethcore (UK) Ltd.
|
|
|
|
// This file is part of Parity.
|
|
|
|
|
|
|
|
// Parity is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
|
|
|
// Parity is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
//! Personal rpc interface.
|
|
|
|
use std::sync::Arc;
|
|
|
|
use jsonrpc_core::*;
|
|
|
|
|
2016-10-27 19:26:34 +02:00
|
|
|
/// Personal rpc interface. Safe (read-only) functions.
|
2016-03-04 12:46:54 +01:00
|
|
|
pub trait Personal: Sized + Send + Sync + 'static {
|
|
|
|
|
|
|
|
/// Lists all stored accounts
|
2016-05-27 20:04:41 +02:00
|
|
|
fn accounts(&self, _: Params) -> Result<Value, Error>;
|
2016-03-04 12:46:54 +01:00
|
|
|
|
2016-10-27 19:26:34 +02:00
|
|
|
/// 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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Personal rpc methods altering stored accounts or their settings.
|
|
|
|
pub trait PersonalAccounts: Sized + Send + Sync + 'static {
|
|
|
|
|
2016-03-04 12:46:54 +01:00
|
|
|
/// Creates new account (it becomes new current unlocked account)
|
2016-08-10 17:57:40 +02:00
|
|
|
/// Param is the password for the account.
|
2016-05-27 20:04:41 +02:00
|
|
|
fn new_account(&self, _: Params) -> Result<Value, Error>;
|
2016-03-04 12:46:54 +01:00
|
|
|
|
2016-08-10 17:57:40 +02:00
|
|
|
/// Creates new account from the given phrase using standard brainwallet mechanism.
|
|
|
|
/// Second parameter is password for the new account.
|
|
|
|
fn new_account_from_phrase(&self, _: Params) -> Result<Value, Error>;
|
|
|
|
|
|
|
|
/// Creates new account from the given JSON wallet.
|
|
|
|
/// Second parameter is password for the wallet and the new account.
|
|
|
|
fn new_account_from_wallet(&self, params: Params) -> Result<Value, Error>;
|
|
|
|
|
2016-03-04 12:46:54 +01:00
|
|
|
/// Unlocks specified account for use (can only be one unlocked account at one moment)
|
2016-05-27 20:04:41 +02:00
|
|
|
fn unlock_account(&self, _: Params) -> Result<Value, Error>;
|
2016-03-04 12:46:54 +01:00
|
|
|
|
2016-10-22 15:24:02 +02:00
|
|
|
/// Returns true if given `password` would unlock given `account`.
|
|
|
|
/// Arguments: `account`, `password`.
|
|
|
|
fn test_password(&self, _: Params) -> Result<Value, Error>;
|
|
|
|
|
|
|
|
/// Changes an account's password.
|
|
|
|
/// Arguments: `account`, `password`, `new_password`.
|
|
|
|
fn change_password(&self, _: Params) -> Result<Value, Error>;
|
|
|
|
|
2016-05-26 20:07:47 +02:00
|
|
|
/// Sends transaction and signs it in single call. The account is not unlocked in such case.
|
2016-05-27 20:04:41 +02:00
|
|
|
fn sign_and_send_transaction(&self, _: Params) -> Result<Value, Error>;
|
2016-05-26 20:07:47 +02:00
|
|
|
|
2016-07-24 17:38:21 +02:00
|
|
|
/// Set an account's name.
|
|
|
|
fn set_account_name(&self, _: Params) -> Result<Value, Error>;
|
|
|
|
|
|
|
|
/// Set an account's metadata string.
|
|
|
|
fn set_account_meta(&self, _: Params) -> Result<Value, Error>;
|
|
|
|
|
2016-10-27 19:26:34 +02:00
|
|
|
/// Imports a number of Geth accounts, with the list provided as the argument.
|
|
|
|
fn import_geth_accounts(&self, _: Params) -> Result<Value, Error>;
|
2016-07-24 17:38:21 +02:00
|
|
|
|
2016-08-11 18:31:28 +02:00
|
|
|
/// Returns the accounts available for importing from Geth.
|
|
|
|
fn geth_accounts(&self, _: Params) -> Result<Value, Error>;
|
|
|
|
|
2016-03-04 12:46:54 +01:00
|
|
|
/// Should be used to convert object to io delegate.
|
|
|
|
fn to_delegate(self) -> IoDelegate<Self> {
|
|
|
|
let mut delegate = IoDelegate::new(Arc::new(self));
|
2016-10-27 19:26:34 +02:00
|
|
|
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_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);
|
2016-07-24 17:38:21 +02:00
|
|
|
|
2016-03-04 12:46:54 +01:00
|
|
|
delegate
|
|
|
|
}
|
|
|
|
}
|
2016-06-01 19:37:34 +02:00
|
|
|
|
2016-08-03 10:36:54 +02:00
|
|
|
/// Personal extension for confirmations rpc interface.
|
2016-06-01 19:37:34 +02:00
|
|
|
pub trait PersonalSigner: Sized + Send + Sync + 'static {
|
|
|
|
|
2016-08-03 10:36:54 +02:00
|
|
|
/// Returns a list of items to confirm.
|
|
|
|
fn requests_to_confirm(&self, _: Params) -> Result<Value, Error>;
|
2016-06-01 19:37:34 +02:00
|
|
|
|
2016-08-03 10:36:54 +02:00
|
|
|
/// Confirm specific request.
|
|
|
|
fn confirm_request(&self, _: Params) -> Result<Value, Error>;
|
2016-06-01 19:37:34 +02:00
|
|
|
|
2016-08-03 10:36:54 +02:00
|
|
|
/// Reject the confirmation request.
|
|
|
|
fn reject_request(&self, _: Params) -> Result<Value, Error>;
|
2016-06-01 19:37:34 +02:00
|
|
|
|
2016-09-21 12:44:49 +02:00
|
|
|
/// Generates new authorization token.
|
|
|
|
fn generate_token(&self, _: Params) -> Result<Value, Error>;
|
|
|
|
|
2016-06-01 19:37:34 +02:00
|
|
|
/// Should be used to convert object to io delegate.
|
|
|
|
fn to_delegate(self) -> IoDelegate<Self> {
|
|
|
|
let mut delegate = IoDelegate::new(Arc::new(self));
|
2016-08-03 10:36:54 +02:00
|
|
|
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);
|
2016-09-21 12:44:49 +02:00
|
|
|
delegate.add_method("personal_generateAuthorizationToken", PersonalSigner::generate_token);
|
2016-10-27 19:26:34 +02:00
|
|
|
|
2016-06-01 19:37:34 +02:00
|
|
|
delegate
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|