6#ifndef BITCOIN_UINT256_H
7#define BITCOIN_UINT256_H
22 static constexpr int WIDTH = BITS / 8;
23 static_assert(BITS % 8 == 0,
24 "base_blob currently only supports whole bytes.");
26 static_assert(
WIDTH ==
sizeof(
m_data),
"Sanity check");
37 std::copy(vch.
begin(), vch.
end(), m_data.begin());
41 return std::all_of(m_data.begin(), m_data.end(),
42 [](uint8_t val) { return val == 0; });
45 constexpr void SetNull() { std::fill(m_data.begin(), m_data.end(), 0); }
48 for (
size_t i = 0; i < WIDTH; i++) {
49 uint8_t a = m_data[WIDTH - 1 - i];
50 uint8_t b = other.
m_data[WIDTH - 1 - i];
81 std::string GetHex()
const;
82 void SetHex(
const char *psz);
83 void SetHex(
const std::string &str);
84 std::string
ToString()
const {
return GetHex(); }
86 constexpr const uint8_t *
data()
const {
return m_data.data(); }
87 constexpr uint8_t *
data() {
return m_data.data(); }
89 constexpr uint8_t *
begin() {
return m_data.data(); }
90 constexpr uint8_t *
end() {
return m_data.data() + WIDTH; }
92 constexpr const uint8_t *
begin()
const {
return m_data.data(); }
93 constexpr const uint8_t *
end()
const {
return m_data.data() + WIDTH; }
95 static constexpr unsigned int size() {
return WIDTH; }
98 return ReadLE64(m_data.data() + pos * 8);
101 template <
typename Stream>
void Serialize(Stream &s)
const {
constexpr std::size_t size() const noexcept
constexpr C * begin() const noexcept
constexpr C * end() const noexcept
Template base class for fixed-sized opaque blobs.
constexpr base_blob(uint8_t v)
constexpr bool IsNull() const
constexpr const uint8_t * data() const
friend constexpr bool operator!=(const base_blob &a, const base_blob &b)
static constexpr int WIDTH
constexpr base_blob(Span< const uint8_t > vch)
static constexpr unsigned int size()
friend constexpr bool operator<(const base_blob &a, const base_blob &b)
void SetHex(const char *psz)
friend constexpr bool operator>(const base_blob &a, const base_blob &b)
constexpr uint64_t GetUint64(int pos) const
void Unserialize(Stream &s)
constexpr uint8_t * begin()
constexpr uint8_t * data()
friend constexpr bool operator<=(const base_blob &a, const base_blob &b)
std::string ToString() const
friend constexpr bool operator==(const base_blob &a, const base_blob &b)
constexpr const uint8_t * begin() const
constexpr uint8_t * end()
friend constexpr bool operator>=(const base_blob &a, const base_blob &b)
constexpr int Compare(const base_blob &other) const
constexpr const uint8_t * end() const
void Serialize(Stream &s) const
std::array< uint8_t, WIDTH > m_data
constexpr uint160(Span< const uint8_t > vch)
constexpr uint160()=default
constexpr uint256()=default
constexpr uint256(Span< const uint8_t > vch)
static const uint256 ZERO
constexpr uint256(uint8_t v)
static uint64_t ReadLE64(const uint8_t *ptr)
Span(T *, EndOrSize) -> Span< T >
Span< std::byte > MakeWritableByteSpan(V &&v) noexcept
uint160 uint160S(const char *str)
uint256 uint256S(const char *str)
uint256 from const char *.