From 8e2d7007f3a957937006320334562b40d5f5c002 Mon Sep 17 00:00:00 2001 From: Jeremiah Buddenhagen Date: Fri, 15 Dec 2017 13:51:26 -0800 Subject: [PATCH] add txComments --- src/primitives/transaction.cpp | 13 ++++++++----- src/primitives/transaction.h | 8 ++++++++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/primitives/transaction.cpp b/src/primitives/transaction.cpp index 9b6a814e1..3d19ad583 100644 --- a/src/primitives/transaction.cpp +++ b/src/primitives/transaction.cpp @@ -54,8 +54,8 @@ std::string CTxOut::ToString() const return strprintf("CTxOut(nValue=%d.%08d, scriptPubKey=%s)", nValue / COIN, nValue % COIN, HexStr(scriptPubKey).substr(0, 30)); } -CMutableTransaction::CMutableTransaction() : nVersion(CTransaction::CURRENT_VERSION), nLockTime(0) {} -CMutableTransaction::CMutableTransaction(const CTransaction& tx) : nVersion(tx.nVersion), vin(tx.vin), vout(tx.vout), nLockTime(tx.nLockTime) {} +CMutableTransaction::CMutableTransaction() : nVersion(CTransaction::CURRENT_VERSION), nLockTime(0), strTxComment('') {} +CMutableTransaction::CMutableTransaction(const CTransaction& tx) : nVersion(tx.nVersion), vin(tx.vin), vout(tx.vout), nLockTime(tx.nLockTime), strTxComment(tx.strTxComment) {} uint256 CMutableTransaction::GetHash() const { @@ -76,9 +76,9 @@ uint256 CTransaction::GetWitnessHash() const } /* For backward compatibility, the hash is initialized to 0. TODO: remove the need for this default constructor entirely. */ -CTransaction::CTransaction() : nVersion(CTransaction::CURRENT_VERSION), vin(), vout(), nLockTime(0), hash() {} -CTransaction::CTransaction(const CMutableTransaction &tx) : nVersion(tx.nVersion), vin(tx.vin), vout(tx.vout), nLockTime(tx.nLockTime), hash(ComputeHash()) {} -CTransaction::CTransaction(CMutableTransaction &&tx) : nVersion(tx.nVersion), vin(std::move(tx.vin)), vout(std::move(tx.vout)), nLockTime(tx.nLockTime), hash(ComputeHash()) {} +CTransaction::CTransaction() : nVersion(CTransaction::CURRENT_VERSION), vin(), vout(), nLockTime(0), strTxComment(''), hash() {} +CTransaction::CTransaction(const CMutableTransaction &tx) : nVersion(tx.nVersion), vin(tx.vin), vout(tx.vout), nLockTime(tx.nLockTime), strTxComment(tx.strTxComment), hash(ComputeHash()) {} +CTransaction::CTransaction(CMutableTransaction &&tx) : nVersion(tx.nVersion), vin(std::move(tx.vin)), vout(std::move(tx.vout)), nLockTime(tx.nLockTime), strTxComment(tx.strTxComment), hash(ComputeHash()) {} CAmount CTransaction::GetValueOut() const { @@ -111,5 +111,8 @@ std::string CTransaction::ToString() const str += " " + tx_in.scriptWitness.ToString() + "\n"; for (const auto& tx_out : vout) str += " " + tx_out.ToString() + "\n"; + if (nVersion >= 2) { + str += " txComment: " + tx.strTxComment + "\n"; + } return str; } diff --git a/src/primitives/transaction.h b/src/primitives/transaction.h index 041034bb8..74365d635 100644 --- a/src/primitives/transaction.h +++ b/src/primitives/transaction.h @@ -226,6 +226,9 @@ inline void UnserializeTransaction(TxType& tx, Stream& s) { throw std::ios_base::failure("Unknown transaction optional data"); } s >> tx.nLockTime; + if (tx.nVersion >= 2) { + s >> tx.strTxComment; + } } template @@ -255,6 +258,9 @@ inline void SerializeTransaction(const TxType& tx, Stream& s) { } } s << tx.nLockTime; + if (tx.nVersion >= 2) { + s << tx.strTxComment; + } } @@ -282,6 +288,7 @@ public: const std::vector vin; const std::vector vout; const uint32_t nLockTime; + const std::string strTxComment; private: /** Memory only. */ @@ -365,6 +372,7 @@ struct CMutableTransaction std::vector vin; std::vector vout; uint32_t nLockTime; + std::string strTxComment; CMutableTransaction(); CMutableTransaction(const CTransaction& tx);