Fix all compile errors from new Slot/Epoch types

This commit is contained in:
Paul Hauner
2019-02-07 11:22:48 +11:00
parent 9b1d8cd3c1
commit 85450ec254
30 changed files with 177 additions and 135 deletions

View File

@@ -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" }

View File

@@ -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)
}
}
};
}

View File

@@ -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(),

View File

@@ -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),