Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

revert block builder #2

Merged
merged 2 commits into from
Nov 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions core/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ impl Block {
&self.header
}

pub fn mut_header(&mut self) -> &mut Header {
&mut self.header
}

pub fn is_genesis(&self) -> bool {
self.header.is_genesis()
}
Expand Down Expand Up @@ -102,15 +98,11 @@ impl BlockBuilder {
}

pub fn uncle(mut self, uncle: UncleBlock) -> Self {
*self.inner.mut_header().mut_raw().mut_uncles_count() =
self.inner.header().raw().uncles_count() + 1;
self.inner.uncles.push(uncle);
self
}

pub fn uncles(mut self, uncles: Vec<UncleBlock>) -> Self {
*self.inner.mut_header().mut_raw().mut_uncles_count() =
self.inner.header().raw().uncles_count() + uncles.len() as u32;
self.inner.uncles.extend(uncles);
self
}
Expand Down
8 changes: 0 additions & 8 deletions core/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,18 +138,10 @@ impl Header {
self.raw.uncles_hash
}

pub fn raw(&self) -> &RawHeader {
&self.raw
}

pub fn into_raw(self) -> RawHeader {
self.raw
}

pub fn mut_raw(&mut self) -> &mut RawHeader {
&mut self.raw
}

pub fn uncles_count(&self) -> u32 {
self.raw.uncles_count
}
Expand Down
6 changes: 3 additions & 3 deletions verification/src/tests/uncle_verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,12 @@ fn test_uncle_verifier() {

let verifier = UnclesVerifier::new(shared.clone());

let mut block = BlockBuilder::default()
let block = BlockBuilder::default()
.block(chain1.last().cloned().unwrap())
.uncle(chain2.last().cloned().unwrap().into())
.build();

*block.mut_header().mut_raw().mut_uncles_count() = 0;
// Uncles not match uncles_hash
// Uncles not match uncles_count
assert_eq!(
verifier.verify(&block),
Err(Error::Uncles(UnclesError::MissMatchCount {
Expand All @@ -113,6 +112,7 @@ fn test_uncle_verifier() {

let block = BlockBuilder::default()
.block(chain1.last().cloned().unwrap())
.header(HeaderBuilder::default().uncles_count(1).build())
.uncle(chain2.last().cloned().unwrap().into())
.build();
// Uncles not match uncles_hash
Expand Down