Merge pull request #3735 from ethcore/jg-addressbook-delete
Add parity_removeAddress RPC
This commit is contained in:
commit
342357302b
@ -194,6 +194,11 @@ impl AccountProvider {
|
|||||||
Ok(self.address_book.write().set_meta(account, meta))
|
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.
|
/// Returns each account along with name and meta.
|
||||||
pub fn accounts_info(&self) -> Result<HashMap<Address, AccountMeta>, Error> {
|
pub fn accounts_info(&self) -> Result<HashMap<Address, AccountMeta>, Error> {
|
||||||
let r: HashMap<Address, AccountMeta> = try!(self.sstore.accounts())
|
let r: HashMap<Address, AccountMeta> = try!(self.sstore.accounts())
|
||||||
|
@ -74,6 +74,12 @@ impl AddressBook {
|
|||||||
}
|
}
|
||||||
self.save();
|
self.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Removes an entry
|
||||||
|
pub fn remove(&mut self, a: Address) {
|
||||||
|
self.cache.remove(&a);
|
||||||
|
self.save();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Dapps user settings
|
/// Dapps user settings
|
||||||
@ -244,4 +250,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}
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -128,6 +128,11 @@ export default class Parity {
|
|||||||
.execute('parity_killAccount', inAddress(account), password);
|
.execute('parity_killAccount', inAddress(account), password);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
removeAddress (address) {
|
||||||
|
return this._transport
|
||||||
|
.execute('parity_removeAddress', inAddress(address));
|
||||||
|
}
|
||||||
|
|
||||||
listGethAccounts () {
|
listGethAccounts () {
|
||||||
return this._transport
|
return this._transport
|
||||||
.execute('parity_listGethAccounts')
|
.execute('parity_listGethAccounts')
|
||||||
|
@ -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: {
|
listGethAccounts: {
|
||||||
desc: 'Returns a list of the accounts available from Geth',
|
desc: 'Returns a list of the accounts available from Geth',
|
||||||
params: [],
|
params: [],
|
||||||
|
@ -126,6 +126,16 @@ impl<C: 'static> ParityAccounts for ParityAccountsClient<C> where C: MiningBlock
|
|||||||
.map_err(|e| errors::account("Could not delete account.", e))
|
.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)
|
||||||
|
.expect("remove_address always returns Ok; qed");
|
||||||
|
Ok(true)
|
||||||
|
}
|
||||||
|
|
||||||
fn set_account_name(&self, addr: RpcH160, name: String) -> Result<bool, Error> {
|
fn set_account_name(&self, addr: RpcH160, name: String) -> Result<bool, Error> {
|
||||||
try!(self.active());
|
try!(self.active());
|
||||||
let store = take_weak!(self.accounts);
|
let store = take_weak!(self.accounts);
|
||||||
|
@ -152,3 +152,32 @@ fn should_be_able_to_kill_account() {
|
|||||||
let accounts = tester.accounts.accounts().unwrap();
|
let accounts = tester.accounts.accounts().unwrap();
|
||||||
assert_eq!(accounts.len(), 0);
|
assert_eq!(accounts.len(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn should_be_able_to_remove_address() {
|
||||||
|
let tester = setup();
|
||||||
|
|
||||||
|
// add an address
|
||||||
|
let request = r#"{"jsonrpc": "2.0", "method": "parity_setAccountName", "params": ["0x000baba1000baba2000baba3000baba4000baba5", "Test"], "id": 1}"#;
|
||||||
|
let response = r#"{"jsonrpc":"2.0","result":true,"id":1}"#;
|
||||||
|
let res = tester.io.handle_request_sync(&request);
|
||||||
|
assert_eq!(res, Some(response.into()));
|
||||||
|
|
||||||
|
// verify it exists
|
||||||
|
let request = r#"{"jsonrpc": "2.0", "method": "parity_accountsInfo", "params": [], "id": 2}"#;
|
||||||
|
let res = tester.io.handle_request_sync(request);
|
||||||
|
let response = r#"{"jsonrpc":"2.0","result":{"0x000baba1000baba2000baba3000baba4000baba5":{"meta":"{}","name":"Test","uuid":null}},"id":2}"#;
|
||||||
|
assert_eq!(res, Some(response.into()));
|
||||||
|
|
||||||
|
// remove the address
|
||||||
|
let request = r#"{"jsonrpc": "2.0", "method": "parity_removeAddress", "params": ["0x000baba1000baba2000baba3000baba4000baba5"], "id": 3}"#;
|
||||||
|
let response = r#"{"jsonrpc":"2.0","result":true,"id":3}"#;
|
||||||
|
let res = tester.io.handle_request_sync(&request);
|
||||||
|
assert_eq!(res, Some(response.into()));
|
||||||
|
|
||||||
|
// verify empty
|
||||||
|
let request = r#"{"jsonrpc": "2.0", "method": "parity_accountsInfo", "params": [], "id": 4}"#;
|
||||||
|
let res = tester.io.handle_request_sync(request);
|
||||||
|
let response = r#"{"jsonrpc":"2.0","result":{},"id":4}"#;
|
||||||
|
assert_eq!(res, Some(response.into()));
|
||||||
|
}
|
||||||
|
@ -58,6 +58,11 @@ build_rpc_trait! {
|
|||||||
#[rpc(name = "parity_killAccount")]
|
#[rpc(name = "parity_killAccount")]
|
||||||
fn kill_account(&self, H160, String) -> Result<bool, Error>;
|
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.
|
/// Set an account's name.
|
||||||
#[rpc(name = "parity_setAccountName")]
|
#[rpc(name = "parity_setAccountName")]
|
||||||
fn set_account_name(&self, H160, String) -> Result<bool, Error>;
|
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>;
|
fn geth_accounts(&self) -> Result<Vec<H160>, Error>;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user