Add parity_removeAddress RPC

This commit is contained in:
Jaco Greeff 2016-12-07 16:53:46 +01:00
parent 1f0a02b638
commit 46840d36c9
6 changed files with 65 additions and 1 deletions

View File

@ -194,6 +194,11 @@ impl AccountProvider {
Ok(self.address_book.write().set_meta(account, meta))
}
/// Removes and address from the addressbook
pub fn remove_address(&self, addr: Address) -> Result<(), Error> {
Ok(self.address_book.write().remove(addr))
}
/// Returns each account along with name and meta.
pub fn accounts_info(&self) -> Result<HashMap<Address, AccountMeta>, Error> {
let r: HashMap<Address, AccountMeta> = try!(self.sstore.accounts())

View File

@ -74,6 +74,14 @@ impl AddressBook {
}
self.save();
}
/// Removes an entry
pub fn remove(&mut self, a: Address) {
{
self.cache.remove(&a);
}
self.save();
}
}
/// Dapps user settings
@ -244,4 +252,22 @@ mod tests {
}
]);
}
#[test]
fn should_remove_address() {
let temp = RandomTempPath::create_dir();
let path = temp.as_str().to_owned();
let mut b = AddressBook::new(path.clone());
b.set_name(1.into(), "One".to_owned());
b.set_name(2.into(), "Two".to_owned());
b.set_name(3.into(), "Three".to_owned());
b.remove(2.into());
let b = AddressBook::new(path);
assert_eq!(b.get(), hash_map![
1.into() => AccountMeta{name: "One".to_owned(), meta: "{}".to_owned(), uuid: None},
3.into() => AccountMeta{name: "Three".to_owned(), meta: "{}".to_owned(), uuid: None}
]);
}
}

View File

@ -128,6 +128,11 @@ export default class Parity {
.execute('parity_killAccount', inAddress(account), password);
}
removeAddress (address) {
return this._transport
.execute('parity_removeAddress', inAddress(address));
}
listGethAccounts () {
return this._transport
.execute('parity_listGethAccounts')

View File

@ -256,6 +256,20 @@ export default {
}
},
removeAddress: {
desc: 'Removes an address from the addressbook',
params: [
{
type: Address,
desc: 'The address to remove'
}
],
returns: {
type: Boolean,
desc: 'true on success'
}
},
listGethAccounts: {
desc: 'Returns a list of the accounts available from Geth',
params: [],

View File

@ -126,6 +126,16 @@ impl<C: 'static> ParityAccounts for ParityAccountsClient<C> where C: MiningBlock
.map_err(|e| errors::account("Could not delete account.", e))
}
fn remove_address(&self, addr: RpcH160) -> Result<bool, Error> {
try!(self.active());
let store = take_weak!(self.accounts);
let addr: Address = addr.into();
store.remove_address(addr, name))
.expect("remove_address always returns Ok; qed");
Ok(true)
}
fn set_account_name(&self, addr: RpcH160, name: String) -> Result<bool, Error> {
try!(self.active());
let store = take_weak!(self.accounts);

View File

@ -58,6 +58,11 @@ build_rpc_trait! {
#[rpc(name = "parity_killAccount")]
fn kill_account(&self, H160, String) -> Result<bool, Error>;
/// Permanently deletes an address from the addressbook
/// Arguments: `address`
#[rpc(name = "parity_removeAddress")]
fn remove_address(&self, H160) -> Result<bool, Error>;
/// Set an account's name.
#[rpc(name = "parity_setAccountName")]
fn set_account_name(&self, H160, String) -> Result<bool, Error>;
@ -83,4 +88,3 @@ build_rpc_trait! {
fn geth_accounts(&self) -> Result<Vec<H160>, Error>;
}
}