Skip to content

Commit

Permalink
cleanup HeaderVersion::default() (#3149)
Browse files Browse the repository at this point in the history
* header version now explicit, no "default" version
"empty" block can safely have verion 0 as it needs to be set later

* default block header uses version 1

* HeaderVersion(1)
  • Loading branch information
antiochp authored Dec 2, 2019
1 parent cbc17ff commit 52ea906
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 8 deletions.
8 changes: 1 addition & 7 deletions core/src/core/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,6 @@ impl Hashed for HeaderEntry {
#[derive(Clone, Copy, Debug, Eq, PartialEq, Serialize)]
pub struct HeaderVersion(pub u16);

impl Default for HeaderVersion {
fn default() -> HeaderVersion {
HeaderVersion(1)
}
}

impl From<HeaderVersion> for u16 {
fn from(v: HeaderVersion) -> u16 {
v.0
Expand Down Expand Up @@ -239,7 +233,7 @@ impl DefaultHashable for BlockHeader {}
impl Default for BlockHeader {
fn default() -> BlockHeader {
BlockHeader {
version: HeaderVersion::default(),
version: HeaderVersion(1),
height: 0,
timestamp: DateTime::<Utc>::from_utc(NaiveDateTime::from_timestamp(0, 0), Utc),
prev_hash: ZERO_HASH,
Expand Down
2 changes: 1 addition & 1 deletion core/tests/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ fn serialize_deserialize_header_version() {
ser::serialize_default(&mut vec1, &1_u16).expect("serialization failed");

let mut vec2 = Vec::new();
ser::serialize_default(&mut vec2, &HeaderVersion::default()).expect("serialization failed");
ser::serialize_default(&mut vec2, &HeaderVersion(1)).expect("serialization failed");

// Check that a header_version serializes to a
// single u16 value with no extraneous bytes wrapping it.
Expand Down

0 comments on commit 52ea906

Please sign in to comment.