Skip to content

Commit b1a6d4c

Browse files
committed
Take a CTransactionRef in AddToWalletIfInvolvingMe to avoid a copy
1 parent 1c95e2f commit b1a6d4c

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

src/wallet/wallet.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -966,8 +966,9 @@ bool CWallet::LoadToWallet(const CWalletTx& wtxIn)
966966
* Abandoned state should probably be more carefully tracked via different
967967
* posInBlock signals or by checking mempool presence when necessary.
968968
*/
969-
bool CWallet::AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlockIndex* pIndex, int posInBlock, bool fUpdate)
969+
bool CWallet::AddToWalletIfInvolvingMe(const CTransactionRef& ptx, const CBlockIndex* pIndex, int posInBlock, bool fUpdate)
970970
{
971+
const CTransaction& tx = *ptx;
971972
{
972973
AssertLockHeld(cs_wallet);
973974

@@ -988,7 +989,7 @@ bool CWallet::AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlockIndex
988989
if (fExisted && !fUpdate) return false;
989990
if (fExisted || IsMine(tx) || IsFromMe(tx))
990991
{
991-
CWalletTx wtx(this, MakeTransactionRef(tx));
992+
CWalletTx wtx(this, ptx);
992993

993994
// Get merkle branch if transaction was found in a block
994995
if (posInBlock != -1)
@@ -1119,7 +1120,7 @@ void CWallet::MarkConflicted(const uint256& hashBlock, const uint256& hashTx)
11191120
void CWallet::SyncTransaction(const CTransactionRef& ptx, const CBlockIndex *pindexBlockConnected, int posInBlock) {
11201121
const CTransaction& tx = *ptx;
11211122

1122-
if (!AddToWalletIfInvolvingMe(tx, pindexBlockConnected, posInBlock, true))
1123+
if (!AddToWalletIfInvolvingMe(ptx, pindexBlockConnected, posInBlock, true))
11231124
return; // Not one of ours
11241125

11251126
// If a transaction changes 'conflicted' state, that changes the balance
@@ -1542,7 +1543,7 @@ CBlockIndex* CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, bool f
15421543
CBlock block;
15431544
if (ReadBlockFromDisk(block, pindex, Params().GetConsensus())) {
15441545
for (size_t posInBlock = 0; posInBlock < block.vtx.size(); ++posInBlock) {
1545-
AddToWalletIfInvolvingMe(*block.vtx[posInBlock], pindex, posInBlock, fUpdate);
1546+
AddToWalletIfInvolvingMe(block.vtx[posInBlock], pindex, posInBlock, fUpdate);
15461547
}
15471548
if (!ret) {
15481549
ret = pindex;

src/wallet/wallet.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -853,7 +853,7 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface
853853
void TransactionAddedToMempool(const CTransactionRef& tx) override;
854854
void BlockConnected(const std::shared_ptr<const CBlock>& pblock, const CBlockIndex *pindex, const std::vector<CTransactionRef>& vtxConflicted) override;
855855
void BlockDisconnected(const std::shared_ptr<const CBlock>& pblock) override;
856-
bool AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlockIndex* pIndex, int posInBlock, bool fUpdate);
856+
bool AddToWalletIfInvolvingMe(const CTransactionRef& tx, const CBlockIndex* pIndex, int posInBlock, bool fUpdate);
857857
CBlockIndex* ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate = false);
858858
void ReacceptWalletTransactions();
859859
void ResendWalletTransactions(int64_t nBestBlockTime, CConnman* connman) override;

0 commit comments

Comments
 (0)