From 783a76f23ba4f33b6e6f609eaf3bf41afd9bcd6f Mon Sep 17 00:00:00 2001 From: John Newbery Date: Thu, 25 Jul 2019 10:43:54 -0400 Subject: [wallet] Flatten CWalletTx class hierarchy Removes CMerkleTx as a base class for CWalletTx. Serialization logic is moved from CMerkleTx to CWalletTx. --- src/wallet/wallet.h | 63 ++++++++++++++++++++++------------------------------- 1 file changed, 26 insertions(+), 37 deletions(-) (limited to 'src') diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 7fb349a9a9..faed0f46a7 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -372,43 +372,13 @@ struct COutputEntry class CMerkleTx { public: - CTransactionRef tx; - uint256 hashBlock; - - /* An nIndex == -1 means that hashBlock (in nonzero) refers to the earliest - * block in the chain we know this or any in-wallet dependency conflicts - * with. Older clients interpret nIndex == -1 as unconfirmed for backward - * compatibility. - */ - int nIndex; - - CMerkleTx() - { - SetTx(MakeTransactionRef()); - Init(); - } - - explicit CMerkleTx(CTransactionRef arg) - { - SetTx(std::move(arg)); - Init(); - } - - void Init() - { - hashBlock = uint256(); - nIndex = -1; - } - - void SetTx(CTransactionRef arg) - { - tx = std::move(arg); - } - ADD_SERIALIZE_METHODS; template inline void SerializationOp(Stream& s, Operation ser_action) { + CTransactionRef tx; + uint256 hashBlock; + int nIndex; std::vector vMerkleBranch; // For compatibility with older versions. READWRITE(tx); READWRITE(hashBlock); @@ -425,7 +395,7 @@ int CalculateMaximumSignedInputSize(const CTxOut& txout, const CWallet* pwallet, * A transaction with a bunch of additional info that only the owner cares about. * It includes any unrecorded transactions needed to link it back to the block chain. */ -class CWalletTx : public CMerkleTx +class CWalletTx { private: const CWallet* pwallet; @@ -490,7 +460,10 @@ public: mutable bool fInMempool; mutable CAmount nChangeCached; - CWalletTx(const CWallet* pwalletIn, CTransactionRef arg) : CMerkleTx(std::move(arg)) + CWalletTx(const CWallet* pwalletIn, CTransactionRef arg) + : tx(std::move(arg)), + hashBlock(uint256()), + nIndex(-1) { Init(pwalletIn); } @@ -510,6 +483,15 @@ public: nOrderPos = -1; } + CTransactionRef tx; + uint256 hashBlock; + /* An nIndex == -1 means that hashBlock (in nonzero) refers to the earliest + * block in the chain we know this or any in-wallet dependency conflicts + * with. Older clients interpret nIndex == -1 as unconfirmed for backward + * compatibility. + */ + int nIndex; + template void Serialize(Stream& s) const { @@ -522,7 +504,8 @@ public: mapValueCopy["timesmart"] = strprintf("%u", nTimeSmart); } - s << static_cast(*this); + std::vector dummy_vector; //!< Used to be vMerkleBranch + s << tx << hashBlock << dummy_vector << nIndex; std::vector vUnused; //!< Used to be vtxPrev s << vUnused << mapValueCopy << vOrderForm << fTimeReceivedIsTxTime << nTimeReceived << fFromMe << fSpent; } @@ -533,7 +516,8 @@ public: Init(nullptr); char fSpent; - s >> static_cast(*this); + std::vector dummy_vector; //!< Used to be vMerkleBranch + s >> tx >> hashBlock >> dummy_vector >> nIndex; std::vector vUnused; //!< Used to be vtxPrev s >> vUnused >> mapValue >> vOrderForm >> fTimeReceivedIsTxTime >> nTimeReceived >> fFromMe >> fSpent; @@ -546,6 +530,11 @@ public: mapValue.erase("timesmart"); } + void SetTx(CTransactionRef arg) + { + tx = std::move(arg); + } + //! make sure balances are recalculated void MarkDirty() { -- cgit v1.2.3