Skip to content

Commit b3a9d17

Browse files
committed
[wallet] Move CMerkleTx functions into CWalletTx
CMerkleTx only exists as a base class for CWalletTx and for wallet file serialization/deserialization. Move CMerkleTx methods into CWalletTx, but leave class hierarchy and serialization logic in place.
1 parent 74f1a27 commit b3a9d17

File tree

2 files changed

+38
-34
lines changed

2 files changed

+38
-34
lines changed

src/wallet/wallet.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ WalletCreationStatus CreateWallet(interfaces::Chain& chain, const SecureString&
228228

229229
const uint32_t BIP32_HARDENED_KEY_LIMIT = 0x80000000;
230230

231-
const uint256 CMerkleTx::ABANDON_HASH(uint256S("0000000000000000000000000000000000000000000000000000000000000001"));
231+
const uint256 CWalletTx::ABANDON_HASH(uint256S("0000000000000000000000000000000000000000000000000000000000000001"));
232232

233233
/** @defgroup mapWallet
234234
*
@@ -4627,7 +4627,7 @@ CKeyPool::CKeyPool(const CPubKey& vchPubKeyIn, bool internalIn)
46274627
m_pre_split = false;
46284628
}
46294629

4630-
void CMerkleTx::SetMerkleBranch(const uint256& block_hash, int posInBlock)
4630+
void CWalletTx::SetMerkleBranch(const uint256& block_hash, int posInBlock)
46314631
{
46324632
// Update the tx's hashBlock
46334633
hashBlock = block_hash;
@@ -4636,15 +4636,15 @@ void CMerkleTx::SetMerkleBranch(const uint256& block_hash, int posInBlock)
46364636
nIndex = posInBlock;
46374637
}
46384638

4639-
int CMerkleTx::GetDepthInMainChain(interfaces::Chain::Lock& locked_chain) const
4639+
int CWalletTx::GetDepthInMainChain(interfaces::Chain::Lock& locked_chain) const
46404640
{
46414641
if (hashUnset())
46424642
return 0;
46434643

46444644
return locked_chain.getBlockDepth(hashBlock) * (nIndex == -1 ? -1 : 1);
46454645
}
46464646

4647-
int CMerkleTx::GetBlocksToMaturity(interfaces::Chain::Lock& locked_chain) const
4647+
int CWalletTx::GetBlocksToMaturity(interfaces::Chain::Lock& locked_chain) const
46484648
{
46494649
if (!IsCoinBase())
46504650
return 0;
@@ -4653,7 +4653,7 @@ int CMerkleTx::GetBlocksToMaturity(interfaces::Chain::Lock& locked_chain) const
46534653
return std::max(0, (COINBASE_MATURITY+1) - chain_depth);
46544654
}
46554655

4656-
bool CMerkleTx::IsImmatureCoinBase(interfaces::Chain::Lock& locked_chain) const
4656+
bool CWalletTx::IsImmatureCoinBase(interfaces::Chain::Lock& locked_chain) const
46574657
{
46584658
// note GetBlocksToMaturity is 0 for non-coinbase tx
46594659
return GetBlocksToMaturity(locked_chain) > 0;

src/wallet/wallet.h

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -364,13 +364,13 @@ struct COutputEntry
364364
int vout;
365365
};
366366

367-
/** A transaction with a merkle branch linking it to the block chain. */
367+
/** Legacy class used for deserializing vtxPrev for backwards compatibility.
368+
* vtxPrev was removed in commit 93a18a3650292afbb441a47d1fa1b94aeb0164e3,
369+
* but old wallet.dat files may still contain vtxPrev vectors of CMerkleTxs.
370+
* These need to get deserialized for field alignment when deserializing
371+
* a CWalletTx, but the deserialized values are discarded.**/
368372
class CMerkleTx
369373
{
370-
private:
371-
/** Constant used in hashBlock to indicate tx has been abandoned */
372-
static const uint256 ABANDON_HASH;
373-
374374
public:
375375
CTransactionRef tx;
376376
uint256 hashBlock;
@@ -416,30 +416,6 @@ class CMerkleTx
416416
READWRITE(nIndex);
417417
}
418418

419-
void SetMerkleBranch(const uint256& block_hash, int posInBlock);
420-
421-
/**
422-
* Return depth of transaction in blockchain:
423-
* <0 : conflicts with a transaction this deep in the blockchain
424-
* 0 : in memory pool, waiting to be included in a block
425-
* >=1 : this many blocks deep in the main chain
426-
*/
427-
int GetDepthInMainChain(interfaces::Chain::Lock& locked_chain) const;
428-
bool IsInMainChain(interfaces::Chain::Lock& locked_chain) const { return GetDepthInMainChain(locked_chain) > 0; }
429-
430-
/**
431-
* @return number of blocks to maturity for this transaction:
432-
* 0 : is not a coinbase transaction, or is a mature coinbase transaction
433-
* >0 : is a coinbase transaction which matures in this many blocks
434-
*/
435-
int GetBlocksToMaturity(interfaces::Chain::Lock& locked_chain) const;
436-
bool hashUnset() const { return (hashBlock.IsNull() || hashBlock == ABANDON_HASH); }
437-
bool isAbandoned() const { return (hashBlock == ABANDON_HASH); }
438-
void setAbandoned() { hashBlock = ABANDON_HASH; }
439-
440-
const uint256& GetHash() const { return tx->GetHash(); }
441-
bool IsCoinBase() const { return tx->IsCoinBase(); }
442-
bool IsImmatureCoinBase(interfaces::Chain::Lock& locked_chain) const;
443419
};
444420

