Remove unnecessary Engine method (#4184)

* remove register_account_provider

* build rpc module

* new dummy client
This commit is contained in:
keorn
2017-01-18 18:49:50 +01:00
committed by Gav Wood
parent 61bfe42d1d
commit 73b80869f5
11 changed files with 118 additions and 149 deletions

View File

@@ -56,7 +56,7 @@ pub struct BasicAuthority {
params: CommonParams,
gas_limit_bound_divisor: U256,
builtins: BTreeMap<Address, Builtin>,
account_provider: Mutex<Option<Arc<AccountProvider>>>,
account_provider: Mutex<Arc<AccountProvider>>,
password: RwLock<Option<String>>,
validators: Box<ValidatorSet + Send + Sync>,
}
@@ -69,7 +69,7 @@ impl BasicAuthority {
gas_limit_bound_divisor: our_params.gas_limit_bound_divisor,
builtins: builtins,
validators: new_validator_set(our_params.validators),
account_provider: Mutex::new(None),
account_provider: Mutex::new(Arc::new(AccountProvider::transient_provider())),
password: RwLock::new(None),
}
}
@@ -110,20 +110,17 @@ impl Engine for BasicAuthority {
/// Attempt to seal the block internally.
fn generate_seal(&self, block: &ExecutedBlock) -> Seal {
if let Some(ref ap) = *self.account_provider.lock() {
let header = block.header();
let author = header.author();
if self.validators.contains(author) {
let message = header.bare_hash();
// account should be pernamently unlocked, otherwise sealing will fail
if let Ok(signature) = ap.sign(*author, self.password.read().clone(), message) {
return Seal::Regular(vec![::rlp::encode(&(&*signature as &[u8])).to_vec()]);
} else {
trace!(target: "basicauthority", "generate_seal: FAIL: accounts secret key unavailable");
}
let ref ap = *self.account_provider.lock();
let header = block.header();
let author = header.author();
if self.validators.contains(author) {
let message = header.bare_hash();
// account should be pernamently unlocked, otherwise sealing will fail
if let Ok(signature) = ap.sign(*author, self.password.read().clone(), message) {
return Seal::Regular(vec![::rlp::encode(&(&*signature as &[u8])).to_vec()]);
} else {
trace!(target: "basicauthority", "generate_seal: FAIL: accounts secret key unavailable");
}
} else {
trace!(target: "basicauthority", "generate_seal: FAIL: accounts not provided");
}
Seal::None
}
@@ -174,12 +171,9 @@ impl Engine for BasicAuthority {
self.validators.register_call_contract(client);
}
fn set_signer(&self, _address: Address, password: String) {
fn set_signer(&self, ap: Arc<AccountProvider>, _address: Address, password: String) {
*self.password.write() = Some(password);
}
fn register_account_provider(&self, ap: Arc<AccountProvider>) {
*self.account_provider.lock() = Some(ap);
*self.account_provider.lock() = ap;
}
}
@@ -256,8 +250,7 @@ mod tests {
let spec = new_test_authority();
let engine = &*spec.engine;
engine.set_signer(addr, "".into());
engine.register_account_provider(Arc::new(tap));
engine.set_signer(Arc::new(tap), addr, "".into());
let genesis_header = spec.genesis_header();
let mut db_result = get_temp_state_db();
let db = spec.ensure_db_good(db_result.take(), &Default::default()).unwrap();