Skip to content

Commit 3f1f94c

Browse files
committed
Port to ethnum
1 parent 43876fd commit 3f1f94c

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ edition = "2021"
88

99
[dependencies]
1010
ethereum-types = { version = "0.13", default-features = false }
11+
ethnum = { version = "1", default-features = false }
1112
primitive-types = { version = "0.11", default-features = false, features = [
1213
"rlp",
1314
] }

src/lib.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ mod miller_rabin;
1212
use byteorder::{ByteOrder, LittleEndian};
1313
use core::ops::BitXor;
1414
pub use dag::LightDAG;
15-
use ethereum_types::{BigEndianHash, H256, H512, H64, U256, U64};
15+
use ethereum_types::{BigEndianHash, H256, H512, H64, U64};
16+
use ethnum::U256;
1617
use miller_rabin::is_prime;
1718
use rlp::Encodable;
1819
use sha3::{Digest, Keccak256, Keccak512};
@@ -306,10 +307,10 @@ pub fn hashimoto_full(
306307

307308
/// Convert across boundary. `f(x) = 2 ^ 256 / x`.
308309
pub fn cross_boundary(val: U256) -> U256 {
309-
if val <= U256::one() {
310-
U256::max_value()
310+
if val <= U256::ONE {
311+
U256::MAX
311312
} else {
312-
((U256::one() << 255) / val) << 1
313+
((U256::ONE << 255) / val) << 1
313314
}
314315
}
315316

@@ -339,7 +340,7 @@ pub fn mine<T: Encodable>(
339340
H512::from(r)
340341
},
341342
);
342-
let result_cmp: U256 = result.into_uint();
343+
let result_cmp = U256::from_be_bytes(result.0);
343344
if result_cmp <= target {
344345
return (nonce_current, result);
345346
}
@@ -360,7 +361,8 @@ pub fn get_seedhash(epoch: usize) -> H256 {
360361
#[cfg(test)]
361362
mod tests {
362363
use crate::{cross_boundary, LightDAG};
363-
use ethereum_types::{H256, H64, U256};
364+
use ethereum_types::{H256, H64};
365+
use ethnum::U256;
364366
use hex_literal::*;
365367

366368
#[test]
@@ -379,6 +381,6 @@ mod tests {
379381
))
380382
);
381383

382-
assert!(U256::from(final_hash.0) <= cross_boundary(2580289863567664_u128.into()));
384+
assert!(U256::from_be_bytes(final_hash.0) <= cross_boundary(2580289863567664_u128.into()));
383385
}
384386
}

0 commit comments

Comments
 (0)