|
@ -39,21 +39,33 @@ RPC::RPC(MainWindow* main) { |
|
|
// Set up timer to refresh Price
|
|
|
// Set up timer to refresh Price
|
|
|
priceTimer = new QTimer(main); |
|
|
priceTimer = new QTimer(main); |
|
|
QObject::connect(priceTimer, &QTimer::timeout, [=]() { |
|
|
QObject::connect(priceTimer, &QTimer::timeout, [=]() { |
|
|
|
|
|
qDebug() << "Refreshing price data"; |
|
|
refreshPrice(); |
|
|
refreshPrice(); |
|
|
}); |
|
|
}); |
|
|
priceTimer->start(Settings::priceRefreshSpeed); |
|
|
priceTimer->start(Settings::priceRefreshSpeed); |
|
|
qDebug() << __func__ << ": started price refresh at speed=" << Settings::priceRefreshSpeed; |
|
|
qDebug() << __func__ << ": started price refresh at speed=" << Settings::priceRefreshSpeed; |
|
|
|
|
|
|
|
|
// Set up a timer to refresh the UI every few seconds
|
|
|
qDebug() << "setting up timer for rescan data"; |
|
|
|
|
|
|
|
|
|
|
|
rescanTimer = new QTimer(main); |
|
|
|
|
|
QObject::connect(rescanTimer, &QTimer::timeout, [=]() { |
|
|
|
|
|
qDebug() << "Refreshing rescan data"; |
|
|
|
|
|
refreshRescan(); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
qDebug() << __func__ << ": started rescanTimer"; |
|
|
|
|
|
rescanTimer->start(Settings::updateSpeed); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
qDebug() << __func__ << ": Setting up a timer to refresh the UI every few seconds"; |
|
|
timer = new QTimer(main); |
|
|
timer = new QTimer(main); |
|
|
QObject::connect(timer, &QTimer::timeout, [=]() { |
|
|
QObject::connect(timer, &QTimer::timeout, [=]() { |
|
|
//qDebug() << "Refreshing main UI";
|
|
|
qDebug() << "Refreshing main UI"; |
|
|
refresh(); |
|
|
refresh(); |
|
|
}); |
|
|
}); |
|
|
timer->start(Settings::updateSpeed); |
|
|
timer->start(Settings::updateSpeed); |
|
|
|
|
|
|
|
|
|
|
|
qDebug() << __func__ << ": Set up the timer to watch for tx status"; |
|
|
// Set up the timer to watch for tx status
|
|
|
|
|
|
txTimer = new QTimer(main); |
|
|
txTimer = new QTimer(main); |
|
|
QObject::connect(txTimer, &QTimer::timeout, [=]() { |
|
|
QObject::connect(txTimer, &QTimer::timeout, [=]() { |
|
|
//qDebug() << "Watching tx status";
|
|
|
//qDebug() << "Watching tx status";
|
|
@ -71,8 +83,10 @@ RPC::RPC(MainWindow* main) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
RPC::~RPC() { |
|
|
RPC::~RPC() { |
|
|
|
|
|
qDebug() << "Deleting stuff"; |
|
|
delete timer; |
|
|
delete timer; |
|
|
delete txTimer; |
|
|
delete txTimer; |
|
|
|
|
|
delete priceTimer; |
|
|
|
|
|
|
|
|
delete transactionsTableModel; |
|
|
delete transactionsTableModel; |
|
|
delete balancesTableModel; |
|
|
delete balancesTableModel; |
|
@ -92,6 +106,16 @@ void RPC::setEHushd(std::shared_ptr<QProcess> p) { |
|
|
ehushd = p; |
|
|
ehushd = p; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void RPC::pauseTimer() { |
|
|
|
|
|
qDebug() << "pausing main timer"; |
|
|
|
|
|
timer->stop(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void RPC::restartTimer() { |
|
|
|
|
|
qDebug() << "restarting main timer"; |
|
|
|
|
|
timer->start(Settings::updateSpeed); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// Called when a connection to hushd is available.
|
|
|
// Called when a connection to hushd is available.
|
|
|
void RPC::setConnection(Connection* c) { |
|
|
void RPC::setConnection(Connection* c) { |
|
|
if (c == nullptr) return; |
|
|
if (c == nullptr) return; |
|
@ -116,6 +140,7 @@ void RPC::setConnection(Connection* c) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
QJsonValue RPC::makePayload(QString method, QString param, QString param2) { |
|
|
QJsonValue RPC::makePayload(QString method, QString param, QString param2) { |
|
|
|
|
|
// qDebug() << __func__ << ": method=" << method << " payload=" << param << ", " << param2;
|
|
|
QJsonObject payload = { |
|
|
QJsonObject payload = { |
|
|
{"jsonrpc", "1.0"}, |
|
|
{"jsonrpc", "1.0"}, |
|
|
{"id", "42" }, |
|
|
{"id", "42" }, |
|
@ -126,6 +151,7 @@ QJsonValue RPC::makePayload(QString method, QString param, QString param2) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
QJsonValue RPC::makePayload(QString method, QString param) { |
|
|
QJsonValue RPC::makePayload(QString method, QString param) { |
|
|
|
|
|
// qDebug() << __func__ << ": method=" << method << " " << "payload=" << param;
|
|
|
QJsonObject payload = { |
|
|
QJsonObject payload = { |
|
|
{"jsonrpc", "1.0"}, |
|
|
{"jsonrpc", "1.0"}, |
|
|
{"id", "42" }, |
|
|
{"id", "42" }, |
|
@ -136,6 +162,7 @@ QJsonValue RPC::makePayload(QString method, QString param) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
QJsonValue RPC::makePayload(QString method, int param) { |
|
|
QJsonValue RPC::makePayload(QString method, int param) { |
|
|
|
|
|
// qDebug() << __func__ << ": method=" << method << " payload=" << param;
|
|
|
QJsonObject payload = { |
|
|
QJsonObject payload = { |
|
|
{"jsonrpc", "1.0"}, |
|
|
{"jsonrpc", "1.0"}, |
|
|
{"id", "42" }, |
|
|
{"id", "42" }, |
|
@ -146,6 +173,7 @@ QJsonValue RPC::makePayload(QString method, int param) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
QJsonValue RPC::makePayload(QString method) { |
|
|
QJsonValue RPC::makePayload(QString method) { |
|
|
|
|
|
// qDebug() << __func__ << ": method=" << method << " with no payload";
|
|
|
QJsonObject payload = { |
|
|
QJsonObject payload = { |
|
|
{"jsonrpc", "1.0"}, |
|
|
{"jsonrpc", "1.0"}, |
|
|
{"id", "42" }, |
|
|
{"id", "42" }, |
|
@ -173,6 +201,12 @@ void RPC::getRescanInfo(const std::function<void(QJsonValue)>& cb){ |
|
|
conn->doRPCWithDefaultErrorHandling(makePayload(method), cb); |
|
|
conn->doRPCWithDefaultErrorHandling(makePayload(method), cb); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// get help
|
|
|
|
|
|
void RPC::help(const std::function<void(QJsonValue)>& cb){ |
|
|
|
|
|
QString method = "help"; |
|
|
|
|
|
conn->doRPCWithDefaultErrorHandling(makePayload(method), cb); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// add/remove a banned node. ip can include an optional netmask
|
|
|
// add/remove a banned node. ip can include an optional netmask
|
|
|
void RPC::setban(QString ip, QString command, const std::function<void(QJsonValue)>& cb) { |
|
|
void RPC::setban(QString ip, QString command, const std::function<void(QJsonValue)>& cb) { |
|
|
QString method = "setban"; |
|
|
QString method = "setban"; |
|
@ -965,6 +999,41 @@ void RPC::refreshBalances() { |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void RPC::refreshRescan() { |
|
|
|
|
|
qDebug() << __func__; |
|
|
|
|
|
if (conn == nullptr) { |
|
|
|
|
|
return noConnection(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
conn->doRPC(makePayload("help", "getrescaninfo"), [=] (const QJsonValue& reply) { |
|
|
|
|
|
qDebug() << __func__ << ": found getrescaninfo: reply=" << reply; |
|
|
|
|
|
// Get rescan info
|
|
|
|
|
|
QObject::connect(rescanTimer, &QTimer::timeout, [=]() { |
|
|
|
|
|
qDebug() << "setting callback for getrescaninfo"; |
|
|
|
|
|
getRescanInfo([=] (QJsonValue response){ |
|
|
|
|
|
qDebug() << "got getrescaninfo json"; |
|
|
|
|
|
auto rescanning = response.toObject().value("rescanning").toBool(); |
|
|
|
|
|
auto rescan_progress = response.toObject().value("rescan_progress").toString(); |
|
|
|
|
|
auto rescan_start_height = (qint64)response.toObject().value("rescan_start_height").toInt(); |
|
|
|
|
|
auto rescan_height = (qint64)response.toObject().value("rescan_height").toInt(); |
|
|
|
|
|
double percent = QString(rescan_progress).toDouble() * 100; |
|
|
|
|
|
qDebug() << __func__ << ": getrescaninfo" << rescanning << " " << percent << " " << rescan_start_height << " " << rescan_height; |
|
|
|
|
|
|
|
|
|
|
|
if(rescanning){ |
|
|
|
|
|
pauseTimer(); |
|
|
|
|
|
qDebug() << __func__ << ": Rescanning at " << percent << " %"; |
|
|
|
|
|
ui->statusBar->showMessage(QObject::tr("Rescanning... ") + QString::number(percent)+ "% " + QObject::tr("at height") + " " + QString::number(rescan_height)); |
|
|
|
|
|
} else{ |
|
|
|
|
|
qDebug() << __func__ << ": not rescanning"; |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
}); |
|
|
|
|
|
}, [=](QNetworkReply* reply, const QJsonValue&) { |
|
|
|
|
|
qDebug() << __func__ << ": missing getrescaninfo, no rescan progress will be shown: reply=" << reply; |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
void RPC::refreshPeers() { |
|
|
void RPC::refreshPeers() { |
|
|
qDebug() << __func__; |
|
|
qDebug() << __func__; |
|
|
if (conn == nullptr) |
|
|
if (conn == nullptr) |
|
|