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)
if (GetSigOpCount() > nSize / 34 || nSize < 100)
return error("AcceptToMemoryPool() : nonstandard transaction");
- // Rather not work on nonstandard transactions
- if (!IsStandard())
+ // Rather not work on nonstandard transactions (unless -testnet)
+ if (!fTestNet && !IsStandard())
return error("AcceptToMemoryPool() : nonstandard transaction type");
// Do we already have it?
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;
}
bool IsInitialBlockDownload()
{
- if (pindexBest == NULL || (!fTestNet && nBestHeight < 105000))
+ if (pindexBest == NULL || (!fTestNet && nBestHeight < 118000))
return true;
static int64 nLastUpdate;
static CBlockIndex* pindexLastBest;
// Watch for transactions paying to me
foreach(CTransaction& tx, vtx)
- AddToWalletIfMine(tx, this);
+ AddToWalletIfInvolvingMe(tx, this, true);
return true;
}
}
}
+ // Update best block in wallet (so we can detect restored wallets)
+ if (!IsInitialBlockDownload())
+ {
+ CWalletDB walletdb;
+ const CBlockLocator locator(pindexNew);
+ if (!walletdb.WriteBestBlock(locator))
+ return error("SetBestChain() : WriteWalletBest failed");
+ }
+
// New best block
hashBestChain = hash;
pindexBest = pindexNew;
(nHeight == 68555 && hash != uint256("0x00000000001e1b4903550a0b96e9a9405c8a95f387162e4944e8d9fbe501cd6a")) ||
(nHeight == 70567 && hash != uint256("0x00000000006a49b14bcf27462068f1264c961f11fa2e0eddd2be0791e1d4124a")) ||
(nHeight == 74000 && hash != uint256("0x0000000000573993a3c9e41ce34471c079dcf5f52a0e824a81e7f953b8661a20")) ||
- (nHeight == 105000 && hash != uint256("0x00000000000291ce28027faea320c8d2b054b2e0fe44a773f3eefb151d6bdc97")))
+ (nHeight == 105000 && hash != uint256("0x00000000000291ce28027faea320c8d2b054b2e0fe44a773f3eefb151d6bdc97")) ||
+ (nHeight == 118000 && hash != uint256("0x000000000000774a7f8a7a12dc906ddb9e17e75d684f15e00f8767f9e8f36553")))
return error("AcceptBlock() : rejected by checkpoint lockin at %d", nHeight);
// Write block to history file
if (hashBestChain == hash)
CRITICAL_BLOCK(cs_vNodes)
foreach(CNode* pnode, vNodes)
- if (nBestHeight > (pnode->nStartingHeight != -1 ? pnode->nStartingHeight - 2000 : 105000))
+ if (nBestHeight > (pnode->nStartingHeight != -1 ? pnode->nStartingHeight - 2000 : 118000))
pnode->PushInventory(CInv(MSG_BLOCK, hash));
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);
{
string strError;
if (nValue + nFeeRequired > GetBalance())
- strError = strprintf(_("Error: This is an oversized transaction that requires a transaction fee of %s "), FormatMoney(nFeeRequired).c_str());
+ strError = strprintf(_("Error: This transaction requires a transaction fee of at least %s because of its amount, complexity, or use of recently received funds "), FormatMoney(nFeeRequired).c_str());
else
strError = _("Error: Transaction creation failed ");
printf("SendMoney() : %s", strError.c_str());