From 2b8bed434c498ff7d200376290a3f85bebe60f94 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Sun, 20 Nov 2016 16:17:57 +0100 Subject: [PATCH] RPC for deleting accounts. --- ethcore/src/account_provider.rs | 10 ++++++++-- rpc/src/v1/impls/parity_accounts.rs | 11 ++++++++++- rpc/src/v1/traits/parity_accounts.rs | 5 +++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/ethcore/src/account_provider.rs b/ethcore/src/account_provider.rs index e906aefe9..917ae8b8b 100644 --- a/ethcore/src/account_provider.rs +++ b/ethcore/src/account_provider.rs @@ -276,14 +276,20 @@ impl AccountProvider { } /// Returns `true` if the password for `account` is `password`. `false` if not. - pub fn test_password(&self, account: &Address, password: String) -> Result { - match self.sstore.sign(account, &password, &Default::default()) { + pub fn test_password(&self, account: &Address, password: &str) -> Result { + match self.sstore.sign(account, password, &Default::default()) { Ok(_) => Ok(true), Err(SSError::InvalidPassword) => Ok(false), Err(e) => Err(Error::SStore(e)), } } + /// Permanently removes an account. + pub fn kill_account(&self, account: &Address, password: &str) -> Result<(), Error> { + try!(self.sstore.remove_account(account, &password)); + Ok(()) + } + /// Changes the password of `account` from `password` to `new_password`. Fails if incorrect `password` given. pub fn change_password(&self, account: &Address, password: String, new_password: String) -> Result<(), Error> { self.sstore.change_password(account, &password, &new_password).map_err(Error::SStore) diff --git a/rpc/src/v1/impls/parity_accounts.rs b/rpc/src/v1/impls/parity_accounts.rs index 2644c59e3..8229715ea 100644 --- a/rpc/src/v1/impls/parity_accounts.rs +++ b/rpc/src/v1/impls/parity_accounts.rs @@ -104,7 +104,7 @@ impl ParityAccounts for ParityAccountsClient where C: MiningBlock let account: Address = account.into(); take_weak!(self.accounts) - .test_password(&account, password) + .test_password(&account, &password) .map_err(|e| errors::account("Could not fetch account info.", e)) } @@ -117,6 +117,15 @@ impl ParityAccounts for ParityAccountsClient where C: MiningBlock .map_err(|e| errors::account("Could not fetch account info.", e)) } + fn kill_account(&self, account: RpcH160, password: String) -> Result { + try!(self.active()); + let account: Address = account.into(); + take_weak!(self.accounts) + .kill_account(&account, &password) + .map(|_| true) + .map_err(|e| errors::account("Could not fetch account info.", e)) + } + fn set_account_name(&self, addr: RpcH160, name: String) -> Result { try!(self.active()); let store = take_weak!(self.accounts); diff --git a/rpc/src/v1/traits/parity_accounts.rs b/rpc/src/v1/traits/parity_accounts.rs index 0f62f59d1..29706d0b2 100644 --- a/rpc/src/v1/traits/parity_accounts.rs +++ b/rpc/src/v1/traits/parity_accounts.rs @@ -53,6 +53,11 @@ build_rpc_trait! { #[rpc(name = "parity_changePassword")] fn change_password(&self, H160, String, String) -> Result; + /// Permanently deletes an account. + /// Arguments: `account`, `password`. + #[rpc(name = "parity_killAccount")] + fn kill_account(&self, H160, String) -> Result; + /// Set an account's name. #[rpc(name = "parity_setAccountName")] fn set_account_name(&self, H160, String) -> Result;