Skip to content

Commit fab6ddb

Browse files
author
MarcoFalke
committed
refactor: Expose FromHex in transaction_identifier
This is needed for the next commit.
1 parent fad2991 commit fab6ddb

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/util/transaction_identifier.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ class transaction_identifier
4242
/** Wrapped `uint256` methods. */
4343
constexpr bool IsNull() const { return m_wrapped.IsNull(); }
4444
constexpr void SetNull() { m_wrapped.SetNull(); }
45+
static std::optional<transaction_identifier> FromHex(std::string_view hex)
46+
{
47+
auto u{uint256::FromHex(hex)};
48+
if (!u) return std::nullopt;
49+
return FromUint256(*u);
50+
}
4551
std::string GetHex() const { return m_wrapped.GetHex(); }
4652
std::string ToString() const { return m_wrapped.ToString(); }
4753
static constexpr auto size() { return decltype(m_wrapped)::size(); }
@@ -66,6 +72,7 @@ using Txid = transaction_identifier<false>;
6672
/** Wtxid commits to all transaction fields including the witness. */
6773
using Wtxid = transaction_identifier<true>;
6874

75+
/** DEPRECATED due to missing length-check and hex-check, please use the safer FromHex, or FromUint256 */
6976
inline Txid TxidFromString(std::string_view str)
7077
{
7178
return Txid::FromUint256(uint256S(str));

0 commit comments

Comments
 (0)