Skip to content

Commit

Permalink
Temporarily add SetNull/IsNull/GetCheapHash to base_uint
Browse files Browse the repository at this point in the history
Also add a stub for arith_uint256 and its conversion functions,
for now completely based on uint256.

Eases step-by-step migration to blob.
  • Loading branch information
laanwj committed Jan 5, 2015
1 parent a043fac commit 5d3064b
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/arith_uint256.h
Original file line number Diff line number Diff line change
@@ -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<unsigned char>& vch) : uint256(vch) {}
};

#define ArithToUint256(x) (x)
#define UintToArith256(x) (x)

#endif // BITCOIN_UINT256_H
20 changes: 20 additions & 0 deletions src/uint256.h
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,23 @@ class base_uint
{
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. */
Expand Down Expand Up @@ -330,4 +347,7 @@ class uint256 : public base_uint<256> {
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

0 comments on commit 5d3064b

Please sign in to comment.