diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -370,12 +370,12 @@ int vout; }; -/** A transaction with a merkle branch linking it to the block chain. */ +/** Legacy class used for deserializing vtxPrev for backwards compatibility. + * vtxPrev was removed in commit 93a18a3650292afbb441a47d1fa1b94aeb0164e3, + * but old wallet.dat files may still contain vtxPrev vectors of CMerkleTxs. + * These need to get deserialized for field alignment when deserializing + * a CWalletTx, but the deserialized values are discarded.**/ class CMerkleTx { -private: - /** Constant used in hashBlock to indicate tx has been abandoned */ - static const BlockHash ABANDON_HASH; - public: CTransactionRef tx; BlockHash hashBlock; @@ -416,35 +416,6 @@ READWRITE(vMerkleBranch); READWRITE(nIndex); } - - void SetMerkleBranch(const BlockHash &block_hash, int posInBlock); - - /** - * Return depth of transaction in blockchain: - * <0 : conflicts with a transaction this deep in the blockchain - * 0 : in memory pool, waiting to be included in a block - * >=1 : this many blocks deep in the main chain - */ - int GetDepthInMainChain(interfaces::Chain::Lock &locked_chain) const; - bool IsInMainChain(interfaces::Chain::Lock &locked_chain) const { - return GetDepthInMainChain(locked_chain) > 0; - } - - /** - * @return number of blocks to maturity for this transaction: - * 0 : is not a coinbase transaction, or is a mature coinbase transaction - * >0 : is a coinbase transaction which matures in this many blocks - */ - int GetBlocksToMaturity(interfaces::Chain::Lock &locked_chain) const; - bool hashUnset() const { - return (hashBlock.IsNull() || hashBlock == ABANDON_HASH); - } - bool isAbandoned() const { return (hashBlock == ABANDON_HASH); } - void setAbandoned() { hashBlock = ABANDON_HASH; } - - TxId GetId() const { return tx->GetId(); } - bool IsCoinBase() const { return tx->IsCoinBase(); } - bool IsImmatureCoinBase(interfaces::Chain::Lock &locked_chain) const; }; // Get the marginal bytes of spending the specified output @@ -460,6 +431,9 @@ private: const CWallet *pwallet; + /** Constant used in hashBlock to indicate tx has been abandoned */ + static const BlockHash ABANDON_HASH; + public: /** * Key/value map with information about the transaction. @@ -650,6 +624,35 @@ // that we still have the runtime check "AssertLockHeld(pwallet->cs_wallet)" // in place. std::set GetConflicts() const NO_THREAD_SAFETY_ANALYSIS; + + void SetMerkleBranch(const BlockHash &block_hash, int posInBlock); + + /** + * Return depth of transaction in blockchain: + * <0 : conflicts with a transaction this deep in the blockchain + * 0 : in memory pool, waiting to be included in a block + * >=1 : this many blocks deep in the main chain + */ + int GetDepthInMainChain(interfaces::Chain::Lock &locked_chain) const; + bool IsInMainChain(interfaces::Chain::Lock &locked_chain) const { + return GetDepthInMainChain(locked_chain) > 0; + } + + /** + * @return number of blocks to maturity for this transaction: + * 0 : is not a coinbase transaction, or is a mature coinbase transaction + * >0 : is a coinbase transaction which matures in this many blocks + */ + int GetBlocksToMaturity(interfaces::Chain::Lock &locked_chain) const; + bool hashUnset() const { + return (hashBlock.IsNull() || hashBlock == ABANDON_HASH); + } + bool isAbandoned() const { return (hashBlock == ABANDON_HASH); } + void setAbandoned() { hashBlock = ABANDON_HASH; } + + TxId GetId() const { return tx->GetId(); } + bool IsCoinBase() const { return tx->IsCoinBase(); } + bool IsImmatureCoinBase(interfaces::Chain::Lock &locked_chain) const; }; class COutput { diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -240,7 +240,7 @@ const uint32_t BIP32_HARDENED_KEY_LIMIT = 0x80000000; -const BlockHash CMerkleTx::ABANDON_HASH(uint256S( +const BlockHash CWalletTx::ABANDON_HASH(uint256S( "0000000000000000000000000000000000000000000000000000000000000001")); /** @defgroup mapWallet @@ -5128,7 +5128,7 @@ m_pre_split = false; } -void CMerkleTx::SetMerkleBranch(const BlockHash &block_hash, int posInBlock) { +void CWalletTx::SetMerkleBranch(const BlockHash &block_hash, int posInBlock) { // Update the tx's hashBlock hashBlock = block_hash; @@ -5136,7 +5136,7 @@ nIndex = posInBlock; } -int CMerkleTx::GetDepthInMainChain( +int CWalletTx::GetDepthInMainChain( interfaces::Chain::Lock &locked_chain) const { if (hashUnset()) { return 0; @@ -5145,7 +5145,7 @@ return locked_chain.getBlockDepth(hashBlock) * (nIndex == -1 ? -1 : 1); } -int CMerkleTx::GetBlocksToMaturity( +int CWalletTx::GetBlocksToMaturity( interfaces::Chain::Lock &locked_chain) const { if (!IsCoinBase()) { return 0; @@ -5157,7 +5157,7 @@ return std::max(0, (COINBASE_MATURITY + 1) - chain_depth); } -bool CMerkleTx::IsImmatureCoinBase( +bool CWalletTx::IsImmatureCoinBase( interfaces::Chain::Lock &locked_chain) const { // note GetBlocksToMaturity is 0 for non-coinbase tx return GetBlocksToMaturity(locked_chain) > 0;