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
This commit is contained in:
Wladimir J. van der Laan 2017-04-13 10:47:42 +02:00
commit c9ff4f8ee6
No known key found for this signature in database
GPG key ID: 74810B012346C9A6
2 changed files with 13 additions and 12 deletions

View file

@ -957,9 +957,9 @@ bool CWallet::LoadToWallet(const CWalletTx& wtxIn)
/** /**
* Add a transaction to the wallet, or update it. pIndex and posInBlock should * Add a transaction to the wallet, or update it. pIndex and posInBlock should
* be set when the transaction was known to be included in a block. When * be set when the transaction was known to be included in a block. When
* posInBlock = SYNC_TRANSACTION_NOT_IN_BLOCK (-1) , then wallet state is not * pIndex == NULL, then wallet state is not updated in AddToWallet, but
* updated in AddToWallet, but notifications happen and cached balances are * notifications happen and cached balances are marked dirty.
* marked dirty. *
* If fUpdate is true, existing transactions will be updated. * If fUpdate is true, existing transactions will be updated.
* TODO: One exception to this is that the abandoned state is cleared under the * TODO: One exception to this is that the abandoned state is cleared under the
* assumption that any further notification of a transaction that was considered * assumption that any further notification of a transaction that was considered
@ -973,7 +973,7 @@ bool CWallet::AddToWalletIfInvolvingMe(const CTransactionRef& ptx, const CBlockI
{ {
AssertLockHeld(cs_wallet); AssertLockHeld(cs_wallet);
if (posInBlock != -1) { if (pIndex != NULL) {
BOOST_FOREACH(const CTxIn& txin, tx.vin) { BOOST_FOREACH(const CTxIn& txin, tx.vin) {
std::pair<TxSpends::const_iterator, TxSpends::const_iterator> range = mapTxSpends.equal_range(txin.prevout); std::pair<TxSpends::const_iterator, TxSpends::const_iterator> range = mapTxSpends.equal_range(txin.prevout);
while (range.first != range.second) { while (range.first != range.second) {
@ -993,7 +993,7 @@ bool CWallet::AddToWalletIfInvolvingMe(const CTransactionRef& ptx, const CBlockI
CWalletTx wtx(this, ptx); CWalletTx wtx(this, ptx);
// Get merkle branch if transaction was found in a block // Get merkle branch if transaction was found in a block
if (posInBlock != -1) if (pIndex != NULL)
wtx.SetMerkleBranch(pIndex, posInBlock); wtx.SetMerkleBranch(pIndex, posInBlock);
return AddToWallet(wtx, false); return AddToWallet(wtx, false);
@ -1118,10 +1118,10 @@ void CWallet::MarkConflicted(const uint256& hashBlock, const uint256& hashTx)
} }
} }
void CWallet::SyncTransaction(const CTransactionRef& ptx, const CBlockIndex *pindexBlockConnected, int posInBlock) { void CWallet::SyncTransaction(const CTransactionRef& ptx, const CBlockIndex *pindex, int posInBlock) {
const CTransaction& tx = *ptx; const CTransaction& tx = *ptx;
if (!AddToWalletIfInvolvingMe(ptx, pindexBlockConnected, posInBlock, true)) if (!AddToWalletIfInvolvingMe(ptx, pindex, posInBlock, true))
return; // Not one of ours return; // Not one of ours
// If a transaction changes 'conflicted' state, that changes the balance // If a transaction changes 'conflicted' state, that changes the balance
@ -1136,7 +1136,7 @@ void CWallet::SyncTransaction(const CTransactionRef& ptx, const CBlockIndex *pin
void CWallet::TransactionAddedToMempool(const CTransactionRef& ptx) { void CWallet::TransactionAddedToMempool(const CTransactionRef& ptx) {
LOCK2(cs_main, cs_wallet); LOCK2(cs_main, cs_wallet);
SyncTransaction(ptx, NULL, -1); SyncTransaction(ptx);
} }
void CWallet::BlockConnected(const std::shared_ptr<const CBlock>& pblock, const CBlockIndex *pindex, const std::vector<CTransactionRef>& vtxConflicted) { 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
// the notification that the conflicted transaction was evicted. // the notification that the conflicted transaction was evicted.
for (const CTransactionRef& ptx : vtxConflicted) { for (const CTransactionRef& ptx : vtxConflicted) {
SyncTransaction(ptx, NULL, -1); SyncTransaction(ptx);
} }
for (size_t i = 0; i < pblock->vtx.size(); i++) { for (size_t i = 0; i < pblock->vtx.size(); i++) {
SyncTransaction(pblock->vtx[i], pindex, i); SyncTransaction(pblock->vtx[i], pindex, i);
@ -1161,7 +1161,7 @@ void CWallet::BlockDisconnected(const std::shared_ptr<const CBlock>& pblock) {
LOCK2(cs_main, cs_wallet); LOCK2(cs_main, cs_wallet);
for (const CTransactionRef& ptx : pblock->vtx) { for (const CTransactionRef& ptx : pblock->vtx) {
SyncTransaction(ptx, NULL, -1); SyncTransaction(ptx);
} }
} }

View file

@ -659,8 +659,9 @@ private:
void SyncMetaData(std::pair<TxSpends::iterator, TxSpends::iterator>); void SyncMetaData(std::pair<TxSpends::iterator, TxSpends::iterator>);
/* Used by TransactionAddedToMemorypool/BlockConnected/Disconnected */ /* Used by TransactionAddedToMemorypool/BlockConnected/Disconnected.
void SyncTransaction(const CTransactionRef& tx, const CBlockIndex *pindexBlockConnected, int posInBlock); * Should be called with pindexBlock and posInBlock if this is for a transaction that is included in a block. */
void SyncTransaction(const CTransactionRef& tx, const CBlockIndex *pindex = NULL, int posInBlock = 0);
/* the HD chain data model (external chain counters) */ /* the HD chain data model (external chain counters) */
CHDChain hdChain; CHDChain hdChain;