From df84fa99c5a52e4688e240c585f7d22b20401906 Mon Sep 17 00:00:00 2001 From: Andrew Chow Date: Mon, 4 Jan 2021 17:21:29 -0500 Subject: [PATCH] Add GetVersion helper to PSBT --- src/psbt.cpp | 8 ++++++++ src/psbt.h | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/psbt.cpp b/src/psbt.cpp index 6585766807..f3ecbd63d2 100644 --- a/src/psbt.cpp +++ b/src/psbt.cpp @@ -401,3 +401,11 @@ bool DecodeRawPSBT(PartiallySignedTransaction& psbt, const std::string& tx_data, } return true; } + +uint32_t PartiallySignedTransaction::GetVersion() const +{ + if (m_version != std::nullopt) { + return *m_version; + } + return 0; +} diff --git a/src/psbt.h b/src/psbt.h index 834af26219..46cfaf5f97 100644 --- a/src/psbt.h +++ b/src/psbt.h @@ -405,6 +405,7 @@ struct PartiallySignedTransaction std::optional m_version; bool IsNull() const; + uint32_t GetVersion() const; /** Merge psbt into this. The two psbts must have the same underlying CTransaction (i.e. the * same actual Bitcoin transaction.) Returns true if the merge succeeded, false otherwise. */ @@ -436,7 +437,7 @@ struct PartiallySignedTransaction SerializeToVector(os, *tx); // PSBT version - if (m_version != std::nullopt && *m_version > 0) { + if (GetVersion() > 0) { SerializeToVector(s, CompactSizeWriter(PSBT_GLOBAL_VERSION)); SerializeToVector(s, *m_version); }