Make the block header struct's internals private (#2000)

* Make the block header struct's internals private

Currently, this involves a lot of explicit cloning, but we
could migrate the return types of the get_* functions to
be copies rather than references since they are mostly copy
types anyway.

I opted to eliminate the constructor in favor of using
Default::default() plus calling a bunch of setters. This
is similar to the model that a Google Protobuf client uses
and I think it looks fine.

* Drop some unnecessary cloning by comparing references

* Fix compiler errors from callsites in tests.
This commit is contained in:
Nipunn Koorapati
2016-08-29 02:35:24 -07:00
committed by Arkadiy Paronyan
parent 2d883c43c9
commit 4389742ca3
21 changed files with 336 additions and 336 deletions

View File

@@ -270,7 +270,7 @@ impl BlockCollection {
match self.head {
None if hash == self.heads[0] => {
trace!("New head {}", hash);
self.head = Some(info.parent_hash);
self.head = Some(info.parent_hash().clone());
},
_ => ()
}
@@ -280,8 +280,8 @@ impl BlockCollection {
body: None,
};
let header_id = HeaderId {
transactions_root: info.transactions_root,
uncles: info.uncles_hash
transactions_root: info.transactions_root().clone(),
uncles: info.uncles_hash().clone(),
};
if header_id.transactions_root == rlp::SHA3_NULL_RLP && header_id.uncles == rlp::SHA3_EMPTY_LIST_RLP {
// empty body, just mark as downloaded
@@ -294,7 +294,7 @@ impl BlockCollection {
self.header_ids.insert(header_id, hash.clone());
}
self.parents.insert(info.parent_hash.clone(), hash.clone());
self.parents.insert(info.parent_hash().clone(), hash.clone());
self.blocks.insert(hash.clone(), block);
trace!(target: "sync", "New header: {}", hash.hex());
Ok(hash)