add the methods to engines

This commit is contained in:
keorn
2016-12-07 10:34:06 +01:00
parent b089aa7a6b
commit 71a96588b0
3 changed files with 22 additions and 7 deletions

View File

@@ -59,6 +59,7 @@ pub struct BasicAuthority {
our_params: BasicAuthorityParams,
builtins: BTreeMap<Address, Builtin>,
account_provider: Mutex<Option<Arc<AccountProvider>>>,
password: RwLock<Option<String>>,
}
impl BasicAuthority {
@@ -68,7 +69,8 @@ impl BasicAuthority {
params: params,
our_params: our_params,
builtins: builtins,
account_provider: Mutex::new(None)
account_provider: Mutex::new(None),
password: RwLock::new(None),
}
}
}
@@ -115,7 +117,7 @@ impl Engine for BasicAuthority {
let header = block.header();
let message = header.bare_hash();
// account should be pernamently unlocked, otherwise sealing will fail
if let Ok(signature) = ap.sign(*block.header().author(), None, message) {
if let Ok(signature) = ap.sign(*block.header().author(), self.password.read().clone(), message) {
return Some(vec![::rlp::encode(&(&*signature as &[u8])).to_vec()]);
} else {
trace!(target: "basicauthority", "generate_seal: FAIL: accounts secret key unavailable");
@@ -177,6 +179,10 @@ impl Engine for BasicAuthority {
t.sender().map(|_|()) // Perform EC recovery and cache sender
}
fn set_signer(&self, _address: Address, password: String) {
*self.password.write() = Some(password);
}
fn register_account_provider(&self, ap: Arc<AccountProvider>) {
*self.account_provider.lock() = Some(ap);
}