Merge remote-tracking branch 'origin/master' into boxjdb
This commit is contained in:
@@ -153,7 +153,7 @@ struct UserTimer {
|
||||
pub struct IoManager<Message> where Message: Send + Sync {
|
||||
timers: Arc<RwLock<HashMap<HandlerId, UserTimer>>>,
|
||||
handlers: Vec<Arc<IoHandler<Message>>>,
|
||||
_workers: Vec<Worker>,
|
||||
workers: Vec<Worker>,
|
||||
worker_channel: chase_lev::Worker<Work<Message>>,
|
||||
work_ready: Arc<Condvar>,
|
||||
}
|
||||
@@ -180,7 +180,7 @@ impl<Message> IoManager<Message> where Message: Send + Sync + Clone + 'static {
|
||||
timers: Arc::new(RwLock::new(HashMap::new())),
|
||||
handlers: Vec::new(),
|
||||
worker_channel: worker,
|
||||
_workers: workers,
|
||||
workers: workers,
|
||||
work_ready: work_ready,
|
||||
};
|
||||
try!(event_loop.run(&mut io));
|
||||
@@ -230,7 +230,10 @@ impl<Message> Handler for IoManager<Message> where Message: Send + Clone + Sync
|
||||
|
||||
fn notify(&mut self, event_loop: &mut EventLoop<Self>, msg: Self::Message) {
|
||||
match msg {
|
||||
IoMessage::Shutdown => event_loop.shutdown(),
|
||||
IoMessage::Shutdown => {
|
||||
self.workers.clear();
|
||||
event_loop.shutdown();
|
||||
},
|
||||
IoMessage::AddHandler { handler } => {
|
||||
let handler_id = {
|
||||
self.handlers.push(handler.clone());
|
||||
|
||||
@@ -78,6 +78,59 @@ struct AccountUnlock {
|
||||
expires: DateTime<UTC>,
|
||||
}
|
||||
|
||||
/// Basic account management trait
|
||||
pub trait AccountProvider : Send + Sync {
|
||||
/// Lists all accounts
|
||||
fn accounts(&self) -> Result<Vec<Address>, ::std::io::Error>;
|
||||
/// Unlocks account with the password provided
|
||||
fn unlock_account(&self, account: &Address, pass: &str) -> Result<(), EncryptedHashMapError>;
|
||||
/// Creates account
|
||||
fn new_account(&self, pass: &str) -> Result<Address, ::std::io::Error>;
|
||||
/// Returns secret for unlocked account
|
||||
fn account_secret(&self, account: &Address) -> Result<crypto::Secret, SigningError>;
|
||||
/// Returns secret for unlocked account
|
||||
fn sign(&self, account: &Address, message: &H256) -> Result<crypto::Signature, SigningError>;
|
||||
}
|
||||
|
||||
/// Thread-safe accounts management
|
||||
pub struct AccountService {
|
||||
secret_store: RwLock<SecretStore>,
|
||||
}
|
||||
|
||||
impl AccountProvider for AccountService {
|
||||
/// Lists all accounts
|
||||
fn accounts(&self) -> Result<Vec<Address>, ::std::io::Error> {
|
||||
Ok(try!(self.secret_store.read().unwrap().accounts()).iter().map(|&(addr, _)| addr).collect::<Vec<Address>>())
|
||||
}
|
||||
/// Unlocks account with the password provided
|
||||
fn unlock_account(&self, account: &Address, pass: &str) -> Result<(), EncryptedHashMapError> {
|
||||
self.secret_store.read().unwrap().unlock_account(account, pass)
|
||||
}
|
||||
/// Creates account
|
||||
fn new_account(&self, pass: &str) -> Result<Address, ::std::io::Error> {
|
||||
self.secret_store.write().unwrap().new_account(pass)
|
||||
}
|
||||
/// Returns secret for unlocked account
|
||||
fn account_secret(&self, account: &Address) -> Result<crypto::Secret, SigningError> {
|
||||
self.secret_store.read().unwrap().account_secret(account)
|
||||
}
|
||||
/// Returns secret for unlocked account
|
||||
fn sign(&self, account: &Address, message: &H256) -> Result<crypto::Signature, SigningError> {
|
||||
self.secret_store.read().unwrap().sign(account, message)
|
||||
}
|
||||
}
|
||||
|
||||
impl AccountService {
|
||||
/// New account service with the default location
|
||||
pub fn new() -> AccountService {
|
||||
let secret_store = RwLock::new(SecretStore::new());
|
||||
secret_store.write().unwrap().try_import_existing();
|
||||
AccountService {
|
||||
secret_store: secret_store
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl SecretStore {
|
||||
/// new instance of Secret Store in default home directory
|
||||
pub fn new() -> SecretStore {
|
||||
|
||||
Reference in New Issue
Block a user