Skip to content

Commit c3945cb

Browse files
sipasanket1729
authored andcommitted
Make XOnlyPubKey act like byte container
bitcoin/bitcoin#22051 (1/9)
1 parent 2c5c7eb commit c3945cb

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/pubkey.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,12 @@ class XOnlyPubKey
217217
uint256 m_keydata;
218218

219219
public:
220+
/** Construct an empty x-only pubkey. */
221+
XOnlyPubKey() = default;
222+
223+
XOnlyPubKey(const XOnlyPubKey&) = default;
224+
XOnlyPubKey& operator=(const XOnlyPubKey&) = default;
225+
220226
/** Construct an x-only pubkey from exactly 32 bytes. */
221227
XOnlyPubKey(Span<const unsigned char> bytes);
222228

@@ -229,7 +235,14 @@ class XOnlyPubKey
229235

230236
const unsigned char& operator[](int pos) const { return *(m_keydata.begin() + pos); }
231237
const unsigned char* data() const { return m_keydata.begin(); }
232-
size_t size() const { return m_keydata.size(); }
238+
static constexpr size_t size() { return decltype(m_keydata)::size(); }
239+
const unsigned char* begin() const { return m_keydata.begin(); }
240+
const unsigned char* end() const { return m_keydata.end(); }
241+
unsigned char* begin() { return m_keydata.begin(); }
242+
unsigned char* end() { return m_keydata.end(); }
243+
bool operator==(const XOnlyPubKey& other) const { return m_keydata == other.m_keydata; }
244+
bool operator!=(const XOnlyPubKey& other) const { return m_keydata != other.m_keydata; }
245+
bool operator<(const XOnlyPubKey& other) const { return m_keydata < other.m_keydata; }
233246
};
234247

235248
struct CExtPubKey {

src/uint256.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class base_blob
7676
return &m_data[WIDTH];
7777
}
7878

79-
unsigned int size() const
79+
static constexpr unsigned int size()
8080
{
8181
return sizeof(m_data);
8282
}

0 commit comments

Comments
 (0)