-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add beaconentries * remove serialziation of prev_round from beaconentry * fix prev_data * add post proof struct * updated blockheader with post proof * blockheaders deserialize properly * post proof comment * make lint * ignore test * suggestions from austin * Last fixes
- Loading branch information
Showing
9 changed files
with
118 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[package] | ||
name = "beacon" | ||
version = "0.1.0" | ||
authors = ["ChainSafe Systems <info@chainsafe.io>"] | ||
edition = "2018" | ||
|
||
[dependencies] | ||
encoding = { package = "forest_encoding", path = "../../encoding" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Copyright 2020 ChainSafe Systems | ||
// SPDX-License-Identifier: Apache-2.0, MIT | ||
|
||
use encoding::{ | ||
de::{Deserialize, Deserializer}, | ||
ser::{Serialize, Serializer}, | ||
BytesDe, BytesSer, | ||
}; | ||
|
||
/// The result from getting an entry from Drand. | ||
#[derive(Clone, Debug, Default, Eq, PartialEq)] | ||
pub struct BeaconEntry { | ||
round: u64, | ||
data: Vec<u8>, | ||
prev_round: u64, | ||
} | ||
|
||
impl BeaconEntry { | ||
pub fn new(round: u64, data: Vec<u8>, prev_round: u64) -> Self { | ||
Self { | ||
round, | ||
data, | ||
prev_round, | ||
} | ||
} | ||
/// Returns the current round number | ||
pub fn round(&self) -> u64 { | ||
self.round | ||
} | ||
/// The signature of message H(prev_round, prev_round.data, round). | ||
pub fn data(&self) -> &[u8] { | ||
&self.data | ||
} | ||
/// Returns the previous round number | ||
pub fn prev_round(&self) -> u64 { | ||
self.prev_round | ||
} | ||
} | ||
|
||
impl Serialize for BeaconEntry { | ||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> | ||
where | ||
S: Serializer, | ||
{ | ||
(&self.round, BytesSer(&self.data)).serialize(serializer) | ||
} | ||
} | ||
|
||
impl<'de> Deserialize<'de> for BeaconEntry { | ||
fn deserialize<D>(deserializer: D) -> Result<Self, <D as Deserializer<'de>>::Error> | ||
where | ||
D: Deserializer<'de>, | ||
{ | ||
let (round, data): (u64, BytesDe) = Deserialize::deserialize(deserializer)?; | ||
let prev_round = if round == 0 { 0 } else { round - 1 }; | ||
Ok(Self { | ||
round, | ||
data: data.0, | ||
prev_round, | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// Copyright 2020 ChainSafe Systems | ||
// SPDX-License-Identifier: Apache-2.0, MIT | ||
|
||
mod beacon_entries; | ||
|
||
pub use beacon_entries::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters