return true;
}
-bool AddToWalletIfMine(const CTransaction& tx, const CBlock* pblock)
+bool AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pblock, bool fUpdate = false)
{
- if (tx.IsMine() || mapWallet.count(tx.GetHash()))
- {
- CWalletTx wtx(tx);
- // Get merkle branch if transaction was found in a block
- if (pblock)
- wtx.SetMerkleBranch(pblock);
- return AddToWallet(wtx);
- }
- return true;
-}
-
-bool AddToWalletIfFromMe(const CTransaction& tx, const CBlock* pblock)
-{
- if (tx.IsFromMe() || mapWallet.count(tx.GetHash()))
+ uint256 hash = tx.GetHash();
+ bool fExisted = mapWallet.count(hash);
+ if (fExisted && !fUpdate) return false;
+ if (fExisted || tx.IsMine() || tx.IsFromMe())
{
CWalletTx wtx(tx);
// Get merkle branch if transaction was found in a block
wtx.SetMerkleBranch(pblock);
return AddToWallet(wtx);
}
- return true;
+ return false;
}
bool EraseFromWallet(uint256 hash)
block.ReadFromDisk(pindex, true);
foreach(CTransaction& tx, block.vtx)
{
- uint256 hash = tx.GetHash();
- if (mapWallet.count(hash)) continue;
- AddToWalletIfMine(tx, &block);
- if (mapWallet.count(hash))
- {
- ++ret;
- printf("Added missing RECEIVE %s\n", hash.ToString().c_str());
- continue;
- }
- AddToWalletIfFromMe(tx, &block);
- if (mapWallet.count(hash))
- {
- ++ret;
- printf("Added missing SEND %s\n", hash.ToString().c_str());
- continue;
- }
+ if (AddToWalletIfInvolvingMe(tx, &block))
+ ret++;
}
pindex = pindex->pnext;
}
// Watch for transactions paying to me
foreach(CTransaction& tx, vtx)
- AddToWalletIfMine(tx, this);
+ AddToWalletIfInvolvingMe(tx, this, true);
return true;
}
bool fMissingInputs = false;
if (tx.AcceptToMemoryPool(true, &fMissingInputs))
{
- AddToWalletIfMine(tx, NULL);
+ AddToWalletIfInvolvingMe(tx, NULL, true);
RelayMessage(inv, vMsg);
mapAlreadyAskedFor.erase(inv);
vWorkQueue.push_back(inv.hash);
if (tx.AcceptToMemoryPool(true))
{
printf(" accepted orphan tx %s\n", inv.hash.ToString().substr(0,10).c_str());
- AddToWalletIfMine(tx, NULL);
+ AddToWalletIfInvolvingMe(tx, NULL, true);
RelayMessage(inv, vMsg);
mapAlreadyAskedFor.erase(inv);
vWorkQueue.push_back(inv.hash);