Skip to content

Commit

Permalink
Replace deprecated bigint with uint (#1874)
Browse files Browse the repository at this point in the history
Merge pull request #1874

Replace deprecated `bigint` with `uint`

* pull/1874/head:
  fix compilation
  replace deprecated bigint with uint
  • Loading branch information
sdbondi committed May 18, 2020
2 parents d7758bf + 9541d03 commit 95a63ff
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion base_layer/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ arrayref = "0.3.5"
bincode = "1.1.4"
log = "0.4"
blake2 = "^0.8.0"
bigint = "^4.4.1"
uint = { version = "0.8", default-features = false }
ttl_cache = "0.5.1"
tokio = { version="^0.2", features = ["blocking", "time"] }
futures = {version = "^0.3.1", features = ["async-await"] }
Expand Down
5 changes: 5 additions & 0 deletions base_layer/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,8 @@ pub mod transactions;
// Re-export the crypto crate to make exposing traits etc easier for clients of this crate
pub use crypto::tari_utilities;
pub use tari_crypto as crypto;

uint::construct_uint! {
/// 256-bit unsigned integer.
pub(crate) struct U256(4);
}
5 changes: 2 additions & 3 deletions base_layer/core/src/proof_of_work/blake_pow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

use crate::{blocks::BlockHeader, proof_of_work::Difficulty};
use bigint::uint::U256;
use crate::{blocks::BlockHeader, proof_of_work::Difficulty, U256};
use blake2::Blake2b;
use digest::Digest;
use tari_crypto::{common::Blake256, tari_utilities::Hashable};
Expand All @@ -43,7 +42,7 @@ pub fn blake_difficulty_with_hash(header: &BlockHeader) -> (Difficulty, Vec<u8>)
let hash = Blake256::digest(&hash).to_vec();
let scalar = U256::from_big_endian(&hash); // Big endian so the hash has leading zeroes
let result = MAX_TARGET / scalar;
let difficulty = u64::from(result).into();
let difficulty = result.low_u64().into();
(difficulty, hash)
}

Expand Down
4 changes: 2 additions & 2 deletions base_layer/core/src/proof_of_work/monero_rx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
use crate::{
blocks::BlockHeader,
proof_of_work::{monero_rx::MergeMineError::HashingError, Difficulty},
U256,
};
use bigint::uint::U256;
use derive_error::Error;
use monero::blockdata::{block::BlockHeader as MoneroBlockHeader, Transaction as MoneroTransaction};
#[cfg(feature = "monero_merge_mining")]
Expand Down Expand Up @@ -94,7 +94,7 @@ fn monero_difficulty_calculation(header: &BlockHeader) -> Result<Difficulty, Mer
let hash = vm.calculate_hash(&input)?;
let scalar = U256::from_big_endian(&hash); // Big endian so the hash has leading zeroes
let result = MAX_TARGET / scalar;
let difficulty = u64::from(result).into();
let difficulty = result.low_u64().into();
Ok(difficulty)
}
#[cfg(not(feature = "monero_merge_mining"))]
Expand Down

0 comments on commit 95a63ff

Please sign in to comment.