@@ -12,7 +12,8 @@ mod miller_rabin;
1212use byteorder:: { ByteOrder , LittleEndian } ;
1313use core:: ops:: BitXor ;
1414pub 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 ;
1617use miller_rabin:: is_prime;
1718use rlp:: Encodable ;
1819use sha3:: { Digest , Keccak256 , Keccak512 } ;
@@ -306,10 +307,10 @@ pub fn hashimoto_full(
306307
307308/// Convert across boundary. `f(x) = 2 ^ 256 / x`.
308309pub 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) ]
361362mod 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