From 5d3064bc44e0b608a428e230f384bd3f846dedca Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Mon, 15 Dec 2014 10:05:51 +0100 Subject: [PATCH] Temporarily add SetNull/IsNull/GetCheapHash to base_uint Also add a stub for arith_uint256 and its conversion functions, for now completely based on uint256. Eases step-by-step migration to blob. --- src/arith_uint256.h | 19 +++++++++++++++++++ src/uint256.h | 20 ++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 src/arith_uint256.h diff --git a/src/arith_uint256.h b/src/arith_uint256.h new file mode 100644 index 000000000..3bb384ca8 --- /dev/null +++ b/src/arith_uint256.h @@ -0,0 +1,19 @@ +#ifndef BITCOIN_ARITH_UINT256_H +#define BITCOIN_ARITH_UINT256_H + +// Temporary for migration to opaque uint160/256 +#include "uint256.h" + +class arith_uint256 : public uint256 { +public: + arith_uint256() {} + arith_uint256(const base_uint<256>& b) : uint256(b) {} + arith_uint256(uint64_t b) : uint256(b) {} + explicit arith_uint256(const std::string& str) : uint256(str) {} + explicit arith_uint256(const std::vector& vch) : uint256(vch) {} +}; + +#define ArithToUint256(x) (x) +#define UintToArith256(x) (x) + +#endif // BITCOIN_UINT256_H diff --git a/src/uint256.h b/src/uint256.h index 139270ac4..8189b27cb 100644 --- a/src/uint256.h +++ b/src/uint256.h @@ -283,6 +283,23 @@ public: { s.read((char*)pn, sizeof(pn)); } + + // Temporary for migration to opaque uint160/256 + uint64_t GetCheapHash() const + { + return GetLow64(); + } + void SetNull() + { + memset(pn, 0, sizeof(pn)); + } + bool IsNull() const + { + for (int i = 0; i < WIDTH; i++) + if (pn[i] != 0) + return false; + return true; + } }; /** 160-bit unsigned big integer. */ @@ -330,4 +347,7 @@ public: uint64_t GetHash(const uint256& salt) const; }; +// Temporary for migration to opaque uint160/256 +inline uint256 uint256S(const std::string &x) { return uint256(x); } + #endif // BITCOIN_UINT256_H