6 #ifndef BITCOIN_UINT256_H
7 #define BITCOIN_UINT256_H
22 template<
unsigned int BITS>
26 static constexpr
int WIDTH = BITS / 8;
27 static_assert(BITS % 8 == 0,
"base_blob currently only supports whole bytes.");
29 static_assert(
WIDTH ==
sizeof(
m_data),
"Sanity check");
46 return std::all_of(
m_data.begin(),
m_data.end(), [](uint8_t val) {
63 std::string
GetHex()
const;
68 constexpr
const unsigned char*
data()
const {
return m_data.data(); }
69 constexpr
unsigned char*
data() {
return m_data.data(); }
74 constexpr
const unsigned char*
begin()
const {
return m_data.data(); }
77 static constexpr
unsigned int size() {
return WIDTH; }
81 template<
typename Stream>
87 template<
typename Stream>
101 template <
class u
intN_t>
102 std::optional<uintN_t>
FromHex(std::string_view str)
104 if (uintN_t::size() * 2 != str.size() || !
IsHex(str))
return std::nullopt;
106 rv.SetHexDeprecated(str);
117 static std::optional<uint160>
FromHex(std::string_view str) {
return detail::FromHex<uint160>(str); }
129 static std::optional<uint256>
FromHex(std::string_view str) {
return detail::FromHex<uint256>(str); }
constexpr std::size_t size() const noexcept
constexpr C * end() const noexcept
constexpr C * begin() const noexcept
Template base class for fixed-sized opaque blobs.
constexpr base_blob(uint8_t v)
constexpr bool IsNull() const
constexpr unsigned char * end()
static constexpr int WIDTH
static constexpr unsigned int size()
constexpr uint64_t GetUint64(int pos) const
void Unserialize(Stream &s)
std::string ToString() const
void SetHexDeprecated(std::string_view str)
Unlike FromHex this accepts any invalid input, thus it is fragile and deprecated.
constexpr const unsigned char * data() const
constexpr const unsigned char * begin() const
constexpr friend bool operator!=(const base_blob &a, const base_blob &b)
constexpr friend bool operator<(const base_blob &a, const base_blob &b)
constexpr int Compare(const base_blob &other) const
constexpr unsigned char * begin()
constexpr friend bool operator==(const base_blob &a, const base_blob &b)
constexpr unsigned char * data()
void Serialize(Stream &s) const
constexpr const unsigned char * end() const
std::string GetHex() const
constexpr base_blob(Span< const unsigned char > vch)
std::array< uint8_t, WIDTH > m_data
constexpr uint160(Span< const unsigned char > vch)
static std::optional< uint160 > FromHex(std::string_view str)
constexpr uint160()=default
constexpr uint256(Span< const unsigned char > vch)
constexpr uint256()=default
static const uint256 ZERO
static std::optional< uint256 > FromHex(std::string_view str)
constexpr uint256(uint8_t v)
static uint64_t ReadLE64(const unsigned char *ptr)
std::optional< uintN_t > FromHex(std::string_view str)
Writes the hex string (treated as little-endian) into a new uintN_t object and only returns a value i...
Span(T *, EndOrSize) -> Span< T >
Span< std::byte > MakeWritableByteSpan(V &&v) noexcept
uint256 uint256S(std::string_view str)
bool IsHex(std::string_view str)