Initial implementation of getrescaninfo
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
// Copyright (c) 2016-2022 The Hush developers
|
||||
// Distributed under the GPLv3 software license, see the accompanying
|
||||
// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
|
||||
|
||||
/******************************************************************************
|
||||
* Copyright © 2014-2019 The SuperNET Developers. *
|
||||
* *
|
||||
@@ -17,7 +16,6 @@
|
||||
* Removal or modification of this copyright notice is prohibited. *
|
||||
* *
|
||||
******************************************************************************/
|
||||
|
||||
#include "chain.h"
|
||||
#include "key_io.h"
|
||||
#include "rpc/server.h"
|
||||
@@ -29,13 +27,10 @@
|
||||
#include "util.h"
|
||||
#include "utiltime.h"
|
||||
#include "wallet.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <boost/date_time/posix_time/posix_time.hpp>
|
||||
|
||||
#include <univalue.h>
|
||||
|
||||
using namespace std;
|
||||
@@ -149,6 +144,39 @@ UniValue convertpassphrase(const UniValue& params, bool fHelp, const CPubKey& my
|
||||
return ret;
|
||||
}
|
||||
|
||||
UniValue getrescaninfo(const UniValue& params, bool fHelp, const CPubKey& mypk)
|
||||
{
|
||||
if (!EnsureWalletIsAvailable(fHelp))
|
||||
return NullUniValue;
|
||||
|
||||
if (fHelp || params.size() > 0)
|
||||
throw runtime_error(
|
||||
"getrescaninfo\n"
|
||||
"\nGet rescan info such as starting height and current height.\n"
|
||||
"\nArguments: none\n"
|
||||
"\nExamples:\n"
|
||||
"\nGet rescan info:\n"
|
||||
+ HelpExampleCli("getrescaninfo","")
|
||||
);
|
||||
UniValue ret(UniValue::VOBJ);
|
||||
auto rescanning = pwalletMain->fRescanning;
|
||||
ret.push_back(Pair("rescanning", rescanning));
|
||||
if(rescanning) {
|
||||
auto rescanHeight = pwalletMain->rescanHeight;
|
||||
auto startHeight = pwalletMain->rescanStartHeight;
|
||||
auto currentHeight = chainActive.Height();
|
||||
// if current height is 0, progress=1 since there is nothing to rescan
|
||||
char progress[8];
|
||||
if (currentHeight != 0) {
|
||||
sprintf(progress, "%.4f", (double) rescanHeight / (double) currentHeight );
|
||||
ret.push_back(Pair("rescan_progress", progress));
|
||||
}
|
||||
ret.push_back(Pair("rescan_start_height", startHeight));
|
||||
ret.push_back(Pair("rescan_height", rescanHeight));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
UniValue rescan(const UniValue& params, bool fHelp, const CPubKey& mypk)
|
||||
{
|
||||
//LOCK2(cs_main, pwalletMain->cs_wallet);
|
||||
|
||||
@@ -8503,6 +8503,7 @@ extern UniValue z_importviewingkey(const UniValue& params, bool fHelp, const CPu
|
||||
extern UniValue z_exportwallet(const UniValue& params, bool fHelp, const CPubKey& mypk);
|
||||
extern UniValue z_importwallet(const UniValue& params, bool fHelp, const CPubKey& mypk);
|
||||
extern UniValue rescan(const UniValue& params, bool fHelp, const CPubKey& mypk);
|
||||
extern UniValue getrescaninfo(const UniValue& params, bool fHelp, const CPubKey& mypk);
|
||||
|
||||
|
||||
static const CRPCCommand commands[] =
|
||||
@@ -8544,6 +8545,7 @@ static const CRPCCommand commands[] =
|
||||
{ "wallet", "lockunspent", &lockunspent, true },
|
||||
{ "wallet", "move", &movecmd, false },
|
||||
{ "wallet", "rescan", &rescan, false },
|
||||
{ "wallet", "getrescaninfo", &getrescaninfo, true },
|
||||
{ "wallet", "sendfrom", &sendfrom, false },
|
||||
{ "wallet", "sendmany", &sendmany, false },
|
||||
{ "wallet", "sendtoaddress", &sendtoaddress, false },
|
||||
|
||||
@@ -2760,6 +2760,7 @@ int CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate)
|
||||
if(fZdebug)
|
||||
LogPrintf("%s: fUpdate=%d now=%li\n",__func__,fUpdate,nNow);
|
||||
|
||||
pwalletMain->fRescanning = true;
|
||||
CBlockIndex* pindex = pindexStart;
|
||||
{
|
||||
LOCK2(cs_main, cs_wallet);
|
||||
@@ -2772,8 +2773,11 @@ int CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate)
|
||||
ShowProgress(_("Rescanning..."), 0); // show rescan progress in GUI as dialog or on splashscreen, if -rescan on startup
|
||||
double dProgressStart = Checkpoints::GuessVerificationProgress(chainParams.Checkpoints(), pindex, false);
|
||||
double dProgressTip = Checkpoints::GuessVerificationProgress(chainParams.Checkpoints(), chainActive.LastTip(), false);
|
||||
|
||||
pwalletMain->rescanStartHeight = pindex->GetHeight();
|
||||
while (pindex)
|
||||
{
|
||||
pwalletMain->rescanHeight = pindex->GetHeight();
|
||||
if (pindex->GetHeight() % 100 == 0 && dProgressTip - dProgressStart > 0.0)
|
||||
ShowProgress(_("Rescanning..."), std::max(1, std::min(99, (int)((Checkpoints::GuessVerificationProgress(chainParams.Checkpoints(), pindex, false) - dProgressStart) / (dProgressTip - dProgressStart) * 100))));
|
||||
|
||||
@@ -2825,6 +2829,9 @@ int CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate)
|
||||
|
||||
ShowProgress(_("Rescanning..."), 100); // hide progress dialog in GUI
|
||||
}
|
||||
|
||||
// we are no longer rescanning
|
||||
pwalletMain->fRescanning = false;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -807,6 +807,13 @@ public:
|
||||
bool fSweepEnabled = false;
|
||||
bool fSweepExternalEnabled = false;
|
||||
bool fSweepRunning = false;
|
||||
// Are we currently rescanning?
|
||||
bool fRescanning = false;
|
||||
// Current height of our rescan
|
||||
int rescanHeight = 0;
|
||||
// Starting height of our rescan
|
||||
int rescanStartHeight = 0;
|
||||
|
||||
int nextSweep = 0;
|
||||
int amountSwept = 0;
|
||||
int amountConsolidated = 0;
|
||||
|
||||
Reference in New Issue
Block a user