io handlers

This commit is contained in:
Nikolay Volf 2016-03-13 14:46:45 +01:00
parent a4103e0830
commit 89dc6fa9cc
2 changed files with 12 additions and 2 deletions

View File

@ -445,6 +445,7 @@ impl Configuration {
// Secret Store
let account_service = Arc::new(AccountService::new());
service.io().register_handler(account_service).expect("Error registering IO handler");
// Setup rpc
if self.args.flag_jsonrpc || self.args.flag_rpc {
@ -468,6 +469,7 @@ impl Configuration {
client: service.client(),
info: Default::default(),
sync: sync.clone(),
accounts: account_service.clone(),
});
service.io().register_handler(io_handler).expect("Error registering IO handler");
@ -559,20 +561,27 @@ impl Informant {
const INFO_TIMER: TimerToken = 0;
const ACCOUNT_TICK_TIMER: TimerToken = 10;
const ACCOUNT_TICK_MS: u64 = 60000;
struct ClientIoHandler {
client: Arc<Client>,
sync: Arc<EthSync>,
accounts: Arc<AccountService>,
info: Informant,
}
impl IoHandler<NetSyncMessage> for ClientIoHandler {
fn initialize(&self, io: &IoContext<NetSyncMessage>) {
io.register_timer(INFO_TIMER, 5000).expect("Error registering timer");
io.register_timer(ACCOUNT_TICK_TIMER, ACCOUNT_TICK_MS).expect("Error registering account timer");
}
fn timeout(&self, _io: &IoContext<NetSyncMessage>, timer: TimerToken) {
if INFO_TIMER == timer {
self.info.tick(&self.client, &self.sync);
match timer {
INFO_TIMER => { self.info.tick(&self.client, &self.sync); }
ACCOUNT_TICK_TIMER => { self.accounts.tick(); }
}
}
}

View File

@ -137,6 +137,7 @@ impl AccountService {
}
}
impl Default for SecretStore {
fn default() -> Self {
SecretStore::new()