From 92cdb1aace3c7343e9c9472061508d3b01d9883d Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Tue, 16 Dec 2014 17:29:51 +0100 Subject: [PATCH] Add conversion functions arith_uint256<->uint_256 --- src/arith_uint256.cpp | 16 ++++++++++++++++ src/arith_uint256.h | 8 ++++++++ 2 files changed, 24 insertions(+) diff --git a/src/arith_uint256.cpp b/src/arith_uint256.cpp index 0dba429a8d..f0b6a6a3bd 100644 --- a/src/arith_uint256.cpp +++ b/src/arith_uint256.cpp @@ -5,6 +5,7 @@ #include "arith_uint256.h" +#include "uint256.h" #include "utilstrencodings.h" #include @@ -355,3 +356,18 @@ uint64_t arith_uint256::GetHash(const arith_uint256& salt) const return ((((uint64_t)b) << 32) | c); } + +uint256 ArithToUint256(const arith_uint256 &a) +{ + uint256 b; + // TODO: needs bswap32 on big-endian + memcpy(b.begin(), a.pn, a.size()); + return b; +} +arith_uint256 UintToArith256(const uint256 &a) +{ + arith_uint256 b; + // TODO: needs bswap32 on big-endian + memcpy(b.pn, a.begin(), a.size()); + return b; +} diff --git a/src/arith_uint256.h b/src/arith_uint256.h index 9e32b124c2..5cb04f3c3c 100644 --- a/src/arith_uint256.h +++ b/src/arith_uint256.h @@ -13,6 +13,8 @@ #include #include +class uint256; + class uint_error : public std::runtime_error { public: explicit uint_error(const std::string& str) : std::runtime_error(str) {} @@ -345,6 +347,12 @@ public: uint32_t GetCompact(bool fNegative = false) const; uint64_t GetHash(const arith_uint256& salt) const; + + friend uint256 ArithToUint256(const arith_uint256 &); + friend arith_uint256 UintToArith256(const uint256 &); }; +uint256 ArithToUint256(const arith_uint256 &); +arith_uint256 UintToArith256(const uint256 &); + #endif // BITCOIN_UINT256_H