Unlock account with timeout for geth compatibility (#1854) (#1858)

* Unlock account with timeout for geth compatibility

* Fixed test
This commit is contained in:
Arkadiy Paronyan
2016-08-06 09:26:06 +02:00
committed by GitHub
parent aa9b152f76
commit 801cf6fcba
4 changed files with 57 additions and 26 deletions

View File

@@ -31,16 +31,18 @@ pub struct PersonalClient<C, M> where C: MiningBlockChainClient, M: MinerService
client: Weak<C>,
miner: Weak<M>,
signer_port: Option<u16>,
allow_perm_unlock: bool,
}
impl<C, M> PersonalClient<C, M> where C: MiningBlockChainClient, M: MinerService {
/// Creates new PersonalClient
pub fn new(store: &Arc<AccountProvider>, client: &Arc<C>, miner: &Arc<M>, signer_port: Option<u16>) -> Self {
pub fn new(store: &Arc<AccountProvider>, client: &Arc<C>, miner: &Arc<M>, signer_port: Option<u16>, allow_perm_unlock: bool) -> Self {
PersonalClient {
accounts: Arc::downgrade(store),
client: Arc::downgrade(client),
miner: Arc::downgrade(miner),
signer_port: signer_port,
allow_perm_unlock: allow_perm_unlock,
}
}
}
@@ -71,10 +73,17 @@ impl<C: 'static, M: 'static> Personal for PersonalClient<C, M> where C: MiningBl
}
fn unlock_account(&self, params: Params) -> Result<Value, Error> {
from_params::<(Address, String, u64)>(params).and_then(
|(account, account_pass, _)|{
from_params::<(Address, String, Option<u64>)>(params).and_then(
|(account, account_pass, duration)|{
let account: Address = account.into();
let store = take_weak!(self.accounts);
match store.unlock_account_temporarily(account, account_pass) {
let r = match (self.allow_perm_unlock, duration) {
(false, _) => store.unlock_account_temporarily(account, account_pass),
(true, Some(0)) => store.unlock_account_permanently(account, account_pass),
(true, Some(d)) => store.unlock_account_timed(account, account_pass, d as u32 * 1000),
(true, None) => store.unlock_account_timed(account, account_pass, 300_000),
};
match r {
Ok(_) => Ok(Value::Bool(true)),
Err(_) => Ok(Value::Bool(false)),
}

View File

@@ -50,7 +50,7 @@ fn setup(signer: Option<u16>) -> PersonalTester {
let accounts = accounts_provider();
let client = blockchain_client();
let miner = miner_service();
let personal = PersonalClient::new(&accounts, &client, &miner, signer);
let personal = PersonalClient::new(&accounts, &client, &miner, signer, false);
let io = IoHandler::new();
io.add_delegate(personal.to_delegate());