[wallet] Flatten CWalletTx class hierarchy

Removes CMerkleTx as a base class for CWalletTx. Serialization logic is
moved from CMerkleTx to CWalletTx.
This commit is contained in:
John Newbery 2019-07-25 10:43:54 -04:00
parent b3a9d179f2
commit 783a76f23b

View file

@ -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 <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action) {
CTransactionRef tx;
uint256 hashBlock;
int nIndex;
std::vector<uint256> 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<typename Stream>
void Serialize(Stream& s) const
{
@ -522,7 +504,8 @@ public:
mapValueCopy["timesmart"] = strprintf("%u", nTimeSmart);
}
s << static_cast<const CMerkleTx&>(*this);
std::vector<uint256> dummy_vector; //!< Used to be vMerkleBranch
s << tx << hashBlock << dummy_vector << nIndex;
std::vector<CMerkleTx> 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<CMerkleTx&>(*this);
std::vector<uint256> dummy_vector; //!< Used to be vMerkleBranch
s >> tx >> hashBlock >> dummy_vector >> nIndex;
std::vector<CMerkleTx> 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()
{