parity_getVaultMeta && parity_setVaultMeta (#4475)
This commit is contained in:
committed by
Gav Wood
parent
b0248cad0b
commit
a92bf65181
@@ -248,6 +248,19 @@ impl ParityAccounts for ParityAccountsClient {
|
||||
.map_err(|e| errors::account("Could not change vault.", e))
|
||||
.map(|_| true)
|
||||
}
|
||||
|
||||
fn get_vault_meta(&self, name: String) -> Result<String, Error> {
|
||||
take_weak!(self.accounts)
|
||||
.get_vault_meta(&name)
|
||||
.map_err(|e| errors::account("Could not get vault metadata.", e))
|
||||
}
|
||||
|
||||
fn set_vault_meta(&self, name: String, meta: String) -> Result<bool, Error> {
|
||||
take_weak!(self.accounts)
|
||||
.set_vault_meta(&name, &meta)
|
||||
.map_err(|e| errors::account("Could not update vault metadata.", e))
|
||||
.map(|_| true)
|
||||
}
|
||||
}
|
||||
|
||||
fn into_vec<A, B>(a: Vec<A>) -> Vec<B> where
|
||||
|
||||
@@ -351,3 +351,27 @@ fn rpc_parity_list_opened_vaults() {
|
||||
assert!(actual_response == Some(response1.to_owned())
|
||||
|| actual_response == Some(response2.to_owned()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rpc_parity_get_set_vault_meta() {
|
||||
let temp_path = RandomTempPath::new();
|
||||
let tester = setup_with_vaults_support(temp_path.as_str());
|
||||
|
||||
assert!(tester.accounts.create_vault("vault1", "password1").is_ok());
|
||||
assert!(tester.accounts.set_vault_meta("vault1", "vault1_meta").is_ok());
|
||||
|
||||
let request = r#"{"jsonrpc": "2.0", "method": "parity_getVaultMeta", "params":["vault1"], "id": 1}"#;
|
||||
let response = r#"{"jsonrpc":"2.0","result":"vault1_meta","id":1}"#;
|
||||
|
||||
assert_eq!(tester.io.handle_request_sync(request), Some(response.to_owned()));
|
||||
|
||||
let request = r#"{"jsonrpc": "2.0", "method": "parity_setVaultMeta", "params":["vault1", "updated_vault1_meta"], "id": 1}"#;
|
||||
let response = r#"{"jsonrpc":"2.0","result":true,"id":1}"#;
|
||||
|
||||
assert_eq!(tester.io.handle_request_sync(request), Some(response.to_owned()));
|
||||
|
||||
let request = r#"{"jsonrpc": "2.0", "method": "parity_getVaultMeta", "params":["vault1"], "id": 1}"#;
|
||||
let response = r#"{"jsonrpc":"2.0","result":"updated_vault1_meta","id":1}"#;
|
||||
|
||||
assert_eq!(tester.io.handle_request_sync(request), Some(response.to_owned()));
|
||||
}
|
||||
|
||||
@@ -133,5 +133,13 @@ build_rpc_trait! {
|
||||
/// Change vault of the given address.
|
||||
#[rpc(name = "parity_changeVault")]
|
||||
fn change_vault(&self, H160, String) -> Result<bool, Error>;
|
||||
|
||||
/// Get vault metadata string.
|
||||
#[rpc(name = "parity_getVaultMeta")]
|
||||
fn get_vault_meta(&self, String) -> Result<String, Error>;
|
||||
|
||||
/// Set vault metadata string.
|
||||
#[rpc(name = "parity_setVaultMeta")]
|
||||
fn set_vault_meta(&self, String, String) -> Result<bool, Error>;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user