mirror of
https://github.com/hinto-janai/cuprate.git
synced 2025-01-23 19:05:55 +00:00
28 lines
649 B
Rust
28 lines
649 B
Rust
use crypto_bigint::{CheckedMul, U256};
|
|
|
|
pub mod difficulty;
|
|
|
|
#[derive(Debug)]
|
|
pub struct BlockPOWInfo {
|
|
pub timestamp: u64,
|
|
pub cumulative_difficulty: u128,
|
|
}
|
|
|
|
pub fn check_block_pow(hash: &[u8; 32], difficulty: u128) -> bool {
|
|
let int_hash = U256::from_le_slice(hash);
|
|
|
|
let difficulty = U256::from_u128(difficulty);
|
|
|
|
int_hash.checked_mul(&difficulty).is_some().unwrap_u8() == 1
|
|
}
|
|
|
|
#[test]
|
|
fn chekc() {
|
|
let hash = hex::decode("5aeebb3de73859d92f3f82fdb97286d81264ecb72a42e4b9f1e6d62eb682d7c0")
|
|
.unwrap()
|
|
.try_into()
|
|
.unwrap();
|
|
let diff = 257344482654;
|
|
|
|
assert!(check_block_pow(&hash, diff))
|
|
}
|