1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
mod simple_list;
mod safe_contract;
mod contract;
use std::sync::Weak;
use util::{Address, Arc};
use ethjson::spec::ValidatorSet as ValidatorSpec;
use client::Client;
use self::simple_list::SimpleList;
use self::contract::ValidatorContract;
use self::safe_contract::ValidatorSafeContract;
pub fn new_validator_set(spec: ValidatorSpec) -> Box<ValidatorSet + Send + Sync> {
match spec {
ValidatorSpec::List(list) => Box::new(SimpleList::new(list.into_iter().map(Into::into).collect())),
ValidatorSpec::SafeContract(address) => Box::new(Arc::new(ValidatorSafeContract::new(address.into()))),
ValidatorSpec::Contract(address) => Box::new(Arc::new(ValidatorContract::new(address.into()))),
}
}
pub trait ValidatorSet {
fn contains(&self, address: &Address) -> bool;
fn get(&self, nonce: usize) -> Address;
fn count(&self) -> usize;
fn report_malicious(&self, _validator: &Address) {}
fn report_benign(&self, _validator: &Address) {}
fn register_contract(&self, _client: Weak<Client>) {}
}