Try wallet fix here

This commit is contained in:
blackjok3r
2018-12-07 00:38:13 +08:00
parent 04285b4b25
commit b76ca3dc43
2 changed files with 28 additions and 5 deletions

View File

@@ -3835,15 +3835,16 @@ bool static DisconnectTip(CValidationState &state, bool fBare = false) {
assert(pcoinsTip->GetSaplingAnchorAt(pcoinsTip->GetBestAnchor(SAPLING), newSaplingTree));
// Let wallets know transactions went from 1-confirmed to
// 0-confirmed or conflicted:
std::vector<uint256> TxToRemove;
for (int i = 0; i < block.vtx.size(); i++)
{
CTransaction &tx = block.vtx[i];
//if ((i == (block.vtx.size() - 1)) && ((ASSETCHAINS_LWMAPOS && block.IsVerusPOSBlock()) || (ASSETCHAINS_STAKED != 0 && (komodo_isPoS((CBlock *)&block) != 0))))
if ((i == (block.vtx.size() - 1)) && (ASSETCHAINS_STAKED != 0 && (komodo_isPoS((CBlock *)&block) != 0)))
{
//EraseFromWallets(tx.GetHash());
#ifdef ENABLE_WALLET
pwalletMain->EraseFromWallet(tx.GetHash());
TxToRemove.push_back(tx.GetHash());
//pwalletMain->EraseFromWallet(tx.GetHash());
#endif
}
else
@@ -3851,6 +3852,25 @@ bool static DisconnectTip(CValidationState &state, bool fBare = false) {
SyncWithWallets(tx, NULL);
}
}
if ( ASSETCHAINS_STAKED != 0 ) // If Staked chain, scan wallet for orphaned txs and delete them.
{
LOCK2(cs_main, pwalletMain->cs_wallet);
for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it)
{
CTransaction tx;
uint256 hashBlock;
if (!GetTransaction((*it).first,tx,hashBlock,true))
{
fprintf(stderr, "TX Does Not Exist: %s\n",(*it).first.ToString().c_str());
TxToRemove.push_back((*it).first);
}
}
BOOST_FOREACH (uint256& hash, TxToRemove)
{
pwalletMain->EraseFromWallet(hash);
fprintf(stderr, "Erased %s from wallet.\n",hash.ToString().c_str());
}
}
// Update cached incremental witnesses
GetMainSignals().ChainTip(pindexDelete, &block, newSproutTree, newSaplingTree, false);
return true;

View File

@@ -867,6 +867,8 @@ static bool IsKeyType(string strType)
strType == "mkey" || strType == "ckey");
}
extern uint64_t ASSETCHAINS_STAKED;
DBErrors CWalletDB::LoadWallet(CWallet* pwallet)
{
pwallet->vchDefaultKey = CPubKey();
@@ -918,8 +920,9 @@ DBErrors CWalletDB::LoadWallet(CWallet* pwallet)
{
// Leave other errors alone, if we try to fix them we might make things worse.
fNoncriticalErrors = true; // ... but do warn the user there is something wrong.
if (strType == "tx")
// Rescan if there is a bad transaction record:
if (strType == "tx" && ASSETCHAINS_STAKED == 0 )
// Rescan if there is a bad transaction record..
// But dont on staked chains!
SoftSetBoolArg("-rescan", true);
}
}
@@ -967,7 +970,7 @@ DBErrors CWalletDB::LoadWallet(CWallet* pwallet)
if (wss.fAnyUnordered)
result = ReorderTransactions(pwallet);
return result;
}