This pull replaces almost all uses of uint256 and all uses of uint160 to use opaque byte blobs blob256 and blob160 with only the following operations:
- Default initialization to 0, or from a vector of bytes
- Assignment from other blobXXXs
IsNull()compare to special all-zeros valueSetNull()clear to special all-zeros value: Bitcoin needsIsNull()/SetNull()because we often use the all-zeroes value as a marker for errors and empty values.<for sorting in maps.!===test for (in)equalityGetHex/SetHex/ToStringbecause they're just so usefulbegin()/end()raw access to the datasize()returns a fixed sizeGetSerializeSize()SerializeUnserializeserialization just reads and writes the bytesGetCheapHash()this is similar toGetLow64()and returns part of the value as uint64_t, for cheap hashing when the contents are assumed distributed uniformy random.
uint256 (used for proof-of-work mainly), on the other hand, loses all functionality like raw bytes access and serialization. Its memory should not be accessed directly. This is necessary for #888 (big endian support).
uint160 is completely removed as Bitcoin Core does no 160-bit integer arithmetic.
Overall steps (see commits)
Even though the diff is huge, I've tried to follow a logical and easy to review process:
Introduce
base_uint::SetNullandbase_uint::IsNull()as well as other methods that will later be onbase_blob, to prepare for migrationReplace x=0 with .SetNull(), x==0 with IsNull(), x!=0 with !IsNull(). Replace uses of uint256(0) with uint256().
Introduce blob256 and blob160 as well as conversion functions (only needed for blob256, we don't ever compute with uint160).
Replace
GetLow64()withGetCheapHash()Rename uint256 and uint160 to blob256 and blob160 except where big integers are really necessary. For reviewing convenience I separated this out into
A) pure renames uintXXX to blobXXX, can easily be verified (in reverse) with find -name *.h -print0 | xargs -0 sed -i 's/blob256/uint256/g' find -name *.cpp -print0 | xargs -0 sed -i 's/blob256/uint256/g' find -name *.h -print0 | xargs -0 sed -i 's/blob160/uint160/g' find -name *.cpp -print0 | xargs -0 sed -i 's/blob160/uint160/g'
B) string conversions uint256("string") to blob256S("string")
C) Added #includes and predeclared classes
D) Necessary conversions between uint256 and blob256 Focus reviewing here
Remove now-unused methods from base_uint and blob160/blob256, eg GetHash, also remove unused uint160.