Skip to content

Commit 4b1cc08

Browse files
committed
Make XOnlyPubKey act like byte container
1 parent b295395 commit 4b1cc08

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
@@ -222,6 +222,12 @@ class XOnlyPubKey
222222
uint256 m_keydata;
223223

224224
public:
225+
/** Construct an empty x-only pubkey. */
226+
XOnlyPubKey() = default;
227+
228+
XOnlyPubKey(const XOnlyPubKey&) = default;
229+
XOnlyPubKey& operator=(const XOnlyPubKey&) = default;
230+
225231
/** Construct an x-only pubkey from exactly 32 bytes. */
226232
explicit XOnlyPubKey(Span<const unsigned char> bytes);
227233

@@ -234,7 +240,14 @@ class XOnlyPubKey
234240

235241
const unsigned char& operator[](int pos) const { return *(m_keydata.begin() + pos); }
236242
const unsigned char* data() const { return m_keydata.begin(); }
237-
size_t size() const { return m_keydata.size(); }
243+
static constexpr size_t size() { return decltype(m_keydata)::size(); }
244+
const unsigned char* begin() const { return m_keydata.begin(); }
245+
const unsigned char* end() const { return m_keydata.end(); }
246+
unsigned char* begin() { return m_keydata.begin(); }
247+
unsigned char* end() { return m_keydata.end(); }
248+
bool operator==(const XOnlyPubKey& other) const { return m_keydata == other.m_keydata; }
249+
bool operator!=(const XOnlyPubKey& other) const { return m_keydata != other.m_keydata; }
250+
bool operator<(const XOnlyPubKey& other) const { return m_keydata < other.m_keydata; }
238251
};
239252

240253
struct CExtPubKey {

src/uint256.h

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

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

0 commit comments

Comments
 (0)