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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
use ssz_derive::Ssz;
#[cfg(feature = "serde")]
use serde_derive::{Serialize, Deserialize};
#[cfg(feature = "parity-codec")]
use codec::{Encode, Decode};
use crate::primitives::{Signature, ValidatorId, H256};
use crate::Config;
#[derive(Ssz, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(deny_unknown_fields))]
#[cfg_attr(feature = "parity-codec", derive(Encode, Decode))]
#[cfg_attr(feature = "std", derive(Debug))]
pub struct Validator {
pub pubkey: ValidatorId,
pub withdrawal_credentials: H256,
pub activation_epoch: u64,
pub exit_epoch: u64,
pub withdrawable_epoch: u64,
pub initiated_exit: bool,
pub slashed: bool,
}
impl Validator {
pub fn activate<C: Config>(&mut self, delayed_activation_exit_epoch: u64, is_genesis: bool, config: &C) {
if is_genesis {
self.activation_epoch = config.genesis_epoch();
} else {
self.activation_epoch = delayed_activation_exit_epoch;
}
}
pub fn initiate_exit(&mut self) {
self.initiated_exit = true;
}
pub fn exit(&mut self, delayed_activation_exit_epoch: u64) {
if self.exit_epoch <= delayed_activation_exit_epoch {
return
} else {
self.exit_epoch = delayed_activation_exit_epoch;
}
}
pub fn is_active(&self, epoch: u64) -> bool {
self.activation_epoch <= epoch && epoch < self.exit_epoch
}
}
#[derive(Ssz, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(deny_unknown_fields))]
#[cfg_attr(feature = "parity-codec", derive(Encode, Decode))]
#[cfg_attr(feature = "std", derive(Debug))]
pub struct VoluntaryExit {
pub epoch: u64,
pub validator_index: u64,
#[ssz(truncate)]
pub signature: Signature,
}
#[derive(Ssz, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(deny_unknown_fields))]
#[cfg_attr(feature = "parity-codec", derive(Encode, Decode))]
#[cfg_attr(feature = "std", derive(Debug))]
pub struct Transfer {
pub sender: u64,
pub recipient: u64,
pub amount: u64,
pub fee: u64,
pub slot: u64,
pub pubkey: ValidatorId,
#[ssz(truncate)]
pub signature: Signature,
}