Return error on timed unlock attempt. (#6777)
This commit is contained in:
parent
3e5d9b92c1
commit
025244e8b2
@ -292,7 +292,7 @@ impl FullDependencies {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
Api::Personal => {
|
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 => {
|
Api::Signer => {
|
||||||
handler.extend_with(SignerClient::new(&self.secret_store, dispatcher.clone(), &self.signer_service, self.remote.clone()).to_delegate());
|
handler.extend_with(SignerClient::new(&self.secret_store, dispatcher.clone(), &self.signer_service, self.remote.clone()).to_delegate());
|
||||||
@ -495,7 +495,7 @@ impl<C: LightChainClient + 'static> LightDependencies<C> {
|
|||||||
},
|
},
|
||||||
Api::Personal => {
|
Api::Personal => {
|
||||||
let secret_store = Some(self.secret_store.clone());
|
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 => {
|
Api::Signer => {
|
||||||
let secret_store = Some(self.secret_store.clone());
|
let secret_store = Some(self.secret_store.clone());
|
||||||
|
@ -42,11 +42,11 @@ pub struct PersonalClient<D: Dispatcher> {
|
|||||||
|
|
||||||
impl<D: Dispatcher> PersonalClient<D> {
|
impl<D: Dispatcher> PersonalClient<D> {
|
||||||
/// Creates new PersonalClient
|
/// 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 {
|
PersonalClient {
|
||||||
accounts: store.clone(),
|
accounts,
|
||||||
dispatcher: dispatcher,
|
dispatcher,
|
||||||
allow_perm_unlock: allow_perm_unlock,
|
allow_perm_unlock,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,15 +89,18 @@ impl<D: Dispatcher + 'static> Personal for PersonalClient<D> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let r = match (self.allow_perm_unlock, duration) {
|
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(0)) => store.unlock_account_permanently(account, account_pass),
|
||||||
(true, Some(d)) => store.unlock_account_timed(account, account_pass, d * 1000),
|
(true, Some(d)) => store.unlock_account_timed(account, account_pass, d * 1000),
|
||||||
(true, None) => store.unlock_account_timed(account, account_pass, 300_000),
|
(true, None) => store.unlock_account_timed(account, account_pass, 300_000),
|
||||||
};
|
};
|
||||||
match r {
|
match r {
|
||||||
Ok(_) => Ok(true),
|
Ok(_) => Ok(true),
|
||||||
// TODO [ToDr] Proper error here?
|
Err(err) => Err(errors::account("Unable to unlock the account.", err)),
|
||||||
Err(_) => Ok(false),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,7 +54,7 @@ fn setup() -> PersonalTester {
|
|||||||
let miner = miner_service();
|
let miner = miner_service();
|
||||||
|
|
||||||
let dispatcher = FullDispatcher::new(client, miner.clone());
|
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();
|
let mut io = IoHandler::default();
|
||||||
io.extend_with(personal.to_delegate());
|
io.extend_with(personal.to_delegate());
|
||||||
@ -178,7 +178,7 @@ fn sign_and_send_test(method: &str) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn should_unlock_account_temporarily() {
|
fn should_unlock_not_account_temporarily_if_allow_perm_is_disabled() {
|
||||||
let tester = setup();
|
let tester = setup();
|
||||||
let address = tester.accounts.new_account("password123").unwrap();
|
let address = tester.accounts.new_account("password123").unwrap();
|
||||||
|
|
||||||
@ -192,10 +192,10 @@ fn should_unlock_account_temporarily() {
|
|||||||
],
|
],
|
||||||
"id": 1
|
"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_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]
|
#[test]
|
||||||
|
Loading…
Reference in New Issue
Block a user