Bitcoin Core  22.99.0
P2P Digital Currency
rpcconsole.cpp
Go to the documentation of this file.
1 // Copyright (c) 2011-2020 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #if defined(HAVE_CONFIG_H)
7 #endif
8 
9 #include <qt/rpcconsole.h>
10 #include <qt/forms/ui_debugwindow.h>
11 
12 #include <chainparams.h>
13 #include <interfaces/node.h>
14 #include <netbase.h>
15 #include <qt/bantablemodel.h>
16 #include <qt/clientmodel.h>
17 #include <qt/peertablesortproxy.h>
18 #include <qt/platformstyle.h>
19 #include <qt/walletmodel.h>
20 #include <rpc/client.h>
21 #include <rpc/server.h>
22 #include <util/strencodings.h>
23 #include <util/string.h>
24 #include <util/system.h>
25 #include <util/threadnames.h>
26 
27 #include <univalue.h>
28 
29 #ifdef ENABLE_WALLET
30 #ifdef USE_BDB
31 #include <wallet/bdb.h>
32 #endif
33 #include <wallet/db.h>
34 #include <wallet/wallet.h>
35 #endif
36 
37 #include <QAbstractButton>
38 #include <QAbstractItemModel>
39 #include <QDateTime>
40 #include <QFont>
41 #include <QKeyEvent>
42 #include <QLatin1String>
43 #include <QLocale>
44 #include <QMenu>
45 #include <QMessageBox>
46 #include <QScreen>
47 #include <QScrollBar>
48 #include <QSettings>
49 #include <QString>
50 #include <QStringList>
51 #include <QStyledItemDelegate>
52 #include <QTime>
53 #include <QTimer>
54 #include <QVariant>
55 
56 const int CONSOLE_HISTORY = 50;
58 const QSize FONT_RANGE(4, 40);
59 const char fontSizeSettingsKey[] = "consoleFontSize";
60 
61 const struct {
62  const char *url;
63  const char *source;
64 } ICON_MAPPING[] = {
65  {"cmd-request", ":/icons/tx_input"},
66  {"cmd-reply", ":/icons/tx_output"},
67  {"cmd-error", ":/icons/tx_output"},
68  {"misc", ":/icons/tx_inout"},
69  {nullptr, nullptr}
70 };
71 
72 namespace {
73 
74 // don't add private key handling cmd's to the history
75 const QStringList historyFilter = QStringList()
76  << "importprivkey"
77  << "importmulti"
78  << "sethdseed"
79  << "signmessagewithprivkey"
80  << "signrawtransactionwithkey"
81  << "walletpassphrase"
82  << "walletpassphrasechange"
83  << "encryptwallet";
84 
85 }
86 
87 /* Object for executing console RPC commands in a separate thread.
88 */
89 class RPCExecutor : public QObject
90 {
91  Q_OBJECT
92 public:
94 
95 public Q_SLOTS:
96  void request(const QString &command, const WalletModel* wallet_model);
97 
98 Q_SIGNALS:
99  void reply(int category, const QString &command);
100 
101 private:
103 };
104 
108 class QtRPCTimerBase: public QObject, public RPCTimerBase
109 {
110  Q_OBJECT
111 public:
112  QtRPCTimerBase(std::function<void()>& _func, int64_t millis):
113  func(_func)
114  {
115  timer.setSingleShot(true);
116  connect(&timer, &QTimer::timeout, [this]{ func(); });
117  timer.start(millis);
118  }
120 private:
121  QTimer timer;
122  std::function<void()> func;
123 };
124 
126 {
127 public:
129  const char *Name() override { return "Qt"; }
130  RPCTimerBase* NewTimer(std::function<void()>& func, int64_t millis) override
131  {
132  return new QtRPCTimerBase(func, millis);
133  }
134 };
135 
136 class PeerIdViewDelegate : public QStyledItemDelegate
137 {
138  Q_OBJECT
139 public:
140  explicit PeerIdViewDelegate(QObject* parent = nullptr)
141  : QStyledItemDelegate(parent) {}
142 
143  QString displayText(const QVariant& value, const QLocale& locale) const override
144  {
145  // Additional spaces should visually separate right-aligned content
146  // from the next column to the right.
147  return value.toString() + QLatin1String(" ");
148  }
149 };
150 
151 #include <qt/rpcconsole.moc>
152 
173 bool RPCConsole::RPCParseCommandLine(interfaces::Node* node, std::string &strResult, const std::string &strCommand, const bool fExecute, std::string * const pstrFilteredOut, const WalletModel* wallet_model)
174 {
175  std::vector< std::vector<std::string> > stack;
176  stack.push_back(std::vector<std::string>());
177 
178  enum CmdParseState
179  {
180  STATE_EATING_SPACES,
181  STATE_EATING_SPACES_IN_ARG,
182  STATE_EATING_SPACES_IN_BRACKETS,
183  STATE_ARGUMENT,
184  STATE_SINGLEQUOTED,
185  STATE_DOUBLEQUOTED,
186  STATE_ESCAPE_OUTER,
187  STATE_ESCAPE_DOUBLEQUOTED,
188  STATE_COMMAND_EXECUTED,
189  STATE_COMMAND_EXECUTED_INNER
190  } state = STATE_EATING_SPACES;
191  std::string curarg;
192  UniValue lastResult;
193  unsigned nDepthInsideSensitive = 0;
194  size_t filter_begin_pos = 0, chpos;
195  std::vector<std::pair<size_t, size_t>> filter_ranges;
196 
197  auto add_to_current_stack = [&](const std::string& strArg) {
198  if (stack.back().empty() && (!nDepthInsideSensitive) && historyFilter.contains(QString::fromStdString(strArg), Qt::CaseInsensitive)) {
199  nDepthInsideSensitive = 1;
200  filter_begin_pos = chpos;
201  }
202  // Make sure stack is not empty before adding something
203  if (stack.empty()) {
204  stack.push_back(std::vector<std::string>());
205  }
206  stack.back().push_back(strArg);
207  };
208 
209  auto close_out_params = [&]() {
210  if (nDepthInsideSensitive) {
211  if (!--nDepthInsideSensitive) {
212  assert(filter_begin_pos);
213  filter_ranges.push_back(std::make_pair(filter_begin_pos, chpos));
214  filter_begin_pos = 0;
215  }
216  }
217  stack.pop_back();
218  };
219 
220  std::string strCommandTerminated = strCommand;
221  if (strCommandTerminated.back() != '\n')
222  strCommandTerminated += "\n";
223  for (chpos = 0; chpos < strCommandTerminated.size(); ++chpos)
224  {
225  char ch = strCommandTerminated[chpos];
226  switch(state)
227  {
228  case STATE_COMMAND_EXECUTED_INNER:
229  case STATE_COMMAND_EXECUTED:
230  {
231  bool breakParsing = true;
232  switch(ch)
233  {
234  case '[': curarg.clear(); state = STATE_COMMAND_EXECUTED_INNER; break;
235  default:
236  if (state == STATE_COMMAND_EXECUTED_INNER)
237  {
238  if (ch != ']')
239  {
240  // append char to the current argument (which is also used for the query command)
241  curarg += ch;
242  break;
243  }
244  if (curarg.size() && fExecute)
245  {
246  // if we have a value query, query arrays with index and objects with a string key
247  UniValue subelement;
248  if (lastResult.isArray())
249  {
250  for(char argch: curarg)
251  if (!IsDigit(argch))
252  throw std::runtime_error("Invalid result query");
253  subelement = lastResult[atoi(curarg.c_str())];
254  }
255  else if (lastResult.isObject())
256  subelement = find_value(lastResult, curarg);
257  else
258  throw std::runtime_error("Invalid result query"); //no array or object: abort
259  lastResult = subelement;
260  }
261 
262  state = STATE_COMMAND_EXECUTED;
263  break;
264  }
265  // don't break parsing when the char is required for the next argument
266  breakParsing = false;
267 
268  // pop the stack and return the result to the current command arguments
269  close_out_params();
270 
271  // don't stringify the json in case of a string to avoid doublequotes
272  if (lastResult.isStr())
273  curarg = lastResult.get_str();
274  else
275  curarg = lastResult.write(2);
276 
277  // if we have a non empty result, use it as stack argument otherwise as general result
278  if (curarg.size())
279  {
280  if (stack.size())
281  add_to_current_stack(curarg);
282  else
283  strResult = curarg;
284  }
285  curarg.clear();
286  // assume eating space state
287  state = STATE_EATING_SPACES;
288  }
289  if (breakParsing)
290  break;
291  [[fallthrough]];
292  }
293  case STATE_ARGUMENT: // In or after argument
294  case STATE_EATING_SPACES_IN_ARG:
295  case STATE_EATING_SPACES_IN_BRACKETS:
296  case STATE_EATING_SPACES: // Handle runs of whitespace
297  switch(ch)
298  {
299  case '"': state = STATE_DOUBLEQUOTED; break;
300  case '\'': state = STATE_SINGLEQUOTED; break;
301  case '\\': state = STATE_ESCAPE_OUTER; break;
302  case '(': case ')': case '\n':
303  if (state == STATE_EATING_SPACES_IN_ARG)
304  throw std::runtime_error("Invalid Syntax");
305  if (state == STATE_ARGUMENT)
306  {
307  if (ch == '(' && stack.size() && stack.back().size() > 0)
308  {
309  if (nDepthInsideSensitive) {
310  ++nDepthInsideSensitive;
311  }
312  stack.push_back(std::vector<std::string>());
313  }
314 
315  // don't allow commands after executed commands on baselevel
316  if (!stack.size())
317  throw std::runtime_error("Invalid Syntax");
318 
319  add_to_current_stack(curarg);
320  curarg.clear();
321  state = STATE_EATING_SPACES_IN_BRACKETS;
322  }
323  if ((ch == ')' || ch == '\n') && stack.size() > 0)
324  {
325  if (fExecute) {
326  // Convert argument list to JSON objects in method-dependent way,
327  // and pass it along with the method name to the dispatcher.
328  UniValue params = RPCConvertValues(stack.back()[0], std::vector<std::string>(stack.back().begin() + 1, stack.back().end()));
329  std::string method = stack.back()[0];
330  std::string uri;
331 #ifdef ENABLE_WALLET
332  if (wallet_model) {
333  QByteArray encodedName = QUrl::toPercentEncoding(wallet_model->getWalletName());
334  uri = "/wallet/"+std::string(encodedName.constData(), encodedName.length());
335  }
336 #endif
337  assert(node);
338  lastResult = node->executeRpc(method, params, uri);
339  }
340 
341  state = STATE_COMMAND_EXECUTED;
342  curarg.clear();
343  }
344  break;
345  case ' ': case ',': case '\t':
346  if(state == STATE_EATING_SPACES_IN_ARG && curarg.empty() && ch == ',')
347  throw std::runtime_error("Invalid Syntax");
348 
349  else if(state == STATE_ARGUMENT) // Space ends argument
350  {
351  add_to_current_stack(curarg);
352  curarg.clear();
353  }
354  if ((state == STATE_EATING_SPACES_IN_BRACKETS || state == STATE_ARGUMENT) && ch == ',')
355  {
356  state = STATE_EATING_SPACES_IN_ARG;
357  break;
358  }
359  state = STATE_EATING_SPACES;
360  break;
361  default: curarg += ch; state = STATE_ARGUMENT;
362  }
363  break;
364  case STATE_SINGLEQUOTED: // Single-quoted string
365  switch(ch)
366  {
367  case '\'': state = STATE_ARGUMENT; break;
368  default: curarg += ch;
369  }
370  break;
371  case STATE_DOUBLEQUOTED: // Double-quoted string
372  switch(ch)
373  {
374  case '"': state = STATE_ARGUMENT; break;
375  case '\\': state = STATE_ESCAPE_DOUBLEQUOTED; break;
376  default: curarg += ch;
377  }
378  break;
379  case STATE_ESCAPE_OUTER: // '\' outside quotes
380  curarg += ch; state = STATE_ARGUMENT;
381  break;
382  case STATE_ESCAPE_DOUBLEQUOTED: // '\' in double-quoted text
383  if(ch != '"' && ch != '\\') curarg += '\\'; // keep '\' for everything but the quote and '\' itself
384  curarg += ch; state = STATE_DOUBLEQUOTED;
385  break;
386  }
387  }
388  if (pstrFilteredOut) {
389  if (STATE_COMMAND_EXECUTED == state) {
390  assert(!stack.empty());
391  close_out_params();
392  }
393  *pstrFilteredOut = strCommand;
394  for (auto i = filter_ranges.rbegin(); i != filter_ranges.rend(); ++i) {
395  pstrFilteredOut->replace(i->first, i->second - i->first, "(…)");
396  }
397  }
398  switch(state) // final state
399  {
400  case STATE_COMMAND_EXECUTED:
401  if (lastResult.isStr())
402  strResult = lastResult.get_str();
403  else
404  strResult = lastResult.write(2);
405  [[fallthrough]];
406  case STATE_ARGUMENT:
407  case STATE_EATING_SPACES:
408  return true;
409  default: // ERROR to end in one of the other states
410  return false;
411  }
412 }
413 
414 void RPCExecutor::request(const QString &command, const WalletModel* wallet_model)
415 {
416  try
417  {
418  std::string result;
419  std::string executableCommand = command.toStdString() + "\n";
420 
421  // Catch the console-only-help command before RPC call is executed and reply with help text as-if a RPC reply.
422  if(executableCommand == "help-console\n") {
423  Q_EMIT reply(RPCConsole::CMD_REPLY, QString(("\n"
424  "This console accepts RPC commands using the standard syntax.\n"
425  " example: getblockhash 0\n\n"
426 
427  "This console can also accept RPC commands using the parenthesized syntax.\n"
428  " example: getblockhash(0)\n\n"
429 
430  "Commands may be nested when specified with the parenthesized syntax.\n"
431  " example: getblock(getblockhash(0) 1)\n\n"
432 
433  "A space or a comma can be used to delimit arguments for either syntax.\n"
434  " example: getblockhash 0\n"
435  " getblockhash,0\n\n"
436 
437  "Named results can be queried with a non-quoted key string in brackets using the parenthesized syntax.\n"
438  " example: getblock(getblockhash(0) 1)[tx]\n\n"
439 
440  "Results without keys can be queried with an integer in brackets using the parenthesized syntax.\n"
441  " example: getblock(getblockhash(0),1)[tx][0]\n\n")));
442  return;
443  }
444  if (!RPCConsole::RPCExecuteCommandLine(m_node, result, executableCommand, nullptr, wallet_model)) {
445  Q_EMIT reply(RPCConsole::CMD_ERROR, QString("Parse error: unbalanced ' or \""));
446  return;
447  }
448 
449  Q_EMIT reply(RPCConsole::CMD_REPLY, QString::fromStdString(result));
450  }
451  catch (UniValue& objError)
452  {
453  try // Nice formatting for standard-format error
454  {
455  int code = find_value(objError, "code").get_int();
456  std::string message = find_value(objError, "message").get_str();
457  Q_EMIT reply(RPCConsole::CMD_ERROR, QString::fromStdString(message) + " (code " + QString::number(code) + ")");
458  }
459  catch (const std::runtime_error&) // raised when converting to invalid type, i.e. missing code or message
460  { // Show raw JSON object
461  Q_EMIT reply(RPCConsole::CMD_ERROR, QString::fromStdString(objError.write()));
462  }
463  }
464  catch (const std::exception& e)
465  {
466  Q_EMIT reply(RPCConsole::CMD_ERROR, QString("Error: ") + QString::fromStdString(e.what()));
467  }
468 }
469 
470 RPCConsole::RPCConsole(interfaces::Node& node, const PlatformStyle *_platformStyle, QWidget *parent) :
471  QWidget(parent),
472  m_node(node),
473  ui(new Ui::RPCConsole),
474  platformStyle(_platformStyle)
475 {
476  ui->setupUi(this);
477  QSettings settings;
478 #ifdef ENABLE_WALLET
480  // RPCConsole widget is a window.
481  if (!restoreGeometry(settings.value("RPCConsoleWindowGeometry").toByteArray())) {
482  // Restore failed (perhaps missing setting), center the window
483  move(QGuiApplication::primaryScreen()->availableGeometry().center() - frameGeometry().center());
484  }
485  ui->splitter->restoreState(settings.value("RPCConsoleWindowPeersTabSplitterSizes").toByteArray());
486  } else
487 #endif // ENABLE_WALLET
488  {
489  // RPCConsole is a child widget.
490  ui->splitter->restoreState(settings.value("RPCConsoleWidgetPeersTabSplitterSizes").toByteArray());
491  }
492 
493  m_peer_widget_header_state = settings.value("PeersTabPeerHeaderState").toByteArray();
494  m_banlist_widget_header_state = settings.value("PeersTabBanlistHeaderState").toByteArray();
495 
496  constexpr QChar nonbreaking_hyphen(8209);
497  const std::vector<QString> CONNECTION_TYPE_DOC{
498  tr("Inbound: initiated by peer"),
499  tr("Outbound Full Relay: default"),
500  tr("Outbound Block Relay: does not relay transactions or addresses"),
501  tr("Outbound Manual: added using RPC %1 or %2/%3 configuration options")
502  .arg("addnode")
503  .arg(QString(nonbreaking_hyphen) + "addnode")
504  .arg(QString(nonbreaking_hyphen) + "connect"),
505  tr("Outbound Feeler: short-lived, for testing addresses"),
506  tr("Outbound Address Fetch: short-lived, for soliciting addresses")};
507  const QString list{"<ul><li>" + Join(CONNECTION_TYPE_DOC, QString("</li><li>")) + "</li></ul>"};
508  ui->peerConnectionTypeLabel->setToolTip(ui->peerConnectionTypeLabel->toolTip().arg(list));
509  const QString hb_list{"<ul><li>\""
510  + ts.to + "\" – " + tr("we selected the peer for high bandwidth relay") + "</li><li>\""
511  + ts.from + "\" – " + tr("the peer selected us for high bandwidth relay") + "</li><li>\""
512  + ts.no + "\" – " + tr("no high bandwidth relay selected") + "</li></ul>"};
513  ui->peerHighBandwidthLabel->setToolTip(ui->peerHighBandwidthLabel->toolTip().arg(hb_list));
514  ui->dataDir->setToolTip(ui->dataDir->toolTip().arg(QString(nonbreaking_hyphen) + "datadir"));
515  ui->blocksDir->setToolTip(ui->blocksDir->toolTip().arg(QString(nonbreaking_hyphen) + "blocksdir"));
516  ui->openDebugLogfileButton->setToolTip(ui->openDebugLogfileButton->toolTip().arg(PACKAGE_NAME));
517 
519  ui->openDebugLogfileButton->setIcon(platformStyle->SingleColorIcon(":/icons/export"));
520  }
521  ui->clearButton->setIcon(platformStyle->SingleColorIcon(":/icons/remove"));
522 
523  ui->fontBiggerButton->setIcon(platformStyle->SingleColorIcon(":/icons/fontbigger"));
524  //: Main shortcut to increase the RPC console font size.
525  ui->fontBiggerButton->setShortcut(tr("Ctrl++"));
526  //: Secondary shortcut to increase the RPC console font size.
527  GUIUtil::AddButtonShortcut(ui->fontBiggerButton, tr("Ctrl+="));
528 
529  ui->fontSmallerButton->setIcon(platformStyle->SingleColorIcon(":/icons/fontsmaller"));
530  //: Main shortcut to decrease the RPC console font size.
531  ui->fontSmallerButton->setShortcut(tr("Ctrl+-"));
532  //: Secondary shortcut to decrease the RPC console font size.
533  GUIUtil::AddButtonShortcut(ui->fontSmallerButton, tr("Ctrl+_"));
534 
535  ui->promptIcon->setIcon(platformStyle->SingleColorIcon(QStringLiteral(":/icons/prompticon")));
536 
537  // Install event filter for up and down arrow
538  ui->lineEdit->installEventFilter(this);
539  ui->lineEdit->setMaxLength(16 * 1024 * 1024);
540  ui->messagesWidget->installEventFilter(this);
541 
542  connect(ui->clearButton, &QAbstractButton::clicked, [this] { clear(); });
543  connect(ui->fontBiggerButton, &QAbstractButton::clicked, this, &RPCConsole::fontBigger);
544  connect(ui->fontSmallerButton, &QAbstractButton::clicked, this, &RPCConsole::fontSmaller);
545  connect(ui->btnClearTrafficGraph, &QPushButton::clicked, ui->trafficGraph, &TrafficGraphWidget::clear);
546 
547  // disable the wallet selector by default
548  ui->WalletSelector->setVisible(false);
549  ui->WalletSelectorLabel->setVisible(false);
550 
551  // Register RPC timer interface
553  // avoid accidentally overwriting an existing, non QTThread
554  // based timer interface
556 
559 
560  consoleFontSize = settings.value(fontSizeSettingsKey, QFont().pointSize()).toInt();
561  clear();
562 
564 }
565 
567 {
568  QSettings settings;
569 #ifdef ENABLE_WALLET
571  // RPCConsole widget is a window.
572  settings.setValue("RPCConsoleWindowGeometry", saveGeometry());
573  settings.setValue("RPCConsoleWindowPeersTabSplitterSizes", ui->splitter->saveState());
574  } else
575 #endif // ENABLE_WALLET
576  {
577  // RPCConsole is a child widget.
578  settings.setValue("RPCConsoleWidgetPeersTabSplitterSizes", ui->splitter->saveState());
579  }
580 
581  settings.setValue("PeersTabPeerHeaderState", m_peer_widget_header_state);
582  settings.setValue("PeersTabBanlistHeaderState", m_banlist_widget_header_state);
583 
585  delete rpcTimerInterface;
586  delete ui;
587 }
588 
589 bool RPCConsole::eventFilter(QObject* obj, QEvent *event)
590 {
591  if(event->type() == QEvent::KeyPress) // Special key handling
592  {
593  QKeyEvent *keyevt = static_cast<QKeyEvent*>(event);
594  int key = keyevt->key();
595  Qt::KeyboardModifiers mod = keyevt->modifiers();
596  switch(key)
597  {
598  case Qt::Key_Up: if(obj == ui->lineEdit) { browseHistory(-1); return true; } break;
599  case Qt::Key_Down: if(obj == ui->lineEdit) { browseHistory(1); return true; } break;
600  case Qt::Key_PageUp: /* pass paging keys to messages widget */
601  case Qt::Key_PageDown:
602  if(obj == ui->lineEdit)
603  {
604  QApplication::postEvent(ui->messagesWidget, new QKeyEvent(*keyevt));
605  return true;
606  }
607  break;
608  case Qt::Key_Return:
609  case Qt::Key_Enter:
610  // forward these events to lineEdit
611  if(obj == autoCompleter->popup()) {
612  QApplication::postEvent(ui->lineEdit, new QKeyEvent(*keyevt));
613  autoCompleter->popup()->hide();
614  return true;
615  }
616  break;
617  default:
618  // Typing in messages widget brings focus to line edit, and redirects key there
619  // Exclude most combinations and keys that emit no text, except paste shortcuts
620  if(obj == ui->messagesWidget && (
621  (!mod && !keyevt->text().isEmpty() && key != Qt::Key_Tab) ||
622  ((mod & Qt::ControlModifier) && key == Qt::Key_V) ||
623  ((mod & Qt::ShiftModifier) && key == Qt::Key_Insert)))
624  {
625  ui->lineEdit->setFocus();
626  QApplication::postEvent(ui->lineEdit, new QKeyEvent(*keyevt));
627  return true;
628  }
629  }
630  }
631  return QWidget::eventFilter(obj, event);
632 }
633 
634 void RPCConsole::setClientModel(ClientModel *model, int bestblock_height, int64_t bestblock_date, double verification_progress)
635 {
636  clientModel = model;
637 
638  bool wallet_enabled{false};
639 #ifdef ENABLE_WALLET
640  wallet_enabled = WalletModel::isWalletEnabled();
641 #endif // ENABLE_WALLET
642  if (model && !wallet_enabled) {
643  // Show warning, for example if this is a prerelease version
644  connect(model, &ClientModel::alertsChanged, this, &RPCConsole::updateAlerts);
646  }
647 
648  ui->trafficGraph->setClientModel(model);
650  // Keep up to date with client
653 
654  setNumBlocks(bestblock_height, QDateTime::fromSecsSinceEpoch(bestblock_date), verification_progress, false);
656 
659 
661  updateTrafficStats(node.getTotalBytesRecv(), node.getTotalBytesSent());
663 
665 
666  // set up peer table
667  ui->peerWidget->setModel(model->peerTableSortProxy());
668  ui->peerWidget->verticalHeader()->hide();
669  ui->peerWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
670  ui->peerWidget->setSelectionMode(QAbstractItemView::ExtendedSelection);
671  ui->peerWidget->setContextMenuPolicy(Qt::CustomContextMenu);
672 
673  if (!ui->peerWidget->horizontalHeader()->restoreState(m_peer_widget_header_state)) {
674  ui->peerWidget->setColumnWidth(PeerTableModel::Address, ADDRESS_COLUMN_WIDTH);
675  ui->peerWidget->setColumnWidth(PeerTableModel::Subversion, SUBVERSION_COLUMN_WIDTH);
676  ui->peerWidget->setColumnWidth(PeerTableModel::Ping, PING_COLUMN_WIDTH);
677  }
678  ui->peerWidget->horizontalHeader()->setStretchLastSection(true);
679  ui->peerWidget->setItemDelegateForColumn(PeerTableModel::NetNodeId, new PeerIdViewDelegate(this));
680 
681  // create peer table context menu
682  peersTableContextMenu = new QMenu(this);
683  //: Context menu action to copy the address of a peer.
684  peersTableContextMenu->addAction(tr("&Copy address"), [this] {
685  GUIUtil::copyEntryData(ui->peerWidget, PeerTableModel::Address, Qt::DisplayRole);
686  });
687  peersTableContextMenu->addSeparator();
688  peersTableContextMenu->addAction(tr("&Disconnect"), this, &RPCConsole::disconnectSelectedNode);
689  peersTableContextMenu->addAction(ts.ban_for + " " + tr("1 &hour"), [this] { banSelectedNode(60 * 60); });
690  peersTableContextMenu->addAction(ts.ban_for + " " + tr("1 d&ay"), [this] { banSelectedNode(60 * 60 * 24); });
691  peersTableContextMenu->addAction(ts.ban_for + " " + tr("1 &week"), [this] { banSelectedNode(60 * 60 * 24 * 7); });
692  peersTableContextMenu->addAction(ts.ban_for + " " + tr("1 &year"), [this] { banSelectedNode(60 * 60 * 24 * 365); });
693  connect(ui->peerWidget, &QTableView::customContextMenuRequested, this, &RPCConsole::showPeersTableContextMenu);
694 
695  // peer table signal handling - update peer details when selecting new node
696  connect(ui->peerWidget->selectionModel(), &QItemSelectionModel::selectionChanged, this, &RPCConsole::updateDetailWidget);
697  connect(model->getPeerTableModel(), &QAbstractItemModel::dataChanged, [this] { updateDetailWidget(); });
698 
699  // set up ban table
700  ui->banlistWidget->setModel(model->getBanTableModel());
701  ui->banlistWidget->verticalHeader()->hide();
702  ui->banlistWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
703  ui->banlistWidget->setSelectionMode(QAbstractItemView::SingleSelection);
704  ui->banlistWidget->setContextMenuPolicy(Qt::CustomContextMenu);
705 
706  if (!ui->banlistWidget->horizontalHeader()->restoreState(m_banlist_widget_header_state)) {
707  ui->banlistWidget->setColumnWidth(BanTableModel::Address, BANSUBNET_COLUMN_WIDTH);
708  ui->banlistWidget->setColumnWidth(BanTableModel::Bantime, BANTIME_COLUMN_WIDTH);
709  }
710  ui->banlistWidget->horizontalHeader()->setStretchLastSection(true);
711 
712  // create ban table context menu
713  banTableContextMenu = new QMenu(this);
714  /*: Context menu action to copy the IP/Netmask of a banned peer.
715  IP/Netmask is the combination of a peer's IP address and its Netmask.
716  For IP address, see: https://en.wikipedia.org/wiki/IP_address. */
717  banTableContextMenu->addAction(tr("&Copy IP/Netmask"), [this] {
718  GUIUtil::copyEntryData(ui->banlistWidget, BanTableModel::Address, Qt::DisplayRole);
719  });
720  banTableContextMenu->addSeparator();
721  banTableContextMenu->addAction(tr("&Unban"), this, &RPCConsole::unbanSelectedNode);
722  connect(ui->banlistWidget, &QTableView::customContextMenuRequested, this, &RPCConsole::showBanTableContextMenu);
723 
724  // ban table signal handling - clear peer details when clicking a peer in the ban table
725  connect(ui->banlistWidget, &QTableView::clicked, this, &RPCConsole::clearSelectedNode);
726  // ban table signal handling - ensure ban table is shown or hidden (if empty)
727  connect(model->getBanTableModel(), &BanTableModel::layoutChanged, this, &RPCConsole::showOrHideBanTableIfRequired);
729 
730  // Provide initial values
731  ui->clientVersion->setText(model->formatFullVersion());
732  ui->clientUserAgent->setText(model->formatSubVersion());
733  ui->dataDir->setText(model->dataDir());
734  ui->blocksDir->setText(model->blocksDir());
735  ui->startupTime->setText(model->formatClientStartupTime());
736  ui->networkName->setText(QString::fromStdString(Params().NetworkIDString()));
737 
738  //Setup autocomplete and attach it
739  QStringList wordList;
740  std::vector<std::string> commandList = m_node.listRpcCommands();
741  for (size_t i = 0; i < commandList.size(); ++i)
742  {
743  wordList << commandList[i].c_str();
744  wordList << ("help " + commandList[i]).c_str();
745  }
746 
747  wordList << "help-console";
748  wordList.sort();
749  autoCompleter = new QCompleter(wordList, this);
750  autoCompleter->setModelSorting(QCompleter::CaseSensitivelySortedModel);
751  // ui->lineEdit is initially disabled because running commands is only
752  // possible from now on.
753  ui->lineEdit->setEnabled(true);
754  ui->lineEdit->setCompleter(autoCompleter);
755  autoCompleter->popup()->installEventFilter(this);
756  // Start thread to execute RPC commands.
757  startExecutor();
758  }
759  if (!model) {
760  // Client model is being set to 0, this means shutdown() is about to be called.
761  thread.quit();
762  thread.wait();
763  }
764 }
765 
766 #ifdef ENABLE_WALLET
767 void RPCConsole::addWallet(WalletModel * const walletModel)
768 {
769  // use name for text and wallet model for internal data object (to allow to move to a wallet id later)
770  ui->WalletSelector->addItem(walletModel->getDisplayName(), QVariant::fromValue(walletModel));
771  if (ui->WalletSelector->count() == 2 && !isVisible()) {
772  // First wallet added, set to default so long as the window isn't presently visible (and potentially in use)
773  ui->WalletSelector->setCurrentIndex(1);
774  }
775  if (ui->WalletSelector->count() > 2) {
776  ui->WalletSelector->setVisible(true);
777  ui->WalletSelectorLabel->setVisible(true);
778  }
779 }
780 
781 void RPCConsole::removeWallet(WalletModel * const walletModel)
782 {
783  ui->WalletSelector->removeItem(ui->WalletSelector->findData(QVariant::fromValue(walletModel)));
784  if (ui->WalletSelector->count() == 2) {
785  ui->WalletSelector->setVisible(false);
786  ui->WalletSelectorLabel->setVisible(false);
787  }
788 }
789 #endif
790 
791 static QString categoryClass(int category)
792 {
793  switch(category)
794  {
795  case RPCConsole::CMD_REQUEST: return "cmd-request"; break;
796  case RPCConsole::CMD_REPLY: return "cmd-reply"; break;
797  case RPCConsole::CMD_ERROR: return "cmd-error"; break;
798  default: return "misc";
799  }
800 }
801 
803 {
805 }
806 
808 {
810 }
811 
812 void RPCConsole::setFontSize(int newSize)
813 {
814  QSettings settings;
815 
816  //don't allow an insane font size
817  if (newSize < FONT_RANGE.width() || newSize > FONT_RANGE.height())
818  return;
819 
820  // temp. store the console content
821  QString str = ui->messagesWidget->toHtml();
822 
823  // replace font tags size in current content
824  str.replace(QString("font-size:%1pt").arg(consoleFontSize), QString("font-size:%1pt").arg(newSize));
825 
826  // store the new font size
827  consoleFontSize = newSize;
828  settings.setValue(fontSizeSettingsKey, consoleFontSize);
829 
830  // clear console (reset icon sizes, default stylesheet) and re-add the content
831  float oldPosFactor = 1.0 / ui->messagesWidget->verticalScrollBar()->maximum() * ui->messagesWidget->verticalScrollBar()->value();
832  clear(/* keep_prompt */ true);
833  ui->messagesWidget->setHtml(str);
834  ui->messagesWidget->verticalScrollBar()->setValue(oldPosFactor * ui->messagesWidget->verticalScrollBar()->maximum());
835 }
836 
837 void RPCConsole::clear(bool keep_prompt)
838 {
839  ui->messagesWidget->clear();
840  if (!keep_prompt) ui->lineEdit->clear();
841  ui->lineEdit->setFocus();
842 
843  // Add smoothly scaled icon images.
844  // (when using width/height on an img, Qt uses nearest instead of linear interpolation)
845  for(int i=0; ICON_MAPPING[i].url; ++i)
846  {
847  ui->messagesWidget->document()->addResource(
848  QTextDocument::ImageResource,
849  QUrl(ICON_MAPPING[i].url),
850  platformStyle->SingleColorImage(ICON_MAPPING[i].source).scaled(QSize(consoleFontSize*2, consoleFontSize*2), Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
851  }
852 
853  // Set default style sheet
854  QFontInfo fixedFontInfo(GUIUtil::fixedPitchFont());
855  ui->messagesWidget->document()->setDefaultStyleSheet(
856  QString(
857  "table { }"
858  "td.time { color: #808080; font-size: %2; padding-top: 3px; } "
859  "td.message { font-family: %1; font-size: %2; white-space:pre-wrap; } "
860  "td.cmd-request { color: #006060; } "
861  "td.cmd-error { color: red; } "
862  ".secwarning { color: red; }"
863  "b { color: #006060; } "
864  ).arg(fixedFontInfo.family(), QString("%1pt").arg(consoleFontSize))
865  );
866 
867  static const QString welcome_message =
868  /*: RPC console welcome message.
869  Placeholders %7 and %8 are style tags for the warning content, and
870  they are not space separated from the rest of the text intentionally. */
871  tr("Welcome to the %1 RPC console.\n"
872  "Use up and down arrows to navigate history, and %2 to clear screen.\n"
873  "Use %3 and %4 to increase or decrease the font size.\n"
874  "Type %5 for an overview of available commands.\n"
875  "For more information on using this console, type %6.\n"
876  "\n"
877  "%7WARNING: Scammers have been active, telling users to type"
878  " commands here, stealing their wallet contents. Do not use this console"
879  " without fully understanding the ramifications of a command.%8")
880  .arg(PACKAGE_NAME,
881  "<b>" + ui->clearButton->shortcut().toString(QKeySequence::NativeText) + "</b>",
882  "<b>" + ui->fontBiggerButton->shortcut().toString(QKeySequence::NativeText) + "</b>",
883  "<b>" + ui->fontSmallerButton->shortcut().toString(QKeySequence::NativeText) + "</b>",
884  "<b>help</b>",
885  "<b>help-console</b>",
886  "<span class=\"secwarning\">",
887  "<span>");
888 
889  message(CMD_REPLY, welcome_message, true);
890 }
891 
892 void RPCConsole::keyPressEvent(QKeyEvent *event)
893 {
894  if(windowType() != Qt::Widget && event->key() == Qt::Key_Escape)
895  {
896  close();
897  }
898 }
899 
900 void RPCConsole::changeEvent(QEvent* e)
901 {
902  if (e->type() == QEvent::PaletteChange) {
903  ui->clearButton->setIcon(platformStyle->SingleColorIcon(QStringLiteral(":/icons/remove")));
904  ui->fontBiggerButton->setIcon(platformStyle->SingleColorIcon(QStringLiteral(":/icons/fontbigger")));
905  ui->fontSmallerButton->setIcon(platformStyle->SingleColorIcon(QStringLiteral(":/icons/fontsmaller")));
906  ui->promptIcon->setIcon(platformStyle->SingleColorIcon(QStringLiteral(":/icons/prompticon")));
907 
908  for (int i = 0; ICON_MAPPING[i].url; ++i) {
909  ui->messagesWidget->document()->addResource(
910  QTextDocument::ImageResource,
911  QUrl(ICON_MAPPING[i].url),
912  platformStyle->SingleColorImage(ICON_MAPPING[i].source).scaled(QSize(consoleFontSize * 2, consoleFontSize * 2), Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
913  }
914  }
915 
916  QWidget::changeEvent(e);
917 }
918 
919 void RPCConsole::message(int category, const QString &message, bool html)
920 {
921  QTime time = QTime::currentTime();
922  QString timeString = time.toString();
923  QString out;
924  out += "<table><tr><td class=\"time\" width=\"65\">" + timeString + "</td>";
925  out += "<td class=\"icon\" width=\"32\"><img src=\"" + categoryClass(category) + "\"></td>";
926  out += "<td class=\"message " + categoryClass(category) + "\" valign=\"middle\">";
927  if(html)
928  out += message;
929  else
930  out += GUIUtil::HtmlEscape(message, false);
931  out += "</td></tr></table>";
932  ui->messagesWidget->append(out);
933 }
934 
936 {
937  QString connections = QString::number(clientModel->getNumConnections()) + " (";
938  connections += tr("In:") + " " + QString::number(clientModel->getNumConnections(CONNECTIONS_IN)) + " / ";
939  connections += tr("Out:") + " " + QString::number(clientModel->getNumConnections(CONNECTIONS_OUT)) + ")";
940 
941  if(!clientModel->node().getNetworkActive()) {
942  connections += " (" + tr("Network activity disabled") + ")";
943  }
944 
945  ui->numberOfConnections->setText(connections);
946 }
947 
949 {
950  if (!clientModel)
951  return;
952 
954 }
955 
956 void RPCConsole::setNetworkActive(bool networkActive)
957 {
959 }
960 
961 void RPCConsole::setNumBlocks(int count, const QDateTime& blockDate, double nVerificationProgress, bool headers)
962 {
963  if (!headers) {
964  ui->numberOfBlocks->setText(QString::number(count));
965  ui->lastBlockTime->setText(blockDate.toString());
966  }
967 }
968 
969 void RPCConsole::setMempoolSize(long numberOfTxs, size_t dynUsage)
970 {
971  ui->mempoolNumberTxs->setText(QString::number(numberOfTxs));
972 
973  if (dynUsage < 1000000)
974  ui->mempoolSize->setText(QString::number(dynUsage/1000.0, 'f', 2) + " KB");
975  else
976  ui->mempoolSize->setText(QString::number(dynUsage/1000000.0, 'f', 2) + " MB");
977 }
978 
980 {
981  QString cmd = ui->lineEdit->text().trimmed();
982 
983  if (cmd.isEmpty()) {
984  return;
985  }
986 
987  std::string strFilteredCmd;
988  try {
989  std::string dummy;
990  if (!RPCParseCommandLine(nullptr, dummy, cmd.toStdString(), false, &strFilteredCmd)) {
991  // Failed to parse command, so we cannot even filter it for the history
992  throw std::runtime_error("Invalid command line");
993  }
994  } catch (const std::exception& e) {
995  QMessageBox::critical(this, "Error", QString("Error: ") + QString::fromStdString(e.what()));
996  return;
997  }
998 
999  // A special case allows to request shutdown even a long-running command is executed.
1000  if (cmd == QLatin1String("stop")) {
1001  std::string dummy;
1002  RPCExecuteCommandLine(m_node, dummy, cmd.toStdString());
1003  return;
1004  }
1005 
1006  if (m_is_executing) {
1007  return;
1008  }
1009 
1010  ui->lineEdit->clear();
1011 
1012 #ifdef ENABLE_WALLET
1013  WalletModel* wallet_model = ui->WalletSelector->currentData().value<WalletModel*>();
1014 
1015  if (m_last_wallet_model != wallet_model) {
1016  if (wallet_model) {
1017  message(CMD_REQUEST, tr("Executing command using \"%1\" wallet").arg(wallet_model->getWalletName()));
1018  } else {
1019  message(CMD_REQUEST, tr("Executing command without any wallet"));
1020  }
1021  m_last_wallet_model = wallet_model;
1022  }
1023 #endif // ENABLE_WALLET
1024 
1025  message(CMD_REQUEST, QString::fromStdString(strFilteredCmd));
1026  //: A console message indicating an entered command is currently being executed.
1027  message(CMD_REPLY, tr("Executing…"));
1028  m_is_executing = true;
1029  Q_EMIT cmdRequest(cmd, m_last_wallet_model);
1030 
1031  cmd = QString::fromStdString(strFilteredCmd);
1032 
1033  // Remove command, if already in history
1034  history.removeOne(cmd);
1035  // Append command to history
1036  history.append(cmd);
1037  // Enforce maximum history size
1038  while (history.size() > CONSOLE_HISTORY) {
1039  history.removeFirst();
1040  }
1041  // Set pointer to end of history
1042  historyPtr = history.size();
1043 
1044  // Scroll console view to end
1045  scrollToEnd();
1046 }
1047 
1049 {
1050  // store current text when start browsing through the history
1051  if (historyPtr == history.size()) {
1052  cmdBeforeBrowsing = ui->lineEdit->text();
1053  }
1054 
1055  historyPtr += offset;
1056  if(historyPtr < 0)
1057  historyPtr = 0;
1058  if(historyPtr > history.size())
1059  historyPtr = history.size();
1060  QString cmd;
1061  if(historyPtr < history.size())
1062  cmd = history.at(historyPtr);
1063  else if (!cmdBeforeBrowsing.isNull()) {
1064  cmd = cmdBeforeBrowsing;
1065  }
1066  ui->lineEdit->setText(cmd);
1067 }
1068 
1070 {
1071  RPCExecutor *executor = new RPCExecutor(m_node);
1072  executor->moveToThread(&thread);
1073 
1074  // Replies from executor object must go to this object
1075  connect(executor, &RPCExecutor::reply, this, [this](int category, const QString& command) {
1076  // Remove "Executing…" message.
1077  ui->messagesWidget->undo();
1078  message(category, command);
1079  scrollToEnd();
1080  m_is_executing = false;
1081  });
1082 
1083  // Requests from this object must go to executor
1084  connect(this, &RPCConsole::cmdRequest, executor, &RPCExecutor::request);
1085 
1086  // Make sure executor object is deleted in its own thread
1087  connect(&thread, &QThread::finished, executor, &RPCExecutor::deleteLater);
1088 
1089  // Default implementation of QThread::run() simply spins up an event loop in the thread,
1090  // which is what we want.
1091  thread.start();
1092  QTimer::singleShot(0, executor, []() {
1093  util::ThreadRename("qt-rpcconsole");
1094  });
1095 }
1096 
1098 {
1099  if (ui->tabWidget->widget(index) == ui->tab_console) {
1100  ui->lineEdit->setFocus();
1101  }
1102 }
1103 
1105 {
1107 }
1108 
1110 {
1111  QScrollBar *scrollbar = ui->messagesWidget->verticalScrollBar();
1112  scrollbar->setValue(scrollbar->maximum());
1113 }
1114 
1116 {
1117  const int multiplier = 5; // each position on the slider represents 5 min
1118  int mins = value * multiplier;
1119  setTrafficGraphRange(mins);
1120 }
1121 
1123 {
1124  ui->trafficGraph->setGraphRangeMins(mins);
1125  ui->lblGraphRange->setText(GUIUtil::formatDurationStr(mins * 60));
1126 }
1127 
1128 void RPCConsole::updateTrafficStats(quint64 totalBytesIn, quint64 totalBytesOut)
1129 {
1130  ui->lblBytesIn->setText(GUIUtil::formatBytes(totalBytesIn));
1131  ui->lblBytesOut->setText(GUIUtil::formatBytes(totalBytesOut));
1132 }
1133 
1135 {
1136  const QList<QModelIndex> selected_peers = GUIUtil::getEntryData(ui->peerWidget, PeerTableModel::NetNodeId);
1137  if (!clientModel || !clientModel->getPeerTableModel() || selected_peers.size() != 1) {
1138  ui->peersTabRightPanel->hide();
1139  ui->peerHeading->setText(tr("Select a peer to view detailed information."));
1140  return;
1141  }
1142  const auto stats = selected_peers.first().data(PeerTableModel::StatsRole).value<CNodeCombinedStats*>();
1143  // update the detail ui with latest node information
1144  QString peerAddrDetails(QString::fromStdString(stats->nodeStats.m_addr_name) + " ");
1145  peerAddrDetails += tr("(peer: %1)").arg(QString::number(stats->nodeStats.nodeid));
1146  if (!stats->nodeStats.addrLocal.empty())
1147  peerAddrDetails += "<br />" + tr("via %1").arg(QString::fromStdString(stats->nodeStats.addrLocal));
1148  ui->peerHeading->setText(peerAddrDetails);
1149  ui->peerServices->setText(GUIUtil::formatServicesStr(stats->nodeStats.nServices));
1150  ui->peerRelayTxes->setText(stats->nodeStats.fRelayTxes ? ts.yes : ts.no);
1151  QString bip152_hb_settings;
1152  if (stats->nodeStats.m_bip152_highbandwidth_to) bip152_hb_settings = ts.to;
1153  if (stats->nodeStats.m_bip152_highbandwidth_from) bip152_hb_settings += (bip152_hb_settings.isEmpty() ? ts.from : QLatin1Char('/') + ts.from);
1154  if (bip152_hb_settings.isEmpty()) bip152_hb_settings = ts.no;
1155  ui->peerHighBandwidth->setText(bip152_hb_settings);
1156  const int64_t time_now{GetTimeSeconds()};
1157  ui->peerConnTime->setText(GUIUtil::formatDurationStr(time_now - stats->nodeStats.nTimeConnected));
1158  ui->peerLastBlock->setText(TimeDurationField(time_now, stats->nodeStats.nLastBlockTime));
1159  ui->peerLastTx->setText(TimeDurationField(time_now, stats->nodeStats.nLastTXTime));
1160  ui->peerLastSend->setText(TimeDurationField(time_now, stats->nodeStats.nLastSend));
1161  ui->peerLastRecv->setText(TimeDurationField(time_now, stats->nodeStats.nLastRecv));
1162  ui->peerBytesSent->setText(GUIUtil::formatBytes(stats->nodeStats.nSendBytes));
1163  ui->peerBytesRecv->setText(GUIUtil::formatBytes(stats->nodeStats.nRecvBytes));
1164  ui->peerPingTime->setText(GUIUtil::formatPingTime(stats->nodeStats.m_last_ping_time));
1165  ui->peerMinPing->setText(GUIUtil::formatPingTime(stats->nodeStats.m_min_ping_time));
1166  ui->timeoffset->setText(GUIUtil::formatTimeOffset(stats->nodeStats.nTimeOffset));
1167  ui->peerVersion->setText(QString::number(stats->nodeStats.nVersion));
1168  ui->peerSubversion->setText(QString::fromStdString(stats->nodeStats.cleanSubVer));
1169  ui->peerConnectionType->setText(GUIUtil::ConnectionTypeToQString(stats->nodeStats.m_conn_type, /* prepend_direction */ true));
1170  ui->peerNetwork->setText(GUIUtil::NetworkToQString(stats->nodeStats.m_network));
1171  if (stats->nodeStats.m_permissionFlags == NetPermissionFlags::None) {
1172  ui->peerPermissions->setText(ts.na);
1173  } else {
1174  QStringList permissions;
1175  for (const auto& permission : NetPermissions::ToStrings(stats->nodeStats.m_permissionFlags)) {
1176  permissions.append(QString::fromStdString(permission));
1177  }
1178  ui->peerPermissions->setText(permissions.join(" & "));
1179  }
1180  ui->peerMappedAS->setText(stats->nodeStats.m_mapped_as != 0 ? QString::number(stats->nodeStats.m_mapped_as) : ts.na);
1181 
1182  // This check fails for example if the lock was busy and
1183  // nodeStateStats couldn't be fetched.
1184  if (stats->fNodeStateStatsAvailable) {
1185  // Sync height is init to -1
1186  if (stats->nodeStateStats.nSyncHeight > -1) {
1187  ui->peerSyncHeight->setText(QString("%1").arg(stats->nodeStateStats.nSyncHeight));
1188  } else {
1189  ui->peerSyncHeight->setText(ts.unknown);
1190  }
1191  // Common height is init to -1
1192  if (stats->nodeStateStats.nCommonHeight > -1) {
1193  ui->peerCommonHeight->setText(QString("%1").arg(stats->nodeStateStats.nCommonHeight));
1194  } else {
1195  ui->peerCommonHeight->setText(ts.unknown);
1196  }
1197  ui->peerHeight->setText(QString::number(stats->nodeStateStats.m_starting_height));
1198  ui->peerPingWait->setText(GUIUtil::formatPingTime(stats->nodeStateStats.m_ping_wait));
1199  }
1200 
1201  ui->peersTabRightPanel->show();
1202 }
1203 
1204 void RPCConsole::resizeEvent(QResizeEvent *event)
1205 {
1206  QWidget::resizeEvent(event);
1207 }
1208 
1209 void RPCConsole::showEvent(QShowEvent *event)
1210 {
1211  QWidget::showEvent(event);
1212 
1214  return;
1215 
1216  // start PeerTableModel auto refresh
1218 }
1219 
1220 void RPCConsole::hideEvent(QHideEvent *event)
1221 {
1222  // It is too late to call QHeaderView::saveState() in ~RPCConsole(), as all of
1223  // the columns of QTableView child widgets will have zero width at that moment.
1224  m_peer_widget_header_state = ui->peerWidget->horizontalHeader()->saveState();
1225  m_banlist_widget_header_state = ui->banlistWidget->horizontalHeader()->saveState();
1226 
1227  QWidget::hideEvent(event);
1228 
1230  return;
1231 
1232  // stop PeerTableModel auto refresh
1234 }
1235 
1236 void RPCConsole::showPeersTableContextMenu(const QPoint& point)
1237 {
1238  QModelIndex index = ui->peerWidget->indexAt(point);
1239  if (index.isValid())
1240  peersTableContextMenu->exec(QCursor::pos());
1241 }
1242 
1243 void RPCConsole::showBanTableContextMenu(const QPoint& point)
1244 {
1245  QModelIndex index = ui->banlistWidget->indexAt(point);
1246  if (index.isValid())
1247  banTableContextMenu->exec(QCursor::pos());
1248 }
1249 
1251 {
1252  // Get selected peer addresses
1253  QList<QModelIndex> nodes = GUIUtil::getEntryData(ui->peerWidget, PeerTableModel::NetNodeId);
1254  for(int i = 0; i < nodes.count(); i++)
1255  {
1256  // Get currently selected peer address
1257  NodeId id = nodes.at(i).data().toLongLong();
1258  // Find the node, disconnect it and clear the selected node
1259  if(m_node.disconnectById(id))
1261  }
1262 }
1263 
1265 {
1266  if (!clientModel)
1267  return;
1268 
1269  for (const QModelIndex& peer : GUIUtil::getEntryData(ui->peerWidget, PeerTableModel::NetNodeId)) {
1270  // Find possible nodes, ban it and clear the selected node
1271  const auto stats = peer.data(PeerTableModel::StatsRole).value<CNodeCombinedStats*>();
1272  if (stats) {
1273  m_node.ban(stats->nodeStats.addr, bantime);
1274  m_node.disconnectByAddress(stats->nodeStats.addr);
1275  }
1276  }
1279 }
1280 
1282 {
1283  if (!clientModel)
1284  return;
1285 
1286  // Get selected ban addresses
1287  QList<QModelIndex> nodes = GUIUtil::getEntryData(ui->banlistWidget, BanTableModel::Address);
1288  for(int i = 0; i < nodes.count(); i++)
1289  {
1290  // Get currently selected ban address
1291  QString strNode = nodes.at(i).data().toString();
1292  CSubNet possibleSubnet;
1293 
1294  LookupSubNet(strNode.toStdString(), possibleSubnet);
1295  if (possibleSubnet.IsValid() && m_node.unban(possibleSubnet))
1296  {
1298  }
1299  }
1300 }
1301 
1303 {
1304  ui->peerWidget->selectionModel()->clearSelection();
1305  cachedNodeids.clear();
1307 }
1308 
1310 {
1311  if (!clientModel)
1312  return;
1313 
1314  bool visible = clientModel->getBanTableModel()->shouldShow();
1315  ui->banlistWidget->setVisible(visible);
1316  ui->banHeading->setVisible(visible);
1317 }
1318 
1320 {
1321  ui->tabWidget->setCurrentIndex(int(tabType));
1322 }
1323 
1324 QString RPCConsole::tabTitle(TabTypes tab_type) const
1325 {
1326  return ui->tabWidget->tabText(int(tab_type));
1327 }
1328 
1329 QKeySequence RPCConsole::tabShortcut(TabTypes tab_type) const
1330 {
1331  switch (tab_type) {
1332  case TabTypes::INFO: return QKeySequence(Qt::CTRL + Qt::Key_I);
1333  case TabTypes::CONSOLE: return QKeySequence(Qt::CTRL + Qt::Key_T);
1334  case TabTypes::GRAPH: return QKeySequence(Qt::CTRL + Qt::Key_N);
1335  case TabTypes::PEERS: return QKeySequence(Qt::CTRL + Qt::Key_P);
1336  } // no default case, so the compiler can warn about missing cases
1337 
1338  assert(false);
1339 }
1340 
1341 void RPCConsole::updateAlerts(const QString& warnings)
1342 {
1343  this->ui->label_alerts->setVisible(!warnings.isEmpty());
1344  this->ui->label_alerts->setText(warnings);
1345 }
interfaces::Node::ban
virtual bool ban(const CNetAddr &net_addr, int64_t ban_time_offset)=0
Ban node.
RPCConsole::TabTypes::CONSOLE
@ CONSOLE
ClientModel::alertsChanged
void alertsChanged(const QString &warnings)
RPCExecutor::RPCExecutor
RPCExecutor(interfaces::Node &node)
Definition: rpcconsole.cpp:93
NodeId
int64_t NodeId
Definition: net.h:87
ClientModel::numBlocksChanged
void numBlocksChanged(int count, const QDateTime &blockDate, double nVerificationProgress, bool header, SynchronizationState sync_state)
PeerIdViewDelegate::displayText
QString displayText(const QVariant &value, const QLocale &locale) const override
Definition: rpcconsole.cpp:143
RPCConsole::TranslatedStrings::yes
const QString yes
Definition: rpcconsole.h:138
CONNECTIONS_IN
@ CONNECTIONS_IN
Definition: clientmodel.h:41
RPCConsole::setNumConnections
void setNumConnections(int count)
Set number of connections shown in the UI.
Definition: rpcconsole.cpp:948
count
static int count
Definition: tests.c:41
assert
assert(!tx.IsCoinBase())
ClientModel::numConnectionsChanged
void numConnectionsChanged(int count)
RPCConsole::ADDRESS_COLUMN_WIDTH
@ ADDRESS_COLUMN_WIDTH
Definition: rpcconsole.h:147
CONNECTIONS_OUT
@ CONNECTIONS_OUT
Definition: clientmodel.h:42
RPCConsole::TranslatedStrings::from
const QString from
Definition: rpcconsole.h:138
NetPermissionFlags::None
@ None
fontSizeSettingsKey
const char fontSizeSettingsKey[]
Definition: rpcconsole.cpp:59
ClientModel::mempoolSizeChanged
void mempoolSizeChanged(long count, size_t mempoolSizeInBytes)
PeerTableModel::NetNodeId
@ NetNodeId
Definition: peertablemodel.h:49
wallet.h
LookupSubNet
bool LookupSubNet(const std::string &strSubnet, CSubNet &ret, DNSLookupFn dns_lookup_function)
Parse and resolve a specified subnet string into the appropriate internal representation.
Definition: netbase.cpp:676
NetPermissions::ToStrings
static std::vector< std::string > ToStrings(NetPermissionFlags flags)
Definition: net_permissions.cpp:71
interfaces::Node::getNetworkActive
virtual bool getNetworkActive()=0
Get network active.
WalletModel
Interface to Bitcoin wallet from Qt view code.
Definition: walletmodel.h:51
QtRPCTimerBase
Class for handling RPC timers (used for e.g.
Definition: rpcconsole.cpp:108
RPCConsole::TimeDurationField
QString TimeDurationField(uint64_t time_now, uint64_t time_at_event) const
Helper for the output of a time duration field.
Definition: rpcconsole.h:178
ClientModel::getNumConnections
int getNumConnections(unsigned int flags=CONNECTIONS_ALL) const
Return number of connections, default is in- and outbound (total)
Definition: clientmodel.cpp:77
RPCConsole::startExecutor
void startExecutor()
Definition: rpcconsole.cpp:1069
RPCTimerInterface
RPC timer "driver".
Definition: server.h:60
PlatformStyle::SingleColorIcon
QIcon SingleColorIcon(const QString &filename) const
Colorize an icon (given filename) with the icon color.
Definition: platformstyle.cpp:105
interfaces::Node::disconnectById
virtual bool disconnectById(NodeId id)=0
Disconnect node by id.
RPCConsole::m_peer_widget_header_state
QByteArray m_peer_widget_header_state
Definition: rpcconsole.h:171
walletmodel.h
RPCConsole::resizeEvent
void resizeEvent(QResizeEvent *event) override
Definition: rpcconsole.cpp:1204
RPCConsole::clearSelectedNode
void clearSelectedNode()
clear the selected node
Definition: rpcconsole.cpp:1302
INITIAL_TRAFFIC_GRAPH_MINS
const int INITIAL_TRAFFIC_GRAPH_MINS
Definition: rpcconsole.cpp:57
string.h
RPCConsole::TranslatedStrings::ban_for
const QString ban_for
Definition: rpcconsole.h:139
atoi
int atoi(const std::string &str)
Definition: strencodings.cpp:449
source
const char * source
Definition: rpcconsole.cpp:63
WalletModel::isWalletEnabled
static bool isWalletEnabled()
Definition: walletmodel.cpp:567
RPCConsole::keyPressEvent
void keyPressEvent(QKeyEvent *) override
Definition: rpcconsole.cpp:892
RPCConsole::platformStyle
const PlatformStyle *const platformStyle
Definition: rpcconsole.h:162
ClientModel::node
interfaces::Node & node() const
Definition: clientmodel.h:55
m_node
NodeContext & m_node
Definition: bitcoin-node.cpp:38
RPCExecutor::m_node
interfaces::Node & m_node
Definition: rpcconsole.cpp:102
RPCConsole::updateNetworkState
void updateNetworkState()
Update UI with latest network info from model.
Definition: rpcconsole.cpp:935
ClientModel::peerTableSortProxy
PeerTableSortProxy * peerTableSortProxy()
Definition: clientmodel.cpp:192
RPCConsole::CMD_REQUEST
@ CMD_REQUEST
Definition: rpcconsole.h:58
PeerTableModel::Subversion
@ Subversion
Definition: peertablemodel.h:57
ClientModel::blocksDir
QString blocksDir() const
Definition: clientmodel.cpp:227
RPCTimerBase
Opaque base class for timers returned by NewTimerFunc.
Definition: server.h:51
GUIUtil::openDebugLogfile
void openDebugLogfile()
Definition: guiutil.cpp:407
peertablesortproxy.h
RPCConsole::showOrHideBanTableIfRequired
void showOrHideBanTableIfRequired()
Hides ban table if no bans are present.
Definition: rpcconsole.cpp:1309
PeerIdViewDelegate
Definition: rpcconsole.cpp:136
RPCConsole::autoCompleter
QCompleter * autoCompleter
Definition: rpcconsole.h:167
PeerIdViewDelegate::PeerIdViewDelegate
PeerIdViewDelegate(QObject *parent=nullptr)
Definition: rpcconsole.cpp:140
RPCConsole::CMD_ERROR
@ CMD_ERROR
Definition: rpcconsole.h:60
categoryClass
static QString categoryClass(int category)
Definition: rpcconsole.cpp:791
interfaces::Node::disconnectByAddress
virtual bool disconnectByAddress(const CNetAddr &net_addr)=0
Disconnect node by address.
RPCConsole::setTrafficGraphRange
void setTrafficGraphRange(int mins)
Definition: rpcconsole.cpp:1122
RPCConsole::RPCParseCommandLine
static bool RPCParseCommandLine(interfaces::Node *node, std::string &strResult, const std::string &strCommand, bool fExecute, std::string *const pstrFilteredOut=nullptr, const WalletModel *wallet_model=nullptr)
Split shell command line into a list of arguments and optionally execute the command(s).
Definition: rpcconsole.cpp:173
RPCConvertValues
UniValue RPCConvertValues(const std::string &strMethod, const std::vector< std::string > &strParams)
Convert positional arguments to command-specific RPC representation.
Definition: client.cpp:240
bitcoin-config.h
bdb.h
chainparams.h
UniValue::write
std::string write(unsigned int prettyIndent=0, unsigned int indentLevel=0) const
Definition: univalue_write.cpp:29
RPCConsole::ui
Ui::RPCConsole *const ui
Definition: rpcconsole.h:156
ClientModel::getStatusBarWarnings
QString getStatusBarWarnings() const
Return warnings to be displayed in status bar.
Definition: clientmodel.cpp:177
RPCConsole::fontSmaller
void fontSmaller()
Definition: rpcconsole.cpp:807
PeerTableModel::Address
@ Address
Definition: peertablemodel.h:50
db.h
BanTableModel::Bantime
@ Bantime
Definition: bantablemodel.h:55
RPCConsole::m_is_executing
bool m_is_executing
Definition: rpcconsole.h:170
QtRPCTimerBase::timer
QTimer timer
Definition: rpcconsole.cpp:121
UniValue
Definition: univalue.h:19
QtRPCTimerInterface::NewTimer
RPCTimerBase * NewTimer(std::function< void()> &func, int64_t millis) override
Factory function for timers.
Definition: rpcconsole.cpp:130
RPCConsole::setMempoolSize
void setMempoolSize(long numberOfTxs, size_t dynUsage)
Set size (number of transactions and memory usage) of the mempool in the UI.
Definition: rpcconsole.cpp:969
rpcconsole.h
RPCConsole::tabShortcut
QKeySequence tabShortcut(TabTypes tab_type) const
Definition: rpcconsole.cpp:1329
RPCConsole::cachedNodeids
QList< NodeId > cachedNodeids
Definition: rpcconsole.h:161
RPCConsole::addWallet
void addWallet(WalletModel *const walletModel)
UniValue::get_str
const std::string & get_str() const
Definition: univalue_get.cpp:97
RPCConsole::updateTrafficStats
void updateTrafficStats(quint64 totalBytesIn, quint64 totalBytesOut)
update traffic statistics
Definition: rpcconsole.cpp:1128
url
const char * url
Definition: rpcconsole.cpp:62
strencodings.h
UniValue::isStr
bool isStr() const
Definition: univalue.h:81
CONNECTION_TYPE_DOC
const std::vector< std::string > CONNECTION_TYPE_DOC
Definition: net.cpp:35
GUIUtil::ConnectionTypeToQString
QString ConnectionTypeToQString(ConnectionType conn_type, bool prepend_direction)
Convert enum ConnectionType to QString.
Definition: guiutil.cpp:672
GUIUtil::formatTimeOffset
QString formatTimeOffset(int64_t nTimeOffset)
Format a CNodeCombinedStats.nTimeOffset into a user-readable string.
Definition: guiutil.cpp:730
RPCConsole::consoleFontSize
int consoleFontSize
Definition: rpcconsole.h:166
RPCConsole::updateAlerts
void updateAlerts(const QString &warnings)
Definition: rpcconsole.cpp:1341
RPCConsole::setNetworkActive
void setNetworkActive(bool networkActive)
Set network state shown in the UI.
Definition: rpcconsole.cpp:956
RPCConsole::scrollToEnd
void scrollToEnd()
Scroll console view to end.
Definition: rpcconsole.cpp:1109
ClientModel::getPeerTableModel
PeerTableModel * getPeerTableModel()
Definition: clientmodel.cpp:187
RPCConsole::removeWallet
void removeWallet(WalletModel *const walletModel)
RPCConsole::showPeersTableContextMenu
void showPeersTableContextMenu(const QPoint &point)
Show custom context menu on Peers tab.
Definition: rpcconsole.cpp:1236
RPCConsole::setFontSize
void setFontSize(int newSize)
Definition: rpcconsole.cpp:812
PlatformStyle::SingleColorImage
QImage SingleColorImage(const QString &filename) const
Colorize an image (given filename) with the icon color.
Definition: platformstyle.cpp:98
RPCConsole::RPCConsole
RPCConsole(interfaces::Node &node, const PlatformStyle *platformStyle, QWidget *parent)
Definition: rpcconsole.cpp:470
RPCConsole::cmdRequest
void cmdRequest(const QString &command, const WalletModel *wallet_model)
PACKAGE_NAME
#define PACKAGE_NAME
Definition: bitcoin-config.h:362
RPCConsole::m_last_wallet_model
WalletModel * m_last_wallet_model
Definition: rpcconsole.h:169
PlatformStyle::getImagesOnButtons
bool getImagesOnButtons() const
Definition: platformstyle.h:21
RPCConsole::setClientModel
void setClientModel(ClientModel *model=nullptr, int bestblock_height=0, int64_t bestblock_date=0, double verification_progress=0.0)
Definition: rpcconsole.cpp:634
node.h
ClientModel::bytesChanged
void bytesChanged(quint64 totalBytesIn, quint64 totalBytesOut)
RPCConsole::CMD_REPLY
@ CMD_REPLY
Definition: rpcconsole.h:59
util::ThreadRename
void ThreadRename(std::string &&)
Rename a thread both in terms of an internal (in-memory) name as well as its system thread name.
Definition: threadnames.cpp:57
RPCConsole::showEvent
void showEvent(QShowEvent *event) override
Definition: rpcconsole.cpp:1209
RPCConsole::on_tabWidget_currentChanged
void on_tabWidget_currentChanged(int index)
Definition: rpcconsole.cpp:1097
univalue.h
QtRPCTimerInterface::Name
const char * Name() override
Implementation name.
Definition: rpcconsole.cpp:129
RPCConsole::disconnectSelectedNode
void disconnectSelectedNode()
Disconnect a selected node on the Peers tab.
Definition: rpcconsole.cpp:1250
interfaces::Node::listRpcCommands
virtual std::vector< std::string > listRpcCommands()=0
List rpc commands.
RPCConsole
Local Bitcoin RPC console.
Definition: rpcconsole.h:38
CONSOLE_HISTORY
const int CONSOLE_HISTORY
Definition: rpcconsole.cpp:56
RPCConsole::TranslatedStrings::to
const QString to
Definition: rpcconsole.h:138
RPCConsole::BANSUBNET_COLUMN_WIDTH
@ BANSUBNET_COLUMN_WIDTH
Definition: rpcconsole.h:150
GUIUtil::AddButtonShortcut
void AddButtonShortcut(QAbstractButton *button, const QKeySequence &shortcut)
Connects an additional shortcut to a QAbstractButton.
Definition: guiutil.cpp:126
CSubNet
Definition: netaddress.h:486
ClientModel::formatFullVersion
QString formatFullVersion() const
Definition: clientmodel.cpp:202
WalletModel::getWalletName
QString getWalletName() const
Definition: walletmodel.cpp:572
RPCConsole::clear
void clear(bool keep_prompt=false)
Definition: rpcconsole.cpp:837
RPCConsole::PING_COLUMN_WIDTH
@ PING_COLUMN_WIDTH
Definition: rpcconsole.h:149
RPCConsole::showBanTableContextMenu
void showBanTableContextMenu(const QPoint &point)
Show custom context menu on Bans tab.
Definition: rpcconsole.cpp:1243
RPCConsole::SUBVERSION_COLUMN_WIDTH
@ SUBVERSION_COLUMN_WIDTH
Definition: rpcconsole.h:148
CNodeCombinedStats
Definition: peertablemodel.h:27
QtRPCTimerInterface
Definition: rpcconsole.cpp:125
GUIUtil::formatBytes
QString formatBytes(uint64_t bytes)
Definition: guiutil.cpp:772
RPCConsole::BANTIME_COLUMN_WIDTH
@ BANTIME_COLUMN_WIDTH
Definition: rpcconsole.h:151
GUIUtil::formatServicesStr
QString formatServicesStr(quint64 mask)
Format CNodeStats.nServices bitmask into a user-readable string.
Definition: guiutil.cpp:709
RPCConsole::hideEvent
void hideEvent(QHideEvent *event) override
Definition: rpcconsole.cpp:1220
RPCConsole::updateDetailWidget
void updateDetailWidget()
show detailed information on ui about selected node
Definition: rpcconsole.cpp:1134
RPCConsole::m_banlist_widget_header_state
QByteArray m_banlist_widget_header_state
Definition: rpcconsole.h:172
UniValue::isArray
bool isArray() const
Definition: univalue.h:83
GUIUtil::fixedPitchFont
QFont fixedPitchFont(bool use_embedded_font)
Definition: guiutil.cpp:87
RPCConsole::m_node
interfaces::Node & m_node
Definition: rpcconsole.h:155
interfaces::Node::unban
virtual bool unban(const CSubNet &ip)=0
Unban node.
RPCConsole::thread
QThread thread
Definition: rpcconsole.h:168
RPCConsole::TabTypes::GRAPH
@ GRAPH
interfaces::Node
Top-level interface for a bitcoin node (bitcoind process).
Definition: node.h:54
RPCConsole::tabTitle
QString tabTitle(TabTypes tab_type) const
Definition: rpcconsole.cpp:1324
RPCConsole::TranslatedStrings::na
const QString na
Definition: rpcconsole.h:139
RPCConsole::~RPCConsole
~RPCConsole()
Definition: rpcconsole.cpp:566
BanTableModel::shouldShow
bool shouldShow()
Definition: bantablemodel.cpp:180
PeerTableModel::Ping
@ Ping
Definition: peertablemodel.h:54
IsDigit
constexpr bool IsDigit(char c)
Tests if the given character is a decimal digit.
Definition: strencodings.h:77
platformstyle.h
RPCConsole::history
QStringList history
Definition: rpcconsole.h:158
system.h
PeerTableModel::StatsRole
@ StatsRole
Definition: peertablemodel.h:61
RPCConsole::TranslatedStrings::unknown
const QString unknown
Definition: rpcconsole.h:139
RPCConsole::TabTypes
TabTypes
Definition: rpcconsole.h:63
TrafficGraphWidget::clear
void clear()
Definition: trafficgraphwidget.cpp:166
RPCConsole::cmdBeforeBrowsing
QString cmdBeforeBrowsing
Definition: rpcconsole.h:160
RPCExecutor
Definition: rpcconsole.cpp:89
ClientModel
Model for Bitcoin network client.
Definition: clientmodel.h:47
Join
auto Join(const std::vector< T > &list, const BaseType &separator, UnaryOp unary_op) -> decltype(unary_op(list.at(0)))
Join a list of items.
Definition: string.h:44
RPCConsole::eventFilter
virtual bool eventFilter(QObject *obj, QEvent *event) override
Definition: rpcconsole.cpp:589
Ui
Definition: addressbookpage.h:14
GUIUtil::HtmlEscape
QString HtmlEscape(const QString &str, bool fMultiLine)
Definition: guiutil.cpp:232
RPCConsole::setTabFocus
void setTabFocus(enum TabTypes tabType)
set which tab has the focus (is visible)
Definition: rpcconsole.cpp:1319
UniValue::get_int
int get_int() const
Definition: univalue_get.cpp:104
GUIUtil::copyEntryData
void copyEntryData(const QAbstractItemView *view, int column, int role)
Copy a field of the currently selected entry of a view to the clipboard.
Definition: guiutil.cpp:247
RPCConsole::on_lineEdit_returnPressed
void on_lineEdit_returnPressed()
Definition: rpcconsole.cpp:979
ClientModel::formatSubVersion
QString formatSubVersion() const
Definition: clientmodel.cpp:207
RPCConsole::peersTableContextMenu
QMenu * peersTableContextMenu
Definition: rpcconsole.h:164
QtRPCTimerInterface::~QtRPCTimerInterface
~QtRPCTimerInterface()
Definition: rpcconsole.cpp:128
ClientModel::formatClientStartupTime
QString formatClientStartupTime() const
Definition: clientmodel.cpp:217
QtRPCTimerBase::QtRPCTimerBase
QtRPCTimerBase(std::function< void()> &_func, int64_t millis)
Definition: rpcconsole.cpp:112
PeerTableModel::startAutoRefresh
void startAutoRefresh()
Definition: peertablemodel.cpp:36
RPCConsole::RPCExecuteCommandLine
static bool RPCExecuteCommandLine(interfaces::Node &node, std::string &strResult, const std::string &strCommand, std::string *const pstrFilteredOut=nullptr, const WalletModel *wallet_model=nullptr)
Definition: rpcconsole.h:47
interfaces::Node::rpcSetTimerInterfaceIfUnset
virtual void rpcSetTimerInterfaceIfUnset(RPCTimerInterface *iface)=0
Set RPC timer interface if unset.
RPCConsole::message
void message(int category, const QString &msg)
Append the message to the message widget.
Definition: rpcconsole.h:109
UniValue::push_back
bool push_back(const UniValue &val)
Definition: univalue.cpp:108
GUIUtil::NetworkToQString
QString NetworkToQString(Network net)
Convert enum Network to QString.
Definition: guiutil.cpp:657
Params
const CChainParams & Params()
Return the currently selected parameters.
Definition: chainparams.cpp:561
CSubNet::IsValid
bool IsValid() const
Definition: netaddress.cpp:1208
ClientModel::dataDir
QString dataDir() const
Definition: clientmodel.cpp:222
node
Definition: interfaces.cpp:68
RPCConsole::on_openDebugLogfileButton_clicked
void on_openDebugLogfileButton_clicked()
open the debug.log from the current datadir
Definition: rpcconsole.cpp:1104
FONT_RANGE
const QSize FONT_RANGE(4, 40)
GUIUtil::formatDurationStr
QString formatDurationStr(int secs)
Convert seconds into a QString with days, hours, mins, secs.
Definition: guiutil.cpp:689
ICON_MAPPING
const struct @8 ICON_MAPPING[]
RPCConsole::browseHistory
void browseHistory(int offset)
Go forward or back in history.
Definition: rpcconsole.cpp:1048
RPCExecutor::reply
void reply(int category, const QString &command)
RPCConsole::historyPtr
int historyPtr
Definition: rpcconsole.h:159
RPCConsole::on_sldGraphRange_valueChanged
void on_sldGraphRange_valueChanged(int value)
change the time range of the network traffic graph
Definition: rpcconsole.cpp:1115
bantablemodel.h
RPCExecutor::request
void request(const QString &command, const WalletModel *wallet_model)
Definition: rpcconsole.cpp:414
interfaces::Node::rpcUnsetTimerInterface
virtual void rpcUnsetTimerInterface(RPCTimerInterface *iface)=0
Unset RPC timer interface.
netbase.h
RPCConsole::setNumBlocks
void setNumBlocks(int count, const QDateTime &blockDate, double nVerificationProgress, bool headers)
Set number of blocks and last block date shown in the UI.
Definition: rpcconsole.cpp:961
GUIUtil::handleCloseWindowShortcut
void handleCloseWindowShortcut(QWidget *w)
Definition: guiutil.cpp:402
find_value
const UniValue & find_value(const UniValue &obj, const std::string &name)
Definition: univalue.cpp:234
RPCConsole::fontBigger
void fontBigger()
Definition: rpcconsole.cpp:802
RPCConsole::TranslatedStrings::no
const QString no
Definition: rpcconsole.h:138
GUIUtil::getEntryData
QList< QModelIndex > getEntryData(const QAbstractItemView *view, int column)
Return a field of the currently selected entry as a QString.
Definition: guiutil.cpp:260
RPCConsole::changeEvent
void changeEvent(QEvent *e) override
Definition: rpcconsole.cpp:900
WalletModel::getDisplayName
QString getDisplayName() const
Definition: walletmodel.cpp:577
server.h
PlatformStyle
Definition: platformstyle.h:13
GUIUtil::formatPingTime
QString formatPingTime(std::chrono::microseconds ping_time)
Format a CNodeStats.m_last_ping_time into a user-readable string or display N/A, if 0.
Definition: guiutil.cpp:723
RPCConsole::unbanSelectedNode
void unbanSelectedNode()
Unban a selected node on the Bans tab.
Definition: rpcconsole.cpp:1281
PeerTableModel::stopAutoRefresh
void stopAutoRefresh()
Definition: peertablemodel.cpp:41
threadnames.h
RPCConsole::ts
struct RPCConsole::TranslatedStrings ts
QtRPCTimerBase::~QtRPCTimerBase
~QtRPCTimerBase()
Definition: rpcconsole.cpp:119
RPCConsole::rpcTimerInterface
RPCTimerInterface * rpcTimerInterface
Definition: rpcconsole.h:163
RPCConsole::banSelectedNode
void banSelectedNode(int bantime)
Ban a selected node on the Peers tab.
Definition: rpcconsole.cpp:1264
BanTableModel::refresh
void refresh()
Definition: bantablemodel.cpp:166
QtRPCTimerBase::func
std::function< void()> func
Definition: rpcconsole.cpp:122
client.h
RPCConsole::clientModel
ClientModel * clientModel
Definition: rpcconsole.h:157
ClientModel::networkActiveChanged
void networkActiveChanged(bool networkActive)
RPCConsole::banTableContextMenu
QMenu * banTableContextMenu
Definition: rpcconsole.h:165
clientmodel.h
RPCConsole::TabTypes::INFO
@ INFO
BanTableModel::Address
@ Address
Definition: bantablemodel.h:54
GetTimeSeconds
int64_t GetTimeSeconds()
Returns the system time (not mockable)
Definition: time.cpp:127
UniValue::isObject
bool isObject() const
Definition: univalue.h:84
ClientModel::getBanTableModel
BanTableModel * getBanTableModel()
Definition: clientmodel.cpp:197
RPCConsole::TabTypes::PEERS
@ PEERS