From 2b5e6eff36abe4c23b8789ef1babfafedc90b973 Mon Sep 17 00:00:00 2001 From: Hodlinator <172445034+hodlinator@users.noreply.github.com> Date: Mon, 19 Aug 2024 15:11:54 +0200 Subject: [PATCH] refactor: Make XOnlyPubKey tolerate constexpr std::arrays Length was already asserted inside of base_blob-ctor. --- src/pubkey.cpp | 6 ------ src/pubkey.h | 2 +- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/src/pubkey.cpp b/src/pubkey.cpp index 13e3c2dbe07..148b268e2eb 100644 --- a/src/pubkey.cpp +++ b/src/pubkey.cpp @@ -193,12 +193,6 @@ int ecdsa_signature_parse_der_lax(secp256k1_ecdsa_signature* sig, const unsigned static const std::vector NUMS_H_DATA{ParseHex("50929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac0")}; const XOnlyPubKey XOnlyPubKey::NUMS_H{NUMS_H_DATA}; -XOnlyPubKey::XOnlyPubKey(Span bytes) -{ - assert(bytes.size() == 32); - std::copy(bytes.begin(), bytes.end(), m_keydata.begin()); -} - std::vector XOnlyPubKey::GetKeyIDs() const { std::vector out; diff --git a/src/pubkey.h b/src/pubkey.h index ae34ddd0afd..b4666aad228 100644 --- a/src/pubkey.h +++ b/src/pubkey.h @@ -254,7 +254,7 @@ public: bool IsNull() const { return m_keydata.IsNull(); } /** Construct an x-only pubkey from exactly 32 bytes. */ - explicit XOnlyPubKey(Span bytes); + constexpr explicit XOnlyPubKey(std::span bytes) : m_keydata{bytes} {} /** Construct an x-only pubkey from a normal pubkey. */ explicit XOnlyPubKey(const CPubKey& pubkey) : XOnlyPubKey(Span{pubkey}.subspan(1, 32)) {}