RPC for deleting accounts.

This commit is contained in:
Gav Wood 2016-11-20 16:17:57 +01:00
parent 9832be395f
commit 2b8bed434c
No known key found for this signature in database
GPG Key ID: C49C1ACA1CC9B252
3 changed files with 23 additions and 3 deletions

View File

@ -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<bool, Error> {
match self.sstore.sign(account, &password, &Default::default()) {
pub fn test_password(&self, account: &Address, password: &str) -> Result<bool, Error> {
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)

View File

@ -104,7 +104,7 @@ impl<C: 'static> ParityAccounts for ParityAccountsClient<C> 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<C: 'static> ParityAccounts for ParityAccountsClient<C> where C: MiningBlock
.map_err(|e| errors::account("Could not fetch account info.", e))
}
fn kill_account(&self, account: RpcH160, password: String) -> Result<bool, Error> {
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<bool, Error> {
try!(self.active());
let store = take_weak!(self.accounts);

View File

@ -53,6 +53,11 @@ build_rpc_trait! {
#[rpc(name = "parity_changePassword")]
fn change_password(&self, H160, String, String) -> Result<bool, Error>;
/// Permanently deletes an account.
/// Arguments: `account`, `password`.
#[rpc(name = "parity_killAccount")]
fn kill_account(&self, H160, String) -> Result<bool, Error>;
/// Set an account's name.
#[rpc(name = "parity_setAccountName")]
fn set_account_name(&self, H160, String) -> Result<bool, Error>;