Skip to content

Commit 783a76f

Browse files
committed
[wallet] Flatten CWalletTx class hierarchy
Removes CMerkleTx as a base class for CWalletTx. Serialization logic is moved from CMerkleTx to CWalletTx.
1 parent b3a9d17 commit 783a76f

File tree

1 file changed

+26
-37
lines changed

1 file changed

+26
-37
lines changed

src/wallet/wallet.h

Lines changed: 26 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -372,43 +372,13 @@ struct COutputEntry
372372
class CMerkleTx
373373
{
374374
public:
375-
CTransactionRef tx;
376-
uint256 hashBlock;
377-
378-
/* An nIndex == -1 means that hashBlock (in nonzero) refers to the earliest
379-
* block in the chain we know this or any in-wallet dependency conflicts
380-
* with. Older clients interpret nIndex == -1 as unconfirmed for backward
381-
* compatibility.
382-
*/
383-
int nIndex;
384-
385-
CMerkleTx()
386-
{
387-
SetTx(MakeTransactionRef());
388-
Init();
389-
}
390-
391-
explicit CMerkleTx(CTransactionRef arg)
392-
{
393-
SetTx(std::move(arg));
394-
Init();
395-
}
396-
397-
void Init()
398-
{
399-
hashBlock = uint256();
400-
nIndex = -1;
401-
}
402-
403-
void SetTx(CTransactionRef arg)
404-
{
405-
tx = std::move(arg);
406-
}
407-
408375
ADD_SERIALIZE_METHODS;
409376

410377
template <typename Stream, typename Operation>
411378
inline void SerializationOp(Stream& s, Operation ser_action) {
379+
CTransactionRef tx;
380+
uint256 hashBlock;
381+
int nIndex;
412382
std::vector<uint256> vMerkleBranch; // For compatibility with older versions.
413383
READWRITE(tx);
414384
READWRITE(hashBlock);
@@ -425,7 +395,7 @@ int CalculateMaximumSignedInputSize(const CTxOut& txout, const CWallet* pwallet,
425395
* A transaction with a bunch of additional info that only the owner cares about.
426396
* It includes any unrecorded transactions needed to link it back to the block chain.
427397
*/
428-
class CWalletTx : public CMerkleTx
398+
class CWalletTx
429399
{
430400
private:
431401
const CWallet* pwallet;
@@ -490,7 +460,10 @@ class CWalletTx : public CMerkleTx
490460
mutable bool fInMempool;
491461
mutable CAmount nChangeCached;
492462

493-
CWalletTx(const CWallet* pwalletIn, CTransactionRef arg) : CMerkleTx(std::move(arg))
463+
CWalletTx(const CWallet* pwalletIn, CTransactionRef arg)
464+
: tx(std::move(arg)),
465+
hashBlock(uint256()),
466+
nIndex(-1)
494467
{
495468
Init(pwalletIn);
496469
}
@@ -510,6 +483,15 @@ class CWalletTx : public CMerkleTx
510483
nOrderPos = -1;
511484
}
512485

486+
CTransactionRef tx;
487+
uint256 hashBlock;
488+
/* An nIndex == -1 means that hashBlock (in nonzero) refers to the earliest
489+
* block in the chain we know this or any in-wallet dependency conflicts
490+
* with. Older clients interpret nIndex == -1 as unconfirmed for backward
491+
* compatibility.
492+
*/
493+
int nIndex;
494+
513495
template<typename Stream>
514496
void Serialize(Stream& s) const
515497
{
@@ -522,7 +504,8 @@ class CWalletTx : public CMerkleTx
522504
mapValueCopy["timesmart"] = strprintf("%u", nTimeSmart);
523505
}
524506

525-
s << static_cast<const CMerkleTx&>(*this);
507+
std::vector<uint256> dummy_vector; //!< Used to be vMerkleBranch
508+
s << tx << hashBlock << dummy_vector << nIndex;
526509
std::vector<CMerkleTx> vUnused; //!< Used to be vtxPrev
527510
s << vUnused << mapValueCopy << vOrderForm << fTimeReceivedIsTxTime << nTimeReceived << fFromMe << fSpent;
528511
}
@@ -533,7 +516,8 @@ class CWalletTx : public CMerkleTx
533516
Init(nullptr);
534517
char fSpent;
535518

536-
s >> static_cast<CMerkleTx&>(*this);
519+
std::vector<uint256> dummy_vector; //!< Used to be vMerkleBranch
520+
s >> tx >> hashBlock >> dummy_vector >> nIndex;
537521
std::vector<CMerkleTx> vUnused; //!< Used to be vtxPrev
538522
s >> vUnused >> mapValue >> vOrderForm >> fTimeReceivedIsTxTime >> nTimeReceived >> fFromMe >> fSpent;
539523

@@ -546,6 +530,11 @@ class CWalletTx : public CMerkleTx
546530
mapValue.erase("timesmart");
547531
}
548532

533+
void SetTx(CTransactionRef arg)
534+
{
535+
tx = std::move(arg);
536+
}
537+
549538
//! make sure balances are recalculated
550539
void MarkDirty()
551540
{

0 commit comments

Comments
 (0)