Skip to content

Commit

Permalink
Make XOnlyPubKey act like byte container
Browse files Browse the repository at this point in the history
  • Loading branch information
sipa authored and sanket1729 committed Aug 26, 2021
1 parent eccdabc commit db33678
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
15 changes: 14 additions & 1 deletion src/pubkey.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,12 @@ class XOnlyPubKey
uint256 m_keydata;

public:
/** Construct an empty x-only pubkey. */
XOnlyPubKey() = default;

XOnlyPubKey(const XOnlyPubKey&) = default;
XOnlyPubKey& operator=(const XOnlyPubKey&) = default;

/** Construct an x-only pubkey from exactly 32 bytes. */
XOnlyPubKey(Span<const unsigned char> bytes);

Expand All @@ -229,7 +235,14 @@ class XOnlyPubKey

const unsigned char& operator[](int pos) const { return *(m_keydata.begin() + pos); }
const unsigned char* data() const { return m_keydata.begin(); }
size_t size() const { return m_keydata.size(); }
static constexpr size_t size() { return decltype(m_keydata)::size(); }
const unsigned char* begin() const { return m_keydata.begin(); }
const unsigned char* end() const { return m_keydata.end(); }
unsigned char* begin() { return m_keydata.begin(); }
unsigned char* end() { return m_keydata.end(); }
bool operator==(const XOnlyPubKey& other) const { return m_keydata == other.m_keydata; }
bool operator!=(const XOnlyPubKey& other) const { return m_keydata != other.m_keydata; }
bool operator<(const XOnlyPubKey& other) const { return m_keydata < other.m_keydata; }
};

struct CExtPubKey {
Expand Down
2 changes: 1 addition & 1 deletion src/uint256.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class base_blob
return &m_data[WIDTH];
}

unsigned int size() const
static constexpr unsigned int size()
{
return sizeof(m_data);
}
Expand Down

0 comments on commit db33678

Please sign in to comment.