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}
]);
}
}