commit toest to dev, clean wallet branch broken

This commit is contained in:
blackjok3r
2018-11-18 20:44:52 +08:00
parent a9957e3bb4
commit 3cc9f623a8
3 changed files with 28 additions and 13 deletions

View File

@@ -494,7 +494,7 @@ static const CRPCCommand vRPCCommands[] =
{ "wallet", "getaccountaddress", &getaccountaddress, true }, { "wallet", "getaccountaddress", &getaccountaddress, true },
{ "wallet", "getaccount", &getaccount, true }, { "wallet", "getaccount", &getaccount, true },
{ "wallet", "getaddressesbyaccount", &getaddressesbyaccount, true }, { "wallet", "getaddressesbyaccount", &getaddressesbyaccount, true },
{ "wallet", "cleanwalletnotarisations", &cleanwalletnotarisations, false }, { "wallet", "cleanwallettransactions", &cleanwallettransactions, false },
{ "wallet", "getbalance", &getbalance, false }, { "wallet", "getbalance", &getbalance, false },
{ "wallet", "getbalance64", &getbalance64, false }, { "wallet", "getbalance64", &getbalance64, false },
{ "wallet", "getnewaddress", &getnewaddress, true }, { "wallet", "getnewaddress", &getnewaddress, true },

View File

@@ -300,7 +300,7 @@ extern UniValue signmessage(const UniValue& params, bool fHelp);
extern UniValue verifymessage(const UniValue& params, bool fHelp); extern UniValue verifymessage(const UniValue& params, bool fHelp);
extern UniValue getreceivedbyaddress(const UniValue& params, bool fHelp); extern UniValue getreceivedbyaddress(const UniValue& params, bool fHelp);
extern UniValue getreceivedbyaccount(const UniValue& params, bool fHelp); extern UniValue getreceivedbyaccount(const UniValue& params, bool fHelp);
extern UniValue cleanwalletnotarisations(const UniValue& params, bool fHelp); extern UniValue cleanwallettransactions(const UniValue& params, bool fHelp);
extern UniValue getbalance(const UniValue& params, bool fHelp); extern UniValue getbalance(const UniValue& params, bool fHelp);
extern UniValue getbalance64(const UniValue& params, bool fHelp); extern UniValue getbalance64(const UniValue& params, bool fHelp);
extern UniValue getunconfirmedbalance(const UniValue& params, bool fHelp); extern UniValue getunconfirmedbalance(const UniValue& params, bool fHelp);

View File

@@ -999,15 +999,15 @@ CAmount GetAccountBalance(const string& strAccount, int nMinDepth, const isminef
return GetAccountBalance(walletdb, strAccount, nMinDepth, filter); return GetAccountBalance(walletdb, strAccount, nMinDepth, filter);
} }
UniValue cleanwalletnotarisations(const UniValue& params, bool fHelp) UniValue cleanwallettransactions(const UniValue& params, bool fHelp)
{ {
if (!EnsureWalletIsAvailable(fHelp)) if (!EnsureWalletIsAvailable(fHelp))
return NullUniValue; return NullUniValue;
if (fHelp || params.size() > 1 ) if (fHelp || params.size() > 1 )
throw runtime_error( throw runtime_error(
"cleanwalletnotarisations \"txid\"\n" "cleanwallettransactions \"txid\"\n"
"\nRemove all txs which are totally spent and all notarisations created from them, you can clear all txs bar one, by specifiying a txid.\n" "\nRemove all txs which are totally spent, you can clear all txs bar one, by specifiying a txid.\n"
"\nPlease backup your wallet.dat before running this command.\n" "\nPlease backup your wallet.dat before running this command.\n"
"\nArguments:\n" "\nArguments:\n"
"1. \"txid\" (string, optional) The transaction id to keep.\n" "1. \"txid\" (string, optional) The transaction id to keep.\n"
@@ -1042,7 +1042,6 @@ UniValue cleanwalletnotarisations(const UniValue& params, bool fHelp)
{ {
for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it) for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it)
{ {
txs++;
const CWalletTx& wtx = (*it).second; const CWalletTx& wtx = (*it).second;
if ( wtx.GetHash() != exception ) if ( wtx.GetHash() != exception )
{ {
@@ -1058,7 +1057,23 @@ UniValue cleanwalletnotarisations(const UniValue& params, bool fHelp)
} }
else else
{ {
std::vector<CWalletTx> NotarisationTxs; // listunspent call... this gets us all the txids that are unspent, we search this list for the oldest tx,
// then delete all txs in the wallet before this block + 10 as safety buffer.
vector<COutput> vecOutputs;
assert(pwalletMain != NULL);
pwalletMain->AvailableCoins(vecOutputs, false, NULL, true);
int32_t oldestTxHeight = 0;
BOOST_FOREACH(const COutput& out, vecOutputs)
{
int32_t txheight = out.nDepth;
fprintf(stderr, "txheight.%i\n", txheight);
if ( txheight > oldestTxHeight )
oldestTxHeight = txheight;
}
fprintf(stderr, "oldestTxHeight.%i\n",oldestTxHeight);
/*std::vector<CWalletTx> NotarisationTxs;
for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it) for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it)
{ {
const CWalletTx& wtx = (*it).second; const CWalletTx& wtx = (*it).second;
@@ -1117,15 +1132,15 @@ UniValue cleanwalletnotarisations(const UniValue& params, bool fHelp)
} }
} }
} }
} } */
} }
// erase txs // erase txs
BOOST_FOREACH (uint256& hash, TxToRemove) /*BOOST_FOREACH (uint256& hash, TxToRemove)
{ {
pwalletMain->EraseFromWallet(hash); pwalletMain->EraseFromWallet(hash);
LogPrintf("ERASED spent Tx: %s\n",hash.ToString().c_str()); LogPrintf("ERASED spent Tx: %s\n",hash.ToString().c_str());
} } */
// build return JSON for stats. // build return JSON for stats.
int remaining = pwalletMain->mapWallet.size(); int remaining = pwalletMain->mapWallet.size();