8 #include "ui_rpcconsole.h"
30 #include <QStringList>
54 {
"cmd-request",
":/icons/tx_input"},
55 {
"cmd-reply",
":/icons/tx_output"},
56 {
"cmd-error",
":/icons/tx_output"},
57 {
"misc",
":/icons/tx_inout"},
60 RPCConsole::RPCConsole(QWidget* parent) : QDialog(parent, Qt::WindowSystemMenuHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint),
66 peersTableContextMenu(nullptr),
67 banTableContextMenu(nullptr)
73 ui->openDebugLogfileButton->setIcon(QIcon(
":/icons/export"));
77 ui->lineEdit->installEventFilter(
this);
78 ui->messagesWidget->installEventFilter(
this);
94 ui->berkeleyDBVersion->setText(DbEnv::version(0, 0, 0));
97 ui->label_berkeleyDBVersion->hide();
98 ui->berkeleyDBVersion->hide();
109 ui->peerHeading->setText(tr(
"Select a peer to view detailed information."));
125 if (event->type() == QEvent::KeyPress)
127 QKeyEvent* keyevt =
static_cast<QKeyEvent*
>(event);
128 int key = keyevt->key();
129 Qt::KeyboardModifiers mod = keyevt->modifiers();
132 if (obj ==
ui->lineEdit) {
138 if (obj ==
ui->lineEdit) {
144 case Qt::Key_PageDown:
145 if (obj ==
ui->lineEdit) {
146 QApplication::postEvent(
ui->messagesWidget,
new QKeyEvent(*keyevt));
154 QApplication::postEvent(
ui->lineEdit,
new QKeyEvent(*keyevt));
161 if (obj ==
ui->messagesWidget && ((!mod && !keyevt->text().isEmpty() && key != Qt::Key_Tab) ||
162 ((mod & Qt::ControlModifier) && key == Qt::Key_V) ||
163 ((mod & Qt::ShiftModifier) && key == Qt::Key_Insert))) {
164 ui->lineEdit->setFocus();
165 QApplication::postEvent(
ui->lineEdit,
new QKeyEvent(*keyevt));
170 return QDialog::eventFilter(obj, event);
176 ui->trafficGraph->setClientModel(model);
196 ui->peerWidget->verticalHeader()->hide();
197 ui->peerWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
198 ui->peerWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
199 ui->peerWidget->setSelectionMode(QAbstractItemView::SingleSelection);
200 ui->peerWidget->setContextMenuPolicy(Qt::CustomContextMenu);
204 ui->peerWidget->horizontalHeader()->setStretchLastSection(
true);
207 QAction* disconnectAction =
new QAction(tr(
"&Disconnect Node"),
this);
208 QAction* banAction1h =
new QAction(tr(
"Ban Node for") +
" " + tr(
"1 &hour"),
this);
209 QAction* banAction24h =
new QAction(tr(
"Ban Node for") +
" " + tr(
"1 &day"),
this);
210 QAction* banAction7d =
new QAction(tr(
"Ban Node for") +
" " + tr(
"1 &week"),
this);
211 QAction* banAction365d =
new QAction(tr(
"Ban Node for") +
" " + tr(
"1 &year"),
this);
221 connect(banAction1h, &QAction::triggered, [
this] {
banSelectedNode(60 * 60); });
222 connect(banAction24h, &QAction::triggered, [
this] {
banSelectedNode(60 * 60 * 24); });
223 connect(banAction7d, &QAction::triggered, [
this] {
banSelectedNode(60 * 60 * 24 * 7); });
224 connect(banAction365d, &QAction::triggered, [
this] {
banSelectedNode(60 * 60 * 24 * 365); });
237 ui->banlistWidget->verticalHeader()->hide();
238 ui->banlistWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
239 ui->banlistWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
240 ui->banlistWidget->setSelectionMode(QAbstractItemView::SingleSelection);
241 ui->banlistWidget->setContextMenuPolicy(Qt::CustomContextMenu);
244 ui->banlistWidget->horizontalHeader()->setStretchLastSection(
true);
247 QAction* unbanAction =
new QAction(tr(
"&Unban Node"),
this);
268 ui->networkName->setText(QString::fromStdString(
Params().NetworkIDString()));
271 QStringList wordList;
273 for (
size_t i = 0; i < commandList.size(); ++i)
275 wordList << commandList[i].c_str();
276 wordList << (
"help " + commandList[i]).c_str();
279 wordList <<
"help-console";
282 autoCompleter->setModelSorting(QCompleter::CaseSensitivelySortedModel);
337 QString resyncWarning = tr(
"This will delete your local blockchain folders and the wallet will synchronize the complete Blockchain from scratch.<br /><br />");
338 resyncWarning += tr(
"This needs quite some time and downloads a lot of data.<br /><br />");
339 resyncWarning += tr(
"Your transactions and funds will be visible again after the download has completed.<br /><br />");
340 resyncWarning += tr(
"Do you want to continue?.<br />");
341 QMessageBox::StandardButton retval = QMessageBox::question(
this, tr(
"Confirm resync Blockchain"),
343 QMessageBox::Yes | QMessageBox::Cancel,
344 QMessageBox::Cancel);
346 if (retval != QMessageBox::Yes) {
359 QStringList args = QApplication::arguments();
379 ui->messagesWidget->clear();
382 ui->lineEdit->clear();
383 ui->lineEdit->setFocus();
388 ui->messagesWidget->document()->addResource(
389 QTextDocument::ImageResource,
395 ui->messagesWidget->document()->setDefaultStyleSheet(
397 "td.time { color: #808080; padding-top: 3px; } "
398 "td.message { font-family: Courier, Courier New, Lucida Console, monospace; font-size: 12px; } "
399 "td.cmd-request { color: #006060; } "
400 "td.cmd-error { color: red; } "
401 ".secwarning { color: red; }"
402 "b { color: #006060; } ");
405 QString clsKey =
"(⌘)-L";
407 QString clsKey =
"Ctrl-L";
411 tr(
"Use up and down arrows to navigate history, and %1 to clear screen.").arg(
"<b>"+clsKey+
"</b>") +
"<br>" +
412 tr(
"Type %1 for an overview of available commands.").arg(
"<b>help</b>") +
"<br>" +
413 tr(
"For more information on using this console type %1.").arg(
"<b>help-console</b>") +
414 "<br><span class=\"secwarning\"><br>" +
415 tr(
"WARNING: Scammers have been active, telling users to type commands here, stealing their wallet contents. Do not use this console without fully understanding the ramifications of a command.") +
423 if (windowType() != Qt::Widget)
429 QTime time = QTime::currentTime();
430 QString timeString = time.toString();
432 out +=
"<table><tr><td class=\"time\" width=\"65\">" + timeString +
"</td>";
439 out +=
"</td></tr></table>";
440 ui->messagesWidget->append(out);
447 if (!netActivityState && numConnections == 0) {
448 connections = tr(
"Network activity disabled");
450 connections = QString::number(numConnections) +
" (";
453 if(!netActivityState) {
454 connections +=
" " + tr(
"Network activity disabled");
457 ui->numberOfConnections->setText(connections);
476 ui->numberOfBlocks->setText(QString::number(count));
485 ui->masternodeCount->setText(strMasternodes);
490 QString cmd =
ui->lineEdit->text();
491 ui->lineEdit->clear();
493 if (!cmd.isEmpty()) {
520 ui->lineEdit->setText(cmd);
525 QThread* thread =
new QThread;
527 executor->moveToThread(thread);
540 connect(thread, &QThread::finished, thread, &QThread::deleteLater);
549 if (
ui->tabWidget->widget(index) ==
ui->tab_console) {
550 ui->lineEdit->setFocus();
551 }
else if (
ui->tabWidget->widget(index) !=
ui->tab_peers) {
563 QScrollBar* scrollbar =
ui->messagesWidget->verticalScrollBar();
564 scrollbar->setValue(scrollbar->maximum());
569 const int multiplier = 5;
570 int mins = value * multiplier;
577 return QString(tr(
"%1 B")).arg(bytes);
578 if (bytes < 1024 * 1024)
579 return QString(tr(
"%1 KB")).arg(bytes / 1024);
580 if (bytes < 1024 * 1024 * 1024)
581 return QString(tr(
"%1 MB")).arg(bytes / 1024 / 1024);
583 return QString(tr(
"%1 GB")).arg(bytes / 1024 / 1024 / 1024);
588 ui->trafficGraph->setGraphRangeMins(mins);
600 ui->tabWidget->setCurrentIndex(0);
606 ui->tabWidget->setCurrentIndex(1);
612 ui->tabWidget->setCurrentIndex(2);
618 ui->tabWidget->setCurrentIndex(3);
624 ui->tabWidget->setCurrentIndex(4);
640 Q_UNUSED(deselected);
656 bool fUnselect =
false;
657 bool fReselect =
false;
663 int selectedRow = -1;
664 QModelIndexList selectedModelIndex =
ui->peerWidget->selectionModel()->selectedIndexes();
665 if (!selectedModelIndex.isEmpty()) {
666 selectedRow = selectedModelIndex.first().row();
673 if (detailNodeRow < 0) {
677 if (detailNodeRow != selectedRow) {
687 if (fUnselect && selectedRow >= 0) {
692 ui->peerWidget->selectRow(detailNodeRow);
705 QString peerAddrDetails(QString::fromStdString(stats->
nodeStats.
addrName) +
" ");
706 peerAddrDetails += tr(
"(node id: %1)").arg(QString::number(stats->
nodeStats.
nodeid));
708 peerAddrDetails +=
"<br />" + tr(
"via %1").arg(QString::fromStdString(stats->
nodeStats.
addrLocal));
709 ui->peerHeading->setText(peerAddrDetails);
735 ui->peerSyncHeight->setText(tr(
"Unknown"));
741 ui->peerCommonHeight->setText(tr(
"Unknown"));
744 ui->detailWidget->show();
749 QWidget::resizeEvent(event);
754 QWidget::showEvent(event);
766 QWidget::hideEvent(event);
783 QModelIndex index =
ui->peerWidget->indexAt(point);
790 QModelIndex index =
ui->banlistWidget->indexAt(point);
817 if (selectedNodeRow < 0)
829 if (!
LookupHost(addr.c_str(), resolved,
false))
845 LookupSubNet(strNode.toStdString().c_str(), possibleSubnet);
855 ui->peerWidget->selectionModel()->clearSelection();
857 ui->detailWidget->hide();
858 ui->peerHeading->setText(tr(
"Select a peer to view detailed information."));
867 ui->banlistWidget->setVisible(visible);
868 ui->banHeading->setVisible(visible);
const CChainParams & Params()
Return the currently selected parameters.
std::vector< std::string > listCommands() const
Returns a list of registered commands.
Model for PIVX network client.
void bytesChanged(quint64 totalBytesIn, quint64 totalBytesOut)
QString getLastBlockHash() const
QString clientName() const
quint64 getTotalBytesRecv() const
quint64 getTotalBytesSent() const
void startMasternodesTimer()
PeerTableModel * getPeerTableModel()
void numBlocksChanged(int count)
void stopMasternodesTimer()
QDateTime getLastBlockDate() const
void strMasternodesChanged(const QString &strMasternodes)
void numConnectionsChanged(int count)
bool getNetworkActive() const
Return true if network activity in core is enabled.
QString formatClientStartupTime() const
int getNumConnections(unsigned int flags=CONNECTIONS_ALL) const
Return number of connections, default is in- and outbound (total)
BanTableModel * getBanTableModel()
QString formatFullVersion() const
void networkActiveChanged(bool networkActive)
const CNodeCombinedStats * getNodeStats(int idx)
int getRowByNodeId(NodeId nodeid)
Local Bitcoin RPC console.
void showBackups()
Show folder with wallet backups in default browser.
QMenu * peersTableContextMenu
void updateNodeDetail(const CNodeCombinedStats *stats)
show detailed information on ui about selected node
void resizeEvent(QResizeEvent *event)
WalletModel * walletModel
void handleRestart(QStringList args)
Get restart command-line parameters and handle restart.
void browseHistory(int offset)
Go forward or back in history.
void setWalletModel(WalletModel *model)
void setMasternodeCount(const QString &strMasternodes)
Set number of masternodes shown in the UI.
void peerSelected(const QItemSelection &selected, const QItemSelection &deselected)
Handle selection of peer in peers list.
RPCTimerInterface * rpcTimerInterface
void on_lineEdit_returnPressed()
void buildParameterlist(QString arg)
Build parameter list for restart.
void walletResync()
Restart wallet with "-resync".
void setClientModel(ClientModel *model)
void message(int category, const QString &msg)
void updateTrafficStats(quint64 totalBytesIn, quint64 totalBytesOut)
update traffic statistics
void setTrafficGraphRange(int mins)
void updateNetworkState(int num_connections)
Update UI with latest network info from model.
void cmdRequest(const QString &command)
void walletUpgrade()
Restart wallet with "-upgradewallet".
void disconnectSelectedNode()
Disconnect a selected node on the Peers tab.
@ SUBVERSION_COLUMN_WIDTH
QCompleter * autoCompleter
void showRepair()
Switch to wallet-repair tab and show.
virtual bool eventFilter(QObject *obj, QEvent *event)
void walletRescan()
Restart wallet with "-rescan".
void showMNConfEditor()
Open external (default) editor with masternode.conf.
void showPeersTableContextMenu(const QPoint &point)
Show custom context menu on Peers tab.
void showPeers()
Switch to peers tab and show.
void setNumBlocks(int count)
Set number of blocks shown in the UI.
void unbanSelectedNode()
Unban a selected node on the Bans tab.
void clearSelectedNode()
clear the selected node
void on_sldGraphRange_valueChanged(int value)
change the time range of the network traffic graph
void setNumConnections(int count)
Set number of connections shown in the UI.
ClientModel * clientModel
void banSelectedNode(int bantime)
Ban a selected node on the Peers tab.
void scrollToEnd()
Scroll console view to end.
void hideEvent(QHideEvent *event)
void showConfEditor()
Open external (default) editor with pivx.conf.
void walletZaptxes2()
Restart wallet with "-zapwallettxes=2".
void walletZaptxes1()
Restart wallet with "-zapwallettxes=1".
void on_tabWidget_currentChanged(int index)
void walletReindex()
Restart wallet with "-reindex".
void setNetworkActive(bool networkActive)
Set network state shown in the UI.
void walletSalvage()
Wallet repair options.
void on_openDebugLogfileButton_clicked()
open the debug.log from the current datadir
void showBanTableContextMenu(const QPoint &point)
Show custom context menu on Bans tab.
void showInfo()
Switch to info tab and show.
void showConsole()
Switch to console tab and show.
RPCConsole(QWidget *parent)
void showEvent(QShowEvent *event)
void showOrHideBanTableIfRequired()
Hides ban table if no bans are present.
QMenu * banTableContextMenu
void peerLayoutChanged()
Handle updated peer information.
static QString FormatBytes(quint64 bytes)
void showNetwork()
Switch to network tab and show.
void reply(int category, const QString &command)
void request(const QString &command)
static QString categoryClass(int category)
Interface to PIVX wallet from Qt view code.
std::unique_ptr< CConnman > g_connman
QString HtmlEscape(const QString &str, bool fMultiLine)
QString formatPingTime(double dPingTime)
void saveWindowGeometry(const QString &strSetting, QWidget *parent)
Save window size and position.
void restoreWindowGeometry(const QString &strSetting, const QSize &defaultSize, QWidget *parent)
Restore window size and position.
QString formatDurationStr(int secs)
QVariant getEntryData(QAbstractItemView *view, int column, int role)
Return a field of the currently selected entry as a QString.
QString formatTimeOffset(int64_t nTimeOffset)
QString formatServicesStr(quint64 mask)
void SplitHostPort(std::string in, int &portOut, std::string &hostOut)
bool LookupHost(const std::string &name, std::vector< CNetAddr > &vIP, unsigned int nMaxSolutions, bool fAllowLookup)
bool LookupSubNet(const std::string &strSubnet, CSubNet &ret)
const struct @24 ICON_MAPPING[]
const QString ZAPTXES1("-zapwallettxes=1")
const QString ZAPTXES2("-zapwallettxes=2")
const QSize ICON_SIZE(24, 24)
const QString UPGRADEWALLET("-upgradewallet")
const int INITIAL_TRAFFIC_GRAPH_MINS
const int CONSOLE_HISTORY
const QString SALVAGEWALLET("-salvagewallet")
const QString REINDEX("-reindex")
const QString RESYNC("-resync")
const QString RESCAN("-rescan")
void RPCSetTimerInterfaceIfUnset(RPCTimerInterface *iface)
Set factory function for timers, but only if unset.
void RPCUnsetTimerInterface(RPCTimerInterface *iface)
Unset factory function for timers.
CNodeStateStats nodeStateStats
bool fNodeStateStatsAvailable
int64_t GetSystemTimeInSeconds()
Returns the system time (not mockable)