mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-08 01:05:47 +00:00
Fix all compile errors from new Slot/Epoch types
This commit is contained in:
@@ -17,5 +17,6 @@ rand = "0.5.5"
|
||||
serde = "1.0"
|
||||
serde_derive = "1.0"
|
||||
serde_json = "1.0"
|
||||
slog = "^2.2.3"
|
||||
ssz = { path = "../utils/ssz" }
|
||||
vec_shuffle = { path = "../utils/vec_shuffle" }
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
use crate::test_utils::TestRandom;
|
||||
use rand::RngCore;
|
||||
use serde_derive::Serialize;
|
||||
use slog;
|
||||
use ssz::{hash, Decodable, DecodeError, Encodable, SszStream, TreeHash};
|
||||
use std::cmp::{Ord, Ordering};
|
||||
use std::fmt;
|
||||
@@ -162,6 +163,15 @@ macro_rules! impl_math {
|
||||
*self - other.into()
|
||||
}
|
||||
|
||||
pub fn checked_div<T: Into<$type>>(&self, rhs: T) -> Option<$type> {
|
||||
let rhs: $type = rhs.into();
|
||||
if rhs == 0 {
|
||||
None
|
||||
} else {
|
||||
Some(*self / rhs)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_power_of_two(&self) -> bool {
|
||||
self.0.is_power_of_two()
|
||||
}
|
||||
@@ -183,6 +193,17 @@ macro_rules! impl_display {
|
||||
write!(f, "{}", self.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl slog::Value for $type {
|
||||
fn serialize(
|
||||
&self,
|
||||
record: &slog::Record,
|
||||
key: slog::Key,
|
||||
serializer: &mut slog::Serializer,
|
||||
) -> slog::Result {
|
||||
self.0.serialize(record, key, serializer)
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -109,7 +109,7 @@ fn initial_validators_for_testing() -> Vec<Validator> {
|
||||
let validator = Validator {
|
||||
pubkey: keypair.pk.clone(),
|
||||
withdrawal_credentials: Hash256::zero(),
|
||||
proposer_slots: Slot::from(0_u64),
|
||||
proposer_slots: 0,
|
||||
activation_slot: Slot::max_value(),
|
||||
exit_slot: Slot::max_value(),
|
||||
withdrawal_slot: Slot::max_value(),
|
||||
|
||||
@@ -46,7 +46,7 @@ fn status_flag_from_byte(flag: u8) -> Result<Option<StatusFlags>, StatusFlagsDec
|
||||
pub struct Validator {
|
||||
pub pubkey: PublicKey,
|
||||
pub withdrawal_credentials: Hash256,
|
||||
pub proposer_slots: Slot,
|
||||
pub proposer_slots: u64,
|
||||
pub activation_slot: Slot,
|
||||
pub exit_slot: Slot,
|
||||
pub withdrawal_slot: Slot,
|
||||
@@ -70,7 +70,7 @@ impl Default for Validator {
|
||||
Self {
|
||||
pubkey: PublicKey::default(),
|
||||
withdrawal_credentials: Hash256::default(),
|
||||
proposer_slots: Slot::from(0_u64),
|
||||
proposer_slots: 0,
|
||||
activation_slot: Slot::from(std::u64::MAX),
|
||||
exit_slot: Slot::from(std::u64::MAX),
|
||||
withdrawal_slot: Slot::from(std::u64::MAX),
|
||||
|
||||
Reference in New Issue
Block a user