Skip to content

Commit

Permalink
add constant contructors for uint256
Browse files Browse the repository at this point in the history
  • Loading branch information
patricklodder committed Jul 15, 2024
1 parent 38c3f67 commit 4add977
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/uint256.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,6 @@ template std::string base_blob<256>::GetHex() const;
template std::string base_blob<256>::ToString() const;
template void base_blob<256>::SetHex(const char*);
template void base_blob<256>::SetHex(const std::string&);

const uint256 uint256::ZERO(0);
const uint256 uint256::ONE(1);
7 changes: 7 additions & 0 deletions src/uint256.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ class base_blob
memset(data, 0, sizeof(data));
}

/* constructor for constants between 1 and 255 */
constexpr explicit base_blob(uint8_t v) : data{v} {}

explicit base_blob(const std::vector<unsigned char>& vch);

bool IsNull() const
Expand Down Expand Up @@ -124,6 +127,7 @@ class uint256 : public base_blob<256> {
public:
uint256() {}
uint256(const base_blob<256>& b) : base_blob<256>(b) {}
constexpr explicit uint256(uint8_t v) : base_blob<256>(v) {}
explicit uint256(const std::vector<unsigned char>& vch) : base_blob<256>(vch) {}

/** A cheap hash function that just returns 64 bits from the result, it can be
Expand All @@ -135,6 +139,9 @@ class uint256 : public base_blob<256> {
{
return ReadLE64(data);
}

static const uint256 ZERO;
static const uint256 ONE;
};

/* uint256 from const char *.
Expand Down

0 comments on commit 4add977

Please sign in to comment.