-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
restored partialeq instead of hashing
- Loading branch information
1 parent
e1a0c56
commit ed7d1b6
Showing
9 changed files
with
63 additions
and
181 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
29 changes: 11 additions & 18 deletions
29
packages/rs-platform-version/src/version/fee/hashing/mod.rs
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 |
---|---|---|
@@ -1,29 +1,22 @@ | ||
use bincode::{Decode, Encode}; | ||
use sha2::{Digest, Sha256}; | ||
|
||
pub mod v1; | ||
|
||
#[derive(Clone, Debug, Encode, Decode, Default)] | ||
pub struct FeeHashingVersion { | ||
pub single_sha256_base: u64, | ||
pub blake3_base: u64, | ||
pub sha256_ripe_md160_base: u64, | ||
pub sha256_per_block: u64, | ||
pub blake3_per_block: u64, | ||
} | ||
|
||
impl FeeHashingVersion { | ||
pub(crate) fn to_hash(&self) -> u64 { | ||
let mut hasher = Sha256::new(); | ||
Digest::update(&mut hasher, &self.single_sha256_base.to_be_bytes()); | ||
Digest::update(&mut hasher, &self.blake3_base.to_be_bytes()); | ||
Digest::update(&mut hasher, &self.sha256_ripe_md160_base.to_be_bytes()); | ||
Digest::update(&mut hasher, &self.sha256_per_block.to_be_bytes()); | ||
Digest::update(&mut hasher, &self.blake3_per_block.to_be_bytes()); | ||
pub sha256_per_block: u64, | ||
pub sha256_ripe_md160_base: u64, | ||
pub single_sha256_base: u64, | ||
|
||
let result = hasher.finalize(); | ||
// Use the first 8 bytes of the hash as the u64 representation | ||
let hash_bytes: [u8; 8] = result[0..8].try_into().unwrap(); | ||
u64::from_be_bytes(hash_bytes) | ||
} | ||
impl PartialEq for FeeHashingVersion { | ||
fn eq(&self, other: &Self) -> bool { | ||
self.blake3_base == other.blake3_base | ||
&& self.blake3_per_block == other.blake3_per_block | ||
&& self.sha256_per_block == other.sha256_per_block | ||
&& self.sha256_ripe_md160_base == other.sha256_ripe_md160_base | ||
&& self.single_sha256_base == other.single_sha256_base | ||
} | ||
} |
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
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