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

Rename Hash::zero() to Hash::default() #858

Merged
merged 1 commit into from
Mar 23, 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
11 changes: 6 additions & 5 deletions core/src/core/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,6 @@ impl Hash {
self.0.to_vec()
}

/// The "zero" hash. No known preimage.
pub fn zero() -> Hash {
ZERO_HASH
}

/// Convert a hash to hex string format.
pub fn to_hex(&self) -> String {
util::to_hex(self.to_vec())
Expand Down Expand Up @@ -154,6 +149,12 @@ impl Add for Hash {
}
}

impl Default for Hash {
fn default() -> Hash {
ZERO_HASH
}
}

/// Serializer that outputs a hash of the serialized object
pub struct HashWriter {
state: Blake2b,
Expand Down
4 changes: 2 additions & 2 deletions core/src/core/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ mod test {
).unwrap();
assert_eq!(foo.hash(), expected_hash);

let other_hash = Hash::zero();
let other_hash = Hash::default();
assert_eq!(
foo.short_id(&other_hash, foo.0),
ShortId::from_hex("4cc808b62476").unwrap()
Expand All @@ -162,7 +162,7 @@ mod test {
).unwrap();
assert_eq!(foo.hash(), expected_hash);

let other_hash = Hash::zero();
let other_hash = Hash::default();
assert_eq!(
foo.short_id(&other_hash, foo.0),
ShortId::from_hex("02955a094534").unwrap()
Expand Down
6 changes: 3 additions & 3 deletions core/src/core/pmmr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ impl MerkleProof {
/// Basically some reasonable defaults. Will not verify successfully.
pub fn empty() -> MerkleProof {
MerkleProof {
root: Hash::zero(),
node: Hash::zero(),
root: Hash::default(),
node: Hash::default(),
peaks: vec![],
path: vec![],
}
Expand Down Expand Up @@ -335,7 +335,7 @@ where

let path = family_branch
.iter()
.map(|x| (self.get_from_file(x.1).unwrap_or(Hash::zero()), x.1))
.map(|x| (self.get_from_file(x.1).unwrap_or(Hash::default()), x.1))
.collect::<Vec<_>>();

let peaks = peaks(self.last_pos)
Expand Down
4 changes: 2 additions & 2 deletions core/src/core/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -583,10 +583,10 @@ impl Input {
}

/// Convenience functon to return the (optional) block_hash for this input.
/// Will return the "zero" hash if we do not have one.
/// Will return the default hash if we do not have one.
pub fn block_hash(&self) -> Hash {
let block_hash = self.block_hash.clone();
block_hash.unwrap_or(Hash::zero())
block_hash.unwrap_or(Hash::default())
}

/// Convenience function to return the (optional) merkle_proof for this input.
Expand Down
2 changes: 1 addition & 1 deletion pool/src/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ impl DummyChainImpl {
impl BlockChain for DummyChainImpl {
fn is_unspent(&self, output_ref: &OutputIdentifier) -> Result<hash::Hash, PoolError> {
match self.output.read().unwrap().get_output(&output_ref.commit) {
Some(_) => Ok(hash::Hash::zero()),
Some(_) => Ok(hash::Hash::default()),
None => Err(PoolError::GenericPoolError),
}
}
Expand Down
6 changes: 3 additions & 3 deletions pool/src/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1654,9 +1654,9 @@ mod tests {
let mut tx_elements = Vec::new();

let merkle_proof = MerkleProof {
node: Hash::zero(),
root: Hash::zero(),
peaks: vec![Hash::zero()],
node: Hash::default(),
root: Hash::default(),
peaks: vec![Hash::default()],
..MerkleProof::default()
};

Expand Down