Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Return error on timed unlock attempt. (#6777)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomusdrw authored and arkpar committed Oct 24, 2017
1 parent 3e5d9b9 commit 025244e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
4 changes: 2 additions & 2 deletions parity/rpc_apis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ impl FullDependencies {
}
},
Api::Personal => {
handler.extend_with(PersonalClient::new(&self.secret_store, dispatcher.clone(), self.geth_compatibility).to_delegate());
handler.extend_with(PersonalClient::new(self.secret_store.clone(), dispatcher.clone(), self.geth_compatibility).to_delegate());
},
Api::Signer => {
handler.extend_with(SignerClient::new(&self.secret_store, dispatcher.clone(), &self.signer_service, self.remote.clone()).to_delegate());
Expand Down Expand Up @@ -495,7 +495,7 @@ impl<C: LightChainClient + 'static> LightDependencies<C> {
},
Api::Personal => {
let secret_store = Some(self.secret_store.clone());
handler.extend_with(PersonalClient::new(&secret_store, dispatcher.clone(), self.geth_compatibility).to_delegate());
handler.extend_with(PersonalClient::new(secret_store, dispatcher.clone(), self.geth_compatibility).to_delegate());
},
Api::Signer => {
let secret_store = Some(self.secret_store.clone());
Expand Down
17 changes: 10 additions & 7 deletions rpc/src/v1/impls/personal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ pub struct PersonalClient<D: Dispatcher> {

impl<D: Dispatcher> PersonalClient<D> {
/// Creates new PersonalClient
pub fn new(store: &Option<Arc<AccountProvider>>, dispatcher: D, allow_perm_unlock: bool) -> Self {
pub fn new(accounts: Option<Arc<AccountProvider>>, dispatcher: D, allow_perm_unlock: bool) -> Self {
PersonalClient {
accounts: store.clone(),
dispatcher: dispatcher,
allow_perm_unlock: allow_perm_unlock,
accounts,
dispatcher,
allow_perm_unlock,
}
}

Expand Down Expand Up @@ -89,15 +89,18 @@ impl<D: Dispatcher + 'static> Personal for PersonalClient<D> {
};

let r = match (self.allow_perm_unlock, duration) {
(false, _) => store.unlock_account_temporarily(account, account_pass),
(false, None) => store.unlock_account_temporarily(account, account_pass),
(false, _) => return Err(errors::unsupported(
"Time-unlocking is only supported in --geth compatibility mode.",
Some("Restart your client with --geth flag or use personal_sendTransaction instead."),
)),
(true, Some(0)) => store.unlock_account_permanently(account, account_pass),
(true, Some(d)) => store.unlock_account_timed(account, account_pass, d * 1000),
(true, None) => store.unlock_account_timed(account, account_pass, 300_000),
};
match r {
Ok(_) => Ok(true),
// TODO [ToDr] Proper error here?
Err(_) => Ok(false),
Err(err) => Err(errors::account("Unable to unlock the account.", err)),
}
}

Expand Down
8 changes: 4 additions & 4 deletions rpc/src/v1/tests/mocked/personal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ fn setup() -> PersonalTester {
let miner = miner_service();

let dispatcher = FullDispatcher::new(client, miner.clone());
let personal = PersonalClient::new(&opt_accounts, dispatcher, false);
let personal = PersonalClient::new(opt_accounts, dispatcher, false);

let mut io = IoHandler::default();
io.extend_with(personal.to_delegate());
Expand Down Expand Up @@ -178,7 +178,7 @@ fn sign_and_send_test(method: &str) {
}

#[test]
fn should_unlock_account_temporarily() {
fn should_unlock_not_account_temporarily_if_allow_perm_is_disabled() {
let tester = setup();
let address = tester.accounts.new_account("password123").unwrap();

Expand All @@ -192,10 +192,10 @@ fn should_unlock_account_temporarily() {
],
"id": 1
}"#;
let response = r#"{"jsonrpc":"2.0","result":true,"id":1}"#;
let response = r#"{"jsonrpc":"2.0","error":{"code":-32000,"message":"Time-unlocking is only supported in --geth compatibility mode.","data":"Restart your client with --geth flag or use personal_sendTransaction instead."},"id":1}"#;
assert_eq!(tester.io.handle_request_sync(&request), Some(response.into()));

assert!(tester.accounts.sign(address, None, Default::default()).is_ok(), "Should unlock account.");
assert!(tester.accounts.sign(address, None, Default::default()).is_err(), "Should not unlock account.");
}

#[test]
Expand Down

0 comments on commit 025244e

Please sign in to comment.