Skip to content

Commit c9ff4f8

Browse files
committed
Merge #10186: Remove SYNC_TRANSACTION_NOT_IN_BLOCK magic number
d0cd0bd Make CWallet::SyncTransactions() interface friendlier (John Newbery) 714e4ad AddToWalletIfInvolvingMe should test pIndex, not posInBlock (John Newbery) Tree-SHA512: d02e7ffce635c53f3e099c37cc5613b431f74e0e3ea189269132901a99fc539477849ddad0282ce721d46a4d794c2d46523d58b64f0c26c655f70b5808c745a5
2 parents de01da7 + d0cd0bd commit c9ff4f8

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

src/wallet/wallet.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -957,9 +957,9 @@ bool CWallet::LoadToWallet(const CWalletTx& wtxIn)
957957
/**
958958
* Add a transaction to the wallet, or update it. pIndex and posInBlock should
959959
* be set when the transaction was known to be included in a block. When
960-
* posInBlock = SYNC_TRANSACTION_NOT_IN_BLOCK (-1) , then wallet state is not
961-
* updated in AddToWallet, but notifications happen and cached balances are
962-
* marked dirty.
960+
* pIndex == NULL, then wallet state is not updated in AddToWallet, but
961+
* notifications happen and cached balances are marked dirty.
962+
*
963963
* If fUpdate is true, existing transactions will be updated.
964964
* TODO: One exception to this is that the abandoned state is cleared under the
965965
* assumption that any further notification of a transaction that was considered
@@ -973,7 +973,7 @@ bool CWallet::AddToWalletIfInvolvingMe(const CTransactionRef& ptx, const CBlockI
973973
{
974974
AssertLockHeld(cs_wallet);
975975

976-
if (posInBlock != -1) {
976+
if (pIndex != NULL) {
977977
BOOST_FOREACH(const CTxIn& txin, tx.vin) {
978978
std::pair<TxSpends::const_iterator, TxSpends::const_iterator> range = mapTxSpends.equal_range(txin.prevout);
979979
while (range.first != range.second) {
@@ -993,7 +993,7 @@ bool CWallet::AddToWalletIfInvolvingMe(const CTransactionRef& ptx, const CBlockI
993993
CWalletTx wtx(this, ptx);
994994

995995
// Get merkle branch if transaction was found in a block
996-
if (posInBlock != -1)
996+
if (pIndex != NULL)
997997
wtx.SetMerkleBranch(pIndex, posInBlock);
998998

999999
return AddToWallet(wtx, false);
@@ -1118,10 +1118,10 @@ void CWallet::MarkConflicted(const uint256& hashBlock, const uint256& hashTx)
11181118
}
11191119
}
11201120

1121-
void CWallet::SyncTransaction(const CTransactionRef& ptx, const CBlockIndex *pindexBlockConnected, int posInBlock) {
1121+
void CWallet::SyncTransaction(const CTransactionRef& ptx, const CBlockIndex *pindex, int posInBlock) {
11221122
const CTransaction& tx = *ptx;
11231123

1124-
if (!AddToWalletIfInvolvingMe(ptx, pindexBlockConnected, posInBlock, true))
1124+
if (!AddToWalletIfInvolvingMe(ptx, pindex, posInBlock, true))
11251125
return; // Not one of ours
11261126

11271127
// If a transaction changes 'conflicted' state, that changes the balance
@@ -1136,7 +1136,7 @@ void CWallet::SyncTransaction(const CTransactionRef& ptx, const CBlockIndex *pin
11361136

11371137
void CWallet::TransactionAddedToMempool(const CTransactionRef& ptx) {
11381138
LOCK2(cs_main, cs_wallet);
1139-
SyncTransaction(ptx, NULL, -1);
1139+
SyncTransaction(ptx);
11401140
}
11411141

11421142
void CWallet::BlockConnected(const std::shared_ptr<const CBlock>& pblock, const CBlockIndex *pindex, const std::vector<CTransactionRef>& vtxConflicted) {
@@ -1150,7 +1150,7 @@ void CWallet::BlockConnected(const std::shared_ptr<const CBlock>& pblock, const
11501150
// the notification that the conflicted transaction was evicted.
11511151

11521152
for (const CTransactionRef& ptx : vtxConflicted) {
1153-
SyncTransaction(ptx, NULL, -1);
1153+
SyncTransaction(ptx);
11541154
}
11551155
for (size_t i = 0; i < pblock->vtx.size(); i++) {
11561156
SyncTransaction(pblock->vtx[i], pindex, i);
@@ -1161,7 +1161,7 @@ void CWallet::BlockDisconnected(const std::shared_ptr<const CBlock>& pblock) {
11611161
LOCK2(cs_main, cs_wallet);
11621162

11631163
for (const CTransactionRef& ptx : pblock->vtx) {
1164-
SyncTransaction(ptx, NULL, -1);
1164+
SyncTransaction(ptx);
11651165
}
11661166
}
11671167

src/wallet/wallet.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -659,8 +659,9 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface
659659

660660
void SyncMetaData(std::pair<TxSpends::iterator, TxSpends::iterator>);
661661

662-
/* Used by TransactionAddedToMemorypool/BlockConnected/Disconnected */
663-
void SyncTransaction(const CTransactionRef& tx, const CBlockIndex *pindexBlockConnected, int posInBlock);
662+
/* Used by TransactionAddedToMemorypool/BlockConnected/Disconnected.
663+
* Should be called with pindexBlock and posInBlock if this is for a transaction that is included in a block. */
664+
void SyncTransaction(const CTransactionRef& tx, const CBlockIndex *pindex = NULL, int posInBlock = 0);
664665

665666
/* the HD chain data model (external chain counters) */
666667
CHDChain hdChain;

0 commit comments

Comments
 (0)