445421
//Get the marginal bytes of spending the specified output
@@ -454,6 +430,9 @@ class CWalletTx : public CMerkleTx
454430
private:
455431
const CWallet* pwallet;
456432

433+
/** Constant used in hashBlock to indicate tx has been abandoned */
434+
static const uint256 ABANDON_HASH;
435+
457436
public:
458437
/**
459438
* Key/value map with information about the transaction.
@@ -630,6 +609,31 @@ class CWalletTx : public CMerkleTx
630609
// that we still have the runtime check "AssertLockHeld(pwallet->cs_wallet)"
631610
// in place.
632611
std::set<uint256> GetConflicts() const NO_THREAD_SAFETY_ANALYSIS;
612+
613+
void SetMerkleBranch(const uint256& block_hash, int posInBlock);
614+
615+
/**
616+
* Return depth of transaction in blockchain:
617+
* <0 : conflicts with a transaction this deep in the blockchain
618+
* 0 : in memory pool, waiting to be included in a block
619+
* >=1 : this many blocks deep in the main chain
620+
*/
621+
int GetDepthInMainChain(interfaces::Chain::Lock& locked_chain) const;
622+
bool IsInMainChain(interfaces::Chain::Lock& locked_chain) const { return GetDepthInMainChain(locked_chain) > 0; }
623+
624+
/**
625+
* @return number of blocks to maturity for this transaction:
626+
* 0 : is not a coinbase transaction, or is a mature coinbase transaction
627+
* >0 : is a coinbase transaction which matures in this many blocks
628+
*/
629+
int GetBlocksToMaturity(interfaces::Chain::Lock& locked_chain) const;
630+
bool hashUnset() const { return (hashBlock.IsNull() || hashBlock == ABANDON_HASH); }
631+
bool isAbandoned() const { return (hashBlock == ABANDON_HASH); }
632+
void setAbandoned() { hashBlock = ABANDON_HASH; }
633+
634+
const uint256& GetHash() const { return tx->GetHash(); }
635+
bool IsCoinBase() const { return tx->IsCoinBase(); }
636+
bool IsImmatureCoinBase(interfaces::Chain::Lock& locked_chain) const;
633637
};
634638

635639
class COutput

0 commit comments

Comments
 (0)