Dogecoin Core  1.14.2
P2P Digital Currency
rpcconsole.cpp
Go to the documentation of this file.
1 // Copyright (c) 2011-2016 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)
6 #include "config/bitcoin-config.h"
7 #endif
8 
9 #include "rpcconsole.h"
10 #include "ui_debugwindow.h"
11 
12 #include "bantablemodel.h"
13 #include "clientmodel.h"
14 #include "guiutil.h"
15 #include "platformstyle.h"
16 #include "bantablemodel.h"
17 
18 #include "chainparams.h"
19 #include "netbase.h"
20 #include "rpc/server.h"
21 #include "rpc/client.h"
22 #include "util.h"
23 
24 #include <openssl/crypto.h>
25 
26 #include <univalue.h>
27 
28 #ifdef ENABLE_WALLET
29 #include <db_cxx.h>
30 #endif
31 
32 #include <QKeyEvent>
33 #include <QMenu>
34 #include <QMessageBox>
35 #include <QScrollBar>
36 #include <QSettings>
37 #include <QSignalMapper>
38 #include <QThread>
39 #include <QTime>
40 #include <QTimer>
41 #include <QStringList>
42 
43 #if QT_VERSION < 0x050000
44 #include <QUrl>
45 #endif
46 
47 // TODO: add a scrollback limit, as there is currently none
48 // TODO: make it possible to filter out categories (esp debug messages when implemented)
49 // TODO: receive errors and debug messages through ClientModel
50 
51 const int CONSOLE_HISTORY = 50;
53 const QSize FONT_RANGE(4, 40);
54 const char fontSizeSettingsKey[] = "consoleFontSize";
55 
56 const struct {
57  const char *url;
58  const char *source;
59 } ICON_MAPPING[] = {
60  {"cmd-request", ":/icons/tx_input"},
61  {"cmd-reply", ":/icons/tx_output"},
62  {"cmd-error", ":/icons/tx_output"},
63  {"misc", ":/icons/tx_inout"},
64  {NULL, NULL}
65 };
66 
67 namespace {
68 
69 // don't add private key handling cmd's to the history
70 const QStringList historyFilter = QStringList()
71  << "importprivkey"
72  << "importmulti"
73  << "signmessagewithprivkey"
74  << "signrawtransaction"
75  << "walletpassphrase"
76  << "walletpassphrasechange"
77  << "encryptwallet";
78 
79 }
80 
81 /* Object for executing console RPC commands in a separate thread.
82 */
83 class RPCExecutor : public QObject
84 {
85  Q_OBJECT
86 
87 public Q_SLOTS:
88  void request(const QString &command);
89 
90 Q_SIGNALS:
91  void reply(int category, const QString &command);
92 };
93 
97 class QtRPCTimerBase: public QObject, public RPCTimerBase
98 {
99  Q_OBJECT
100 public:
101  QtRPCTimerBase(boost::function<void(void)>& _func, int64_t millis):
102  func(_func)
103  {
104  timer.setSingleShot(true);
105  connect(&timer, SIGNAL(timeout()), this, SLOT(timeout()));
106  timer.start(millis);
107  }
109 private Q_SLOTS:
110  void timeout() { func(); }
111 private:
112  QTimer timer;
113  boost::function<void(void)> func;
114 };
115 
117 {
118 public:
120  const char *Name() { return "Qt"; }
121  RPCTimerBase* NewTimer(boost::function<void(void)>& func, int64_t millis)
122  {
123  return new QtRPCTimerBase(func, millis);
124  }
125 };
126 
127 
128 #include "rpcconsole.moc"
129 
149 bool RPCConsole::RPCParseCommandLine(std::string &strResult, const std::string &strCommand, const bool fExecute, std::string * const pstrFilteredOut)
150 {
151  std::vector< std::vector<std::string> > stack;
152  stack.push_back(std::vector<std::string>());
153 
154  enum CmdParseState
155  {
156  STATE_EATING_SPACES,
157  STATE_EATING_SPACES_IN_ARG,
158  STATE_EATING_SPACES_IN_BRACKETS,
159  STATE_ARGUMENT,
160  STATE_SINGLEQUOTED,
161  STATE_DOUBLEQUOTED,
162  STATE_ESCAPE_OUTER,
163  STATE_ESCAPE_DOUBLEQUOTED,
164  STATE_COMMAND_EXECUTED,
165  STATE_COMMAND_EXECUTED_INNER
166  } state = STATE_EATING_SPACES;
167  std::string curarg;
168  UniValue lastResult;
169  unsigned nDepthInsideSensitive = 0;
170  size_t filter_begin_pos = 0, chpos;
171  std::vector<std::pair<size_t, size_t>> filter_ranges;
172 
173  auto add_to_current_stack = [&](const std::string& strArg) {
174  if (stack.back().empty() && (!nDepthInsideSensitive) && historyFilter.contains(QString::fromStdString(strArg), Qt::CaseInsensitive)) {
175  nDepthInsideSensitive = 1;
176  filter_begin_pos = chpos;
177  }
178  // Make sure stack is not empty before adding something
179  if (stack.empty()) {
180  stack.push_back(std::vector<std::string>());
181  }
182  stack.back().push_back(strArg);
183  };
184 
185  auto close_out_params = [&]() {
186  if (nDepthInsideSensitive) {
187  if (!--nDepthInsideSensitive) {
188  assert(filter_begin_pos);
189  filter_ranges.push_back(std::make_pair(filter_begin_pos, chpos));
190  filter_begin_pos = 0;
191  }
192  }
193  stack.pop_back();
194  };
195 
196  std::string strCommandTerminated = strCommand;
197  if (strCommandTerminated.back() != '\n')
198  strCommandTerminated += "\n";
199  for (chpos = 0; chpos < strCommandTerminated.size(); ++chpos)
200  {
201  char ch = strCommandTerminated[chpos];
202  switch(state)
203  {
204  case STATE_COMMAND_EXECUTED_INNER:
205  case STATE_COMMAND_EXECUTED:
206  {
207  bool breakParsing = true;
208  switch(ch)
209  {
210  case '[': curarg.clear(); state = STATE_COMMAND_EXECUTED_INNER; break;
211  default:
212  if (state == STATE_COMMAND_EXECUTED_INNER)
213  {
214  if (ch != ']')
215  {
216  // append char to the current argument (which is also used for the query command)
217  curarg += ch;
218  break;
219  }
220  if (curarg.size() && fExecute)
221  {
222  // if we have a value query, query arrays with index and objects with a string key
223  UniValue subelement;
224  if (lastResult.isArray())
225  {
226  for(char argch: curarg)
227  if (!std::isdigit(argch))
228  throw std::runtime_error("Invalid result query");
229  subelement = lastResult[atoi(curarg.c_str())];
230  }
231  else if (lastResult.isObject())
232  subelement = find_value(lastResult, curarg);
233  else
234  throw std::runtime_error("Invalid result query"); //no array or object: abort
235  lastResult = subelement;
236  }
237 
238  state = STATE_COMMAND_EXECUTED;
239  break;
240  }
241  // don't break parsing when the char is required for the next argument
242  breakParsing = false;
243 
244  // pop the stack and return the result to the current command arguments
245  close_out_params();
246 
247  // don't stringify the json in case of a string to avoid doublequotes
248  if (lastResult.isStr())
249  curarg = lastResult.get_str();
250  else
251  curarg = lastResult.write(2);
252 
253  // if we have a non empty result, use it as stack argument otherwise as general result
254  if (curarg.size())
255  {
256  if (stack.size())
257  add_to_current_stack(curarg);
258  else
259  strResult = curarg;
260  }
261  curarg.clear();
262  // assume eating space state
263  state = STATE_EATING_SPACES;
264  }
265  if (breakParsing)
266  break;
267  }
268  case STATE_ARGUMENT: // In or after argument
269  case STATE_EATING_SPACES_IN_ARG:
270  case STATE_EATING_SPACES_IN_BRACKETS:
271  case STATE_EATING_SPACES: // Handle runs of whitespace
272  switch(ch)
273  {
274  case '"': state = STATE_DOUBLEQUOTED; break;
275  case '\'': state = STATE_SINGLEQUOTED; break;
276  case '\\': state = STATE_ESCAPE_OUTER; break;
277  case '(': case ')': case '\n':
278  if (state == STATE_EATING_SPACES_IN_ARG)
279  throw std::runtime_error("Invalid Syntax");
280  if (state == STATE_ARGUMENT)
281  {
282  if (ch == '(' && stack.size() && stack.back().size() > 0)
283  {
284  if (nDepthInsideSensitive) {
285  ++nDepthInsideSensitive;
286  }
287  stack.push_back(std::vector<std::string>());
288  }
289 
290  // don't allow commands after executed commands on baselevel
291  if (!stack.size())
292  throw std::runtime_error("Invalid Syntax");
293 
294  add_to_current_stack(curarg);
295  curarg.clear();
296  state = STATE_EATING_SPACES_IN_BRACKETS;
297  }
298  if ((ch == ')' || ch == '\n') && stack.size() > 0)
299  {
300  if (fExecute) {
301  // Convert argument list to JSON objects in method-dependent way,
302  // and pass it along with the method name to the dispatcher.
303  JSONRPCRequest req;
304  req.params = RPCConvertValues(stack.back()[0], std::vector<std::string>(stack.back().begin() + 1, stack.back().end()));
305  req.strMethod = stack.back()[0];
306  lastResult = tableRPC.execute(req);
307  }
308 
309  state = STATE_COMMAND_EXECUTED;
310  curarg.clear();
311  }
312  break;
313  case ' ': case ',': case '\t':
314  if(state == STATE_EATING_SPACES_IN_ARG && curarg.empty() && ch == ',')
315  throw std::runtime_error("Invalid Syntax");
316 
317  else if(state == STATE_ARGUMENT) // Space ends argument
318  {
319  add_to_current_stack(curarg);
320  curarg.clear();
321  }
322  if ((state == STATE_EATING_SPACES_IN_BRACKETS || state == STATE_ARGUMENT) && ch == ',')
323  {
324  state = STATE_EATING_SPACES_IN_ARG;
325  break;
326  }
327  state = STATE_EATING_SPACES;
328  break;
329  default: curarg += ch; state = STATE_ARGUMENT;
330  }
331  break;
332  case STATE_SINGLEQUOTED: // Single-quoted string
333  switch(ch)
334  {
335  case '\'': state = STATE_ARGUMENT; break;
336  default: curarg += ch;
337  }
338  break;
339  case STATE_DOUBLEQUOTED: // Double-quoted string
340  switch(ch)
341  {
342  case '"': state = STATE_ARGUMENT; break;
343  case '\\': state = STATE_ESCAPE_DOUBLEQUOTED; break;
344  default: curarg += ch;
345  }
346  break;
347  case STATE_ESCAPE_OUTER: // '\' outside quotes
348  curarg += ch; state = STATE_ARGUMENT;
349  break;
350  case STATE_ESCAPE_DOUBLEQUOTED: // '\' in double-quoted text
351  if(ch != '"' && ch != '\\') curarg += '\\'; // keep '\' for everything but the quote and '\' itself
352  curarg += ch; state = STATE_DOUBLEQUOTED;
353  break;
354  }
355  }
356  if (pstrFilteredOut) {
357  if (STATE_COMMAND_EXECUTED == state) {
358  assert(!stack.empty());
359  close_out_params();
360  }
361  *pstrFilteredOut = strCommand;
362  for (auto i = filter_ranges.rbegin(); i != filter_ranges.rend(); ++i) {
363  pstrFilteredOut->replace(i->first, i->second - i->first, "(…)");
364  }
365  }
366  switch(state) // final state
367  {
368  case STATE_COMMAND_EXECUTED:
369  if (lastResult.isStr())
370  strResult = lastResult.get_str();
371  else
372  strResult = lastResult.write(2);
373  case STATE_ARGUMENT:
374  case STATE_EATING_SPACES:
375  return true;
376  default: // ERROR to end in one of the other states
377  return false;
378  }
379 }
380 
381 void RPCExecutor::request(const QString &command)
382 {
383  try
384  {
385  std::string result;
386  std::string executableCommand = command.toStdString() + "\n";
387  if(!RPCConsole::RPCExecuteCommandLine(result, executableCommand))
388  {
389  Q_EMIT reply(RPCConsole::CMD_ERROR, QString("Parse error: unbalanced ' or \""));
390  return;
391  }
392  Q_EMIT reply(RPCConsole::CMD_REPLY, QString::fromStdString(result));
393  }
394  catch (UniValue& objError)
395  {
396  try // Nice formatting for standard-format error
397  {
398  int code = find_value(objError, "code").get_int();
399  std::string message = find_value(objError, "message").get_str();
400  Q_EMIT reply(RPCConsole::CMD_ERROR, QString::fromStdString(message) + " (code " + QString::number(code) + ")");
401  }
402  catch (const std::runtime_error&) // raised when converting to invalid type, i.e. missing code or message
403  { // Show raw JSON object
404  Q_EMIT reply(RPCConsole::CMD_ERROR, QString::fromStdString(objError.write()));
405  }
406  }
407  catch (const std::exception& e)
408  {
409  Q_EMIT reply(RPCConsole::CMD_ERROR, QString("Error: ") + QString::fromStdString(e.what()));
410  }
411 }
412 
413 RPCConsole::RPCConsole(const PlatformStyle *_platformStyle, QWidget *parent) :
414  QWidget(parent),
415  ui(new Ui::RPCConsole),
416  clientModel(0),
417  historyPtr(0),
418  platformStyle(_platformStyle),
419  peersTableContextMenu(0),
420  banTableContextMenu(0),
421  consoleFontSize(0)
422 {
423  ui->setupUi(this);
424  GUIUtil::restoreWindowGeometry("nRPCConsoleWindow", this->size(), this);
425 
426  ui->openDebugLogfileButton->setToolTip(ui->openDebugLogfileButton->toolTip().arg(tr(PACKAGE_NAME)));
427 
429  ui->openDebugLogfileButton->setIcon(platformStyle->SingleColorIcon(":/icons/export"));
430  }
431  ui->clearButton->setIcon(platformStyle->SingleColorIcon(":/icons/remove"));
432  ui->fontBiggerButton->setIcon(platformStyle->SingleColorIcon(":/icons/fontbigger"));
433  ui->fontSmallerButton->setIcon(platformStyle->SingleColorIcon(":/icons/fontsmaller"));
434 
435  // Install event filter for up and down arrow
436  ui->lineEdit->installEventFilter(this);
437  ui->messagesWidget->installEventFilter(this);
438 
439  connect(ui->clearButton, SIGNAL(clicked()), this, SLOT(clear()));
440  connect(ui->fontBiggerButton, SIGNAL(clicked()), this, SLOT(fontBigger()));
441  connect(ui->fontSmallerButton, SIGNAL(clicked()), this, SLOT(fontSmaller()));
442  connect(ui->btnClearTrafficGraph, SIGNAL(clicked()), ui->trafficGraph, SLOT(clear()));
443 
444  // set library version labels
445 #ifdef ENABLE_WALLET
446  ui->berkeleyDBVersion->setText(DbEnv::version(0, 0, 0));
447 #else
448  ui->label_berkeleyDBVersion->hide();
449  ui->berkeleyDBVersion->hide();
450 #endif
451  // Register RPC timer interface
453  // avoid accidentally overwriting an existing, non QTThread
454  // based timer interface
456 
458 
459  ui->detailWidget->hide();
460  ui->peerHeading->setText(tr("Select a peer to view detailed information."));
461 
462  QSettings settings;
463  consoleFontSize = settings.value(fontSizeSettingsKey, QFontInfo(QFont()).pointSize()).toInt();
464  clear();
465 }
466 
468 {
469  GUIUtil::saveWindowGeometry("nRPCConsoleWindow", this);
471  delete rpcTimerInterface;
472  delete ui;
473 }
474 
475 bool RPCConsole::eventFilter(QObject* obj, QEvent *event)
476 {
477  if(event->type() == QEvent::KeyPress) // Special key handling
478  {
479  QKeyEvent *keyevt = static_cast<QKeyEvent*>(event);
480  int key = keyevt->key();
481  Qt::KeyboardModifiers mod = keyevt->modifiers();
482  switch(key)
483  {
484  case Qt::Key_Up: if(obj == ui->lineEdit) { browseHistory(-1); return true; } break;
485  case Qt::Key_Down: if(obj == ui->lineEdit) { browseHistory(1); return true; } break;
486  case Qt::Key_PageUp: /* pass paging keys to messages widget */
487  case Qt::Key_PageDown:
488  if(obj == ui->lineEdit)
489  {
490  QApplication::postEvent(ui->messagesWidget, new QKeyEvent(*keyevt));
491  return true;
492  }
493  break;
494  case Qt::Key_Return:
495  case Qt::Key_Enter:
496  // forward these events to lineEdit
497  if(obj == autoCompleter->popup()) {
498  QApplication::postEvent(ui->lineEdit, new QKeyEvent(*keyevt));
499  return true;
500  }
501  break;
502  default:
503  // Typing in messages widget brings focus to line edit, and redirects key there
504  // Exclude most combinations and keys that emit no text, except paste shortcuts
505  if(obj == ui->messagesWidget && (
506  (!mod && !keyevt->text().isEmpty() && key != Qt::Key_Tab) ||
507  ((mod & Qt::ControlModifier) && key == Qt::Key_V) ||
508  ((mod & Qt::ShiftModifier) && key == Qt::Key_Insert)))
509  {
510  ui->lineEdit->setFocus();
511  QApplication::postEvent(ui->lineEdit, new QKeyEvent(*keyevt));
512  return true;
513  }
514  }
515  }
516  return QWidget::eventFilter(obj, event);
517 }
518 
520 {
521  clientModel = model;
522  ui->trafficGraph->setClientModel(model);
524  // Keep up to date with client
526  connect(model, SIGNAL(numConnectionsChanged(int)), this, SLOT(setNumConnections(int)));
527 
528  setNumBlocks(model->getNumBlocks(), model->getLastBlockDate(), model->getVerificationProgress(NULL), false);
529  connect(model, SIGNAL(numBlocksChanged(int,QDateTime,double,bool)), this, SLOT(setNumBlocks(int,QDateTime,double,bool)));
530 
532  connect(model, SIGNAL(networkActiveChanged(bool)), this, SLOT(setNetworkActive(bool)));
533 
535  connect(model, SIGNAL(bytesChanged(quint64,quint64)), this, SLOT(updateTrafficStats(quint64, quint64)));
536 
537  connect(model, SIGNAL(mempoolSizeChanged(long,size_t)), this, SLOT(setMempoolSize(long,size_t)));
538 
539  // set up peer table
540  ui->peerWidget->setModel(model->getPeerTableModel());
541  ui->peerWidget->verticalHeader()->hide();
542  ui->peerWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
543  ui->peerWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
544  ui->peerWidget->setSelectionMode(QAbstractItemView::ExtendedSelection);
545  ui->peerWidget->setContextMenuPolicy(Qt::CustomContextMenu);
546  ui->peerWidget->setColumnWidth(PeerTableModel::Address, ADDRESS_COLUMN_WIDTH);
547  ui->peerWidget->setColumnWidth(PeerTableModel::Subversion, SUBVERSION_COLUMN_WIDTH);
548  ui->peerWidget->setColumnWidth(PeerTableModel::Ping, PING_COLUMN_WIDTH);
549  ui->peerWidget->horizontalHeader()->setStretchLastSection(true);
550 
551  // create peer table context menu actions
552  QAction* disconnectAction = new QAction(tr("&Disconnect"), this);
553  QAction* banAction1h = new QAction(tr("Ban for") + " " + tr("1 &hour"), this);
554  QAction* banAction24h = new QAction(tr("Ban for") + " " + tr("1 &day"), this);
555  QAction* banAction7d = new QAction(tr("Ban for") + " " + tr("1 &week"), this);
556  QAction* banAction365d = new QAction(tr("Ban for") + " " + tr("1 &year"), this);
557 
558  // create peer table context menu
559  peersTableContextMenu = new QMenu(this);
560  peersTableContextMenu->addAction(disconnectAction);
561  peersTableContextMenu->addAction(banAction1h);
562  peersTableContextMenu->addAction(banAction24h);
563  peersTableContextMenu->addAction(banAction7d);
564  peersTableContextMenu->addAction(banAction365d);
565 
566  // Add a signal mapping to allow dynamic context menu arguments.
567  // We need to use int (instead of int64_t), because signal mapper only supports
568  // int or objects, which is okay because max bantime (1 year) is < int_max.
569  QSignalMapper* signalMapper = new QSignalMapper(this);
570  signalMapper->setMapping(banAction1h, 60*60);
571  signalMapper->setMapping(banAction24h, 60*60*24);
572  signalMapper->setMapping(banAction7d, 60*60*24*7);
573  signalMapper->setMapping(banAction365d, 60*60*24*365);
574  connect(banAction1h, SIGNAL(triggered()), signalMapper, SLOT(map()));
575  connect(banAction24h, SIGNAL(triggered()), signalMapper, SLOT(map()));
576  connect(banAction7d, SIGNAL(triggered()), signalMapper, SLOT(map()));
577  connect(banAction365d, SIGNAL(triggered()), signalMapper, SLOT(map()));
578  connect(signalMapper, SIGNAL(mapped(int)), this, SLOT(banSelectedNode(int)));
579 
580  // peer table context menu signals
581  connect(ui->peerWidget, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(showPeersTableContextMenu(const QPoint&)));
582  connect(disconnectAction, SIGNAL(triggered()), this, SLOT(disconnectSelectedNode()));
583 
584  // peer table signal handling - update peer details when selecting new node
585  connect(ui->peerWidget->selectionModel(), SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)),
586  this, SLOT(peerSelected(const QItemSelection &, const QItemSelection &)));
587  // peer table signal handling - update peer details when new nodes are added to the model
588  connect(model->getPeerTableModel(), SIGNAL(layoutChanged()), this, SLOT(peerLayoutChanged()));
589  // peer table signal handling - cache selected node ids
590  connect(model->getPeerTableModel(), SIGNAL(layoutAboutToBeChanged()), this, SLOT(peerLayoutAboutToChange()));
591 
592  // set up ban table
593  ui->banlistWidget->setModel(model->getBanTableModel());
594  ui->banlistWidget->verticalHeader()->hide();
595  ui->banlistWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
596  ui->banlistWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
597  ui->banlistWidget->setSelectionMode(QAbstractItemView::SingleSelection);
598  ui->banlistWidget->setContextMenuPolicy(Qt::CustomContextMenu);
599  ui->banlistWidget->setColumnWidth(BanTableModel::Address, BANSUBNET_COLUMN_WIDTH);
600  ui->banlistWidget->setColumnWidth(BanTableModel::Bantime, BANTIME_COLUMN_WIDTH);
601  ui->banlistWidget->horizontalHeader()->setStretchLastSection(true);
602 
603  // create ban table context menu action
604  QAction* unbanAction = new QAction(tr("&Unban"), this);
605 
606  // create ban table context menu
607  banTableContextMenu = new QMenu(this);
608  banTableContextMenu->addAction(unbanAction);
609 
610  // ban table context menu signals
611  connect(ui->banlistWidget, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(showBanTableContextMenu(const QPoint&)));
612  connect(unbanAction, SIGNAL(triggered()), this, SLOT(unbanSelectedNode()));
613 
614  // ban table signal handling - clear peer details when clicking a peer in the ban table
615  connect(ui->banlistWidget, SIGNAL(clicked(const QModelIndex&)), this, SLOT(clearSelectedNode()));
616  // ban table signal handling - ensure ban table is shown or hidden (if empty)
617  connect(model->getBanTableModel(), SIGNAL(layoutChanged()), this, SLOT(showOrHideBanTableIfRequired()));
619 
620  // Provide initial values
621  ui->clientVersion->setText(model->formatFullVersion());
622  ui->clientUserAgent->setText(model->formatSubVersion());
623  ui->dataDir->setText(model->dataDir());
624  ui->startupTime->setText(model->formatClientStartupTime());
625  ui->networkName->setText(QString::fromStdString(Params().NetworkIDString()));
626 
627  //Setup autocomplete and attach it
628  QStringList wordList;
629  std::vector<std::string> commandList = tableRPC.listCommands();
630  for (size_t i = 0; i < commandList.size(); ++i)
631  {
632  wordList << commandList[i].c_str();
633  }
634 
635  autoCompleter = new QCompleter(wordList, this);
636  ui->lineEdit->setCompleter(autoCompleter);
637  autoCompleter->popup()->installEventFilter(this);
638  // Start thread to execute RPC commands.
639  startExecutor();
640  }
641  if (!model) {
642  // Client model is being set to 0, this means shutdown() is about to be called.
643  // Make sure we clean up the executor thread
644  Q_EMIT stopExecutor();
645  thread.wait();
646  }
647 }
648 
649 static QString categoryClass(int category)
650 {
651  switch(category)
652  {
653  case RPCConsole::CMD_REQUEST: return "cmd-request"; break;
654  case RPCConsole::CMD_REPLY: return "cmd-reply"; break;
655  case RPCConsole::CMD_ERROR: return "cmd-error"; break;
656  default: return "misc";
657  }
658 }
659 
661 {
663 }
664 
666 {
668 }
669 
670 void RPCConsole::setFontSize(int newSize)
671 {
672  QSettings settings;
673 
674  //don't allow a insane font size
675  if (newSize < FONT_RANGE.width() || newSize > FONT_RANGE.height())
676  return;
677 
678  // temp. store the console content
679  QString str = ui->messagesWidget->toHtml();
680 
681  // replace font tags size in current content
682  str.replace(QString("font-size:%1pt").arg(consoleFontSize), QString("font-size:%1pt").arg(newSize));
683 
684  // store the new font size
685  consoleFontSize = newSize;
686  settings.setValue(fontSizeSettingsKey, consoleFontSize);
687 
688  // clear console (reset icon sizes, default stylesheet) and re-add the content
689  float oldPosFactor = 1.0 / ui->messagesWidget->verticalScrollBar()->maximum() * ui->messagesWidget->verticalScrollBar()->value();
690  clear(false);
691  ui->messagesWidget->setHtml(str);
692  ui->messagesWidget->verticalScrollBar()->setValue(oldPosFactor * ui->messagesWidget->verticalScrollBar()->maximum());
693 }
694 
695 void RPCConsole::clear(bool clearHistory)
696 {
697  ui->messagesWidget->clear();
698  if(clearHistory)
699  {
700  history.clear();
701  historyPtr = 0;
702  }
703  ui->lineEdit->clear();
704  ui->lineEdit->setFocus();
705 
706  // Add smoothly scaled icon images.
707  // (when using width/height on an img, Qt uses nearest instead of linear interpolation)
708  for(int i=0; ICON_MAPPING[i].url; ++i)
709  {
710  ui->messagesWidget->document()->addResource(
711  QTextDocument::ImageResource,
712  QUrl(ICON_MAPPING[i].url),
713  platformStyle->SingleColorImage(ICON_MAPPING[i].source).scaled(QSize(consoleFontSize*2, consoleFontSize*2), Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
714  }
715 
716  // Set default style sheet
717  QFontInfo fixedFontInfo(GUIUtil::fixedPitchFont());
718  ui->messagesWidget->document()->setDefaultStyleSheet(
719  QString(
720  "table { }"
721  "td.time { color: #808080; font-size: %2; padding-top: 3px; } "
722  "td.message { font-family: %1; font-size: %2; white-space:pre-wrap; } "
723  "td.cmd-request { color: #006060; } "
724  "td.cmd-error { color: red; } "
725  ".secwarning { color: red; }"
726  "b { color: #006060; } "
727  ).arg(fixedFontInfo.family(), QString("%1pt").arg(consoleFontSize))
728  );
729 
730  message(CMD_REPLY, (tr("Welcome to the %1 RPC console.").arg(tr(PACKAGE_NAME)) + "<br>" +
731  tr("Use up and down arrows to navigate history, and <b>Ctrl-L</b> to clear screen.") + "<br>" +
732  tr("Type <b>help</b> for an overview of available commands.")) +
733  "<br><span class=\"secwarning\">" +
734  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 ramification of a command.") +
735  "</span>",
736  true);
737 }
738 
739 void RPCConsole::keyPressEvent(QKeyEvent *event)
740 {
741  if(windowType() != Qt::Widget && event->key() == Qt::Key_Escape)
742  {
743  close();
744  }
745 }
746 
747 void RPCConsole::message(int category, const QString &message, bool html)
748 {
749  QTime time = QTime::currentTime();
750  QString timeString = time.toString();
751  QString out;
752  out += "<table><tr><td class=\"time\" width=\"65\">" + timeString + "</td>";
753  out += "<td class=\"icon\" width=\"32\"><img src=\"" + categoryClass(category) + "\"></td>";
754  out += "<td class=\"message " + categoryClass(category) + "\" valign=\"middle\">";
755  if(html)
756  out += message;
757  else
758  out += GUIUtil::HtmlEscape(message, false);
759  out += "</td></tr></table>";
760  ui->messagesWidget->append(out);
761 }
762 
764 {
765  QString connections = QString::number(clientModel->getNumConnections()) + " (";
766  connections += tr("In:") + " " + QString::number(clientModel->getNumConnections(CONNECTIONS_IN)) + " / ";
767  connections += tr("Out:") + " " + QString::number(clientModel->getNumConnections(CONNECTIONS_OUT)) + ")";
768 
769  if(!clientModel->getNetworkActive()) {
770  connections += " (" + tr("Network activity disabled") + ")";
771  }
772 
773  ui->numberOfConnections->setText(connections);
774 }
775 
777 {
778  if (!clientModel)
779  return;
780 
782 }
783 
784 void RPCConsole::setNetworkActive(bool networkActive)
785 {
787 }
788 
789 void RPCConsole::setNumBlocks(int count, const QDateTime& blockDate, double nVerificationProgress, bool headers)
790 {
791  if (!headers) {
792  ui->numberOfBlocks->setText(QString::number(count));
793  ui->lastBlockTime->setText(blockDate.toString());
794  }
795 }
796 
797 void RPCConsole::setMempoolSize(long numberOfTxs, size_t dynUsage)
798 {
799  ui->mempoolNumberTxs->setText(QString::number(numberOfTxs));
800 
801  if (dynUsage < 1000000)
802  ui->mempoolSize->setText(QString::number(dynUsage/1000.0, 'f', 2) + " KB");
803  else
804  ui->mempoolSize->setText(QString::number(dynUsage/1000000.0, 'f', 2) + " MB");
805 }
806 
808 {
809  QString cmd = ui->lineEdit->text();
810 
811  if(!cmd.isEmpty())
812  {
813  std::string strFilteredCmd;
814  try {
815  std::string dummy;
816  if (!RPCParseCommandLine(dummy, cmd.toStdString(), false, &strFilteredCmd)) {
817  // Failed to parse command, so we cannot even filter it for the history
818  throw std::runtime_error("Invalid command line");
819  }
820  } catch (const std::exception& e) {
821  QMessageBox::critical(this, "Error", QString("Error: ") + QString::fromStdString(e.what()));
822  return;
823  }
824 
825  ui->lineEdit->clear();
826 
827  cmdBeforeBrowsing = QString();
828 
829  message(CMD_REQUEST, cmd);
830  Q_EMIT cmdRequest(cmd);
831 
832  cmd = QString::fromStdString(strFilteredCmd);
833 
834  // Remove command, if already in history
835  history.removeOne(cmd);
836  // Append command to history
837  history.append(cmd);
838  // Enforce maximum history size
839  while(history.size() > CONSOLE_HISTORY)
840  history.removeFirst();
841  // Set pointer to end of history
842  historyPtr = history.size();
843 
844  // Scroll console view to end
845  scrollToEnd();
846  }
847 }
848 
850 {
851  // store current text when start browsing through the history
852  if (historyPtr == history.size()) {
853  cmdBeforeBrowsing = ui->lineEdit->text();
854  }
855 
856  historyPtr += offset;
857  if(historyPtr < 0)
858  historyPtr = 0;
859  if(historyPtr > history.size())
860  historyPtr = history.size();
861  QString cmd;
862  if(historyPtr < history.size())
863  cmd = history.at(historyPtr);
864  else if (!cmdBeforeBrowsing.isNull()) {
865  cmd = cmdBeforeBrowsing;
866  }
867  ui->lineEdit->setText(cmd);
868 }
869 
871 {
872  RPCExecutor *executor = new RPCExecutor();
873  executor->moveToThread(&thread);
874 
875  // Replies from executor object must go to this object
876  connect(executor, SIGNAL(reply(int,QString)), this, SLOT(message(int,QString)));
877  // Requests from this object must go to executor
878  connect(this, SIGNAL(cmdRequest(QString)), executor, SLOT(request(QString)));
879 
880  // On stopExecutor signal
881  // - quit the Qt event loop in the execution thread
882  connect(this, SIGNAL(stopExecutor()), &thread, SLOT(quit()));
883  // - queue executor for deletion (in execution thread)
884  connect(&thread, SIGNAL(finished()), executor, SLOT(deleteLater()), Qt::DirectConnection);
885 
886  // Default implementation of QThread::run() simply spins up an event loop in the thread,
887  // which is what we want.
888  thread.start();
889 }
890 
892 {
893  if (ui->tabWidget->widget(index) == ui->tab_console)
894  ui->lineEdit->setFocus();
895  else if (ui->tabWidget->widget(index) != ui->tab_peers)
897 }
898 
900 {
902 }
903 
905 {
906  QScrollBar *scrollbar = ui->messagesWidget->verticalScrollBar();
907  scrollbar->setValue(scrollbar->maximum());
908 }
909 
911 {
912  const int multiplier = 5; // each position on the slider represents 5 min
913  int mins = value * multiplier;
914  setTrafficGraphRange(mins);
915 }
916 
917 QString RPCConsole::FormatBytes(quint64 bytes)
918 {
919  if(bytes < 1024)
920  return QString(tr("%1 B")).arg(bytes);
921  if(bytes < 1024 * 1024)
922  return QString(tr("%1 KB")).arg(bytes / 1024);
923  if(bytes < 1024 * 1024 * 1024)
924  return QString(tr("%1 MB")).arg(bytes / 1024 / 1024);
925 
926  return QString(tr("%1 GB")).arg(bytes / 1024 / 1024 / 1024);
927 }
928 
930 {
931  ui->trafficGraph->setGraphRangeMins(mins);
932  ui->lblGraphRange->setText(GUIUtil::formatDurationStr(mins * 60));
933 }
934 
935 void RPCConsole::updateTrafficStats(quint64 totalBytesIn, quint64 totalBytesOut)
936 {
937  ui->lblBytesIn->setText(FormatBytes(totalBytesIn));
938  ui->lblBytesOut->setText(FormatBytes(totalBytesOut));
939 }
940 
941 void RPCConsole::peerSelected(const QItemSelection &selected, const QItemSelection &deselected)
942 {
943  Q_UNUSED(deselected);
944 
945  if (!clientModel || !clientModel->getPeerTableModel() || selected.indexes().isEmpty())
946  return;
947 
948  const CNodeCombinedStats *stats = clientModel->getPeerTableModel()->getNodeStats(selected.indexes().first().row());
949  if (stats)
950  updateNodeDetail(stats);
951 }
952 
954 {
955  QModelIndexList selected = ui->peerWidget->selectionModel()->selectedIndexes();
956  cachedNodeids.clear();
957  for(int i = 0; i < selected.size(); i++)
958  {
959  const CNodeCombinedStats *stats = clientModel->getPeerTableModel()->getNodeStats(selected.at(i).row());
960  cachedNodeids.append(stats->nodeStats.nodeid);
961  }
962 }
963 
965 {
967  return;
968 
969  const CNodeCombinedStats *stats = NULL;
970  bool fUnselect = false;
971  bool fReselect = false;
972 
973  if (cachedNodeids.empty()) // no node selected yet
974  return;
975 
976  // find the currently selected row
977  int selectedRow = -1;
978  QModelIndexList selectedModelIndex = ui->peerWidget->selectionModel()->selectedIndexes();
979  if (!selectedModelIndex.isEmpty()) {
980  selectedRow = selectedModelIndex.first().row();
981  }
982 
983  // check if our detail node has a row in the table (it may not necessarily
984  // be at selectedRow since its position can change after a layout change)
985  int detailNodeRow = clientModel->getPeerTableModel()->getRowByNodeId(cachedNodeids.first());
986 
987  if (detailNodeRow < 0)
988  {
989  // detail node disappeared from table (node disconnected)
990  fUnselect = true;
991  }
992  else
993  {
994  if (detailNodeRow != selectedRow)
995  {
996  // detail node moved position
997  fUnselect = true;
998  fReselect = true;
999  }
1000 
1001  // get fresh stats on the detail node.
1002  stats = clientModel->getPeerTableModel()->getNodeStats(detailNodeRow);
1003  }
1004 
1005  if (fUnselect && selectedRow >= 0) {
1007  }
1008 
1009  if (fReselect)
1010  {
1011  for(int i = 0; i < cachedNodeids.size(); i++)
1012  {
1013  ui->peerWidget->selectRow(clientModel->getPeerTableModel()->getRowByNodeId(cachedNodeids.at(i)));
1014  }
1015  }
1016 
1017  if (stats)
1018  updateNodeDetail(stats);
1019 }
1020 
1022 {
1023  // update the detail ui with latest node information
1024  QString peerAddrDetails(QString::fromStdString(stats->nodeStats.addrName) + " ");
1025  peerAddrDetails += tr("(node id: %1)").arg(QString::number(stats->nodeStats.nodeid));
1026  if (!stats->nodeStats.addrLocal.empty())
1027  peerAddrDetails += "<br />" + tr("via %1").arg(QString::fromStdString(stats->nodeStats.addrLocal));
1028  ui->peerHeading->setText(peerAddrDetails);
1029  ui->peerServices->setText(GUIUtil::formatServicesStr(stats->nodeStats.nServices));
1030  ui->peerLastSend->setText(stats->nodeStats.nLastSend ? GUIUtil::formatDurationStr(GetSystemTimeInSeconds() - stats->nodeStats.nLastSend) : tr("never"));
1031  ui->peerLastRecv->setText(stats->nodeStats.nLastRecv ? GUIUtil::formatDurationStr(GetSystemTimeInSeconds() - stats->nodeStats.nLastRecv) : tr("never"));
1032  ui->peerBytesSent->setText(FormatBytes(stats->nodeStats.nSendBytes));
1033  ui->peerBytesRecv->setText(FormatBytes(stats->nodeStats.nRecvBytes));
1034  ui->peerConnTime->setText(GUIUtil::formatDurationStr(GetSystemTimeInSeconds() - stats->nodeStats.nTimeConnected));
1035  ui->peerPingTime->setText(GUIUtil::formatPingTime(stats->nodeStats.dPingTime));
1036  ui->peerPingWait->setText(GUIUtil::formatPingTime(stats->nodeStats.dPingWait));
1037  ui->peerMinPing->setText(GUIUtil::formatPingTime(stats->nodeStats.dMinPing));
1038  ui->timeoffset->setText(GUIUtil::formatTimeOffset(stats->nodeStats.nTimeOffset));
1039  ui->peerVersion->setText(QString("%1").arg(QString::number(stats->nodeStats.nVersion)));
1040  ui->peerSubversion->setText(QString::fromStdString(stats->nodeStats.cleanSubVer));
1041  ui->peerDirection->setText(stats->nodeStats.fInbound ? tr("Inbound") : tr("Outbound"));
1042  ui->peerHeight->setText(QString("%1").arg(QString::number(stats->nodeStats.nStartingHeight)));
1043  ui->peerWhitelisted->setText(stats->nodeStats.fWhitelisted ? tr("Yes") : tr("No"));
1044 
1045  // This check fails for example if the lock was busy and
1046  // nodeStateStats couldn't be fetched.
1047  if (stats->fNodeStateStatsAvailable) {
1048  // Ban score is init to 0
1049  ui->peerBanScore->setText(QString("%1").arg(stats->nodeStateStats.nMisbehavior));
1050 
1051  // Sync height is init to -1
1052  if (stats->nodeStateStats.nSyncHeight > -1)
1053  ui->peerSyncHeight->setText(QString("%1").arg(stats->nodeStateStats.nSyncHeight));
1054  else
1055  ui->peerSyncHeight->setText(tr("Unknown"));
1056 
1057  // Common height is init to -1
1058  if (stats->nodeStateStats.nCommonHeight > -1)
1059  ui->peerCommonHeight->setText(QString("%1").arg(stats->nodeStateStats.nCommonHeight));
1060  else
1061  ui->peerCommonHeight->setText(tr("Unknown"));
1062  }
1063 
1064  ui->detailWidget->show();
1065 }
1066 
1067 void RPCConsole::resizeEvent(QResizeEvent *event)
1068 {
1069  QWidget::resizeEvent(event);
1070 }
1071 
1072 void RPCConsole::showEvent(QShowEvent *event)
1073 {
1074  QWidget::showEvent(event);
1075 
1077  return;
1078 
1079  // start PeerTableModel auto refresh
1081 }
1082 
1083 void RPCConsole::hideEvent(QHideEvent *event)
1084 {
1085  QWidget::hideEvent(event);
1086 
1088  return;
1089 
1090  // stop PeerTableModel auto refresh
1092 }
1093 
1094 void RPCConsole::showPeersTableContextMenu(const QPoint& point)
1095 {
1096  QModelIndex index = ui->peerWidget->indexAt(point);
1097  if (index.isValid())
1098  peersTableContextMenu->exec(QCursor::pos());
1099 }
1100 
1101 void RPCConsole::showBanTableContextMenu(const QPoint& point)
1102 {
1103  QModelIndex index = ui->banlistWidget->indexAt(point);
1104  if (index.isValid())
1105  banTableContextMenu->exec(QCursor::pos());
1106 }
1107 
1109 {
1110  if(!g_connman)
1111  return;
1112 
1113  // Get selected peer addresses
1114  QList<QModelIndex> nodes = GUIUtil::getEntryData(ui->peerWidget, PeerTableModel::NetNodeId);
1115  for(int i = 0; i < nodes.count(); i++)
1116  {
1117  // Get currently selected peer address
1118  NodeId id = nodes.at(i).data().toLongLong();
1119  // Find the node, disconnect it and clear the selected node
1120  if(g_connman->DisconnectNode(id))
1122  }
1123 }
1124 
1126 {
1127  if (!clientModel || !g_connman)
1128  return;
1129 
1130  // Get selected peer addresses
1131  QList<QModelIndex> nodes = GUIUtil::getEntryData(ui->peerWidget, PeerTableModel::NetNodeId);
1132  for(int i = 0; i < nodes.count(); i++)
1133  {
1134  // Get currently selected peer address
1135  NodeId id = nodes.at(i).data().toLongLong();
1136 
1137  // Get currently selected peer address
1138  int detailNodeRow = clientModel->getPeerTableModel()->getRowByNodeId(id);
1139  if(detailNodeRow < 0)
1140  return;
1141 
1142  // Find possible nodes, ban it and clear the selected node
1143  const CNodeCombinedStats *stats = clientModel->getPeerTableModel()->getNodeStats(detailNodeRow);
1144  if(stats) {
1145  g_connman->Ban(stats->nodeStats.addr, BanReasonManuallyAdded, bantime);
1146  }
1147  }
1150 }
1151 
1153 {
1154  if (!clientModel)
1155  return;
1156 
1157  // Get selected ban addresses
1158  QList<QModelIndex> nodes = GUIUtil::getEntryData(ui->banlistWidget, BanTableModel::Address);
1159  for(int i = 0; i < nodes.count(); i++)
1160  {
1161  // Get currently selected ban address
1162  QString strNode = nodes.at(i).data().toString();
1163  CSubNet possibleSubnet;
1164 
1165  LookupSubNet(strNode.toStdString().c_str(), possibleSubnet);
1166  if (possibleSubnet.IsValid() && g_connman)
1167  {
1168  g_connman->Unban(possibleSubnet);
1170  }
1171  }
1172 }
1173 
1175 {
1176  ui->peerWidget->selectionModel()->clearSelection();
1177  cachedNodeids.clear();
1178  ui->detailWidget->hide();
1179  ui->peerHeading->setText(tr("Select a peer to view detailed information."));
1180 }
1181 
1183 {
1184  if (!clientModel)
1185  return;
1186 
1187  bool visible = clientModel->getBanTableModel()->shouldShow();
1188  ui->banlistWidget->setVisible(visible);
1189  ui->banHeading->setVisible(visible);
1190 }
1191 
1193 {
1194  ui->tabWidget->setCurrentIndex(tabType);
1195 }
@ BanReasonManuallyAdded
Definition: addrdb.h:23
const CChainParams & Params()
Return the currently selected parameters.
std::string addrLocal
Definition: net.h:511
double dPingWait
Definition: net.h:509
uint64_t nRecvBytes
Definition: net.h:505
std::string addrName
Definition: net.h:497
bool fInbound
Definition: net.h:500
bool fWhitelisted
Definition: net.h:507
uint64_t nSendBytes
Definition: net.h:503
int64_t nTimeConnected
Definition: net.h:495
double dPingTime
Definition: net.h:508
CAddress addr
Definition: net.h:512
int64_t nLastRecv
Definition: net.h:494
double dMinPing
Definition: net.h:510
ServiceFlags nServices
Definition: net.h:491
int nStartingHeight
Definition: net.h:502
int64_t nTimeOffset
Definition: net.h:496
int nVersion
Definition: net.h:498
NodeId nodeid
Definition: net.h:490
std::string cleanSubVer
Definition: net.h:499
int64_t nLastSend
Definition: net.h:493
std::vector< std::string > listCommands() const
Returns a list of registered commands.
Definition: server.cpp:512
UniValue execute(const JSONRPCRequest &request) const
Execute a method.
Definition: server.cpp:479
bool IsValid() const
Definition: netaddress.cpp:698
Model for Bitcoin network client.
Definition: clientmodel.h:42
quint64 getTotalBytesRecv() const
quint64 getTotalBytesSent() const
PeerTableModel * getPeerTableModel()
QDateTime getLastBlockDate() const
int getNumBlocks() const
Definition: clientmodel.cpp:74
double getVerificationProgress(const CBlockIndex *tip) const
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)
Definition: clientmodel.cpp:58
BanTableModel * getBanTableModel()
QString dataDir() const
QString formatFullVersion() const
QString formatSubVersion() const
UniValue params
Definition: server.h:52
std::string strMethod
Definition: server.h:51
const CNodeCombinedStats * getNodeStats(int idx)
int getRowByNodeId(NodeId nodeid)
QIcon SingleColorIcon(const QString &filename) const
Colorize an icon (given filename) with the icon color.
bool getImagesOnButtons() const
Definition: platformstyle.h:21
QImage SingleColorImage(const QString &filename) const
Colorize an image (given filename) with the icon color.
Class for handling RPC timers (used for e.g.
Definition: rpcconsole.cpp:98
boost::function< void(void)> func
Definition: rpcconsole.cpp:113
QtRPCTimerBase(boost::function< void(void)> &_func, int64_t millis)
Definition: rpcconsole.cpp:101
RPCTimerBase * NewTimer(boost::function< void(void)> &func, int64_t millis)
Factory function for timers.
Definition: rpcconsole.cpp:121
const char * Name()
Implementation name.
Definition: rpcconsole.cpp:120
Local Bitcoin RPC console.
Definition: rpcconsole.h:32
QMenu * peersTableContextMenu
Definition: rpcconsole.h:150
void updateNodeDetail(const CNodeCombinedStats *stats)
show detailed information on ui about selected node
void resizeEvent(QResizeEvent *event)
static bool RPCParseCommandLine(std::string &strResult, const std::string &strCommand, bool fExecute, std::string *const pstrFilteredOut=NULL)
Split shell command line into a list of arguments and optionally execute the command(s).
Definition: rpcconsole.cpp:149
void browseHistory(int offset)
Go forward or back in history.
Definition: rpcconsole.cpp:849
void peerSelected(const QItemSelection &selected, const QItemSelection &deselected)
Handle selection of peer in peers list.
Definition: rpcconsole.cpp:941
void fontSmaller()
Definition: rpcconsole.cpp:665
RPCTimerInterface * rpcTimerInterface
Definition: rpcconsole.h:149
void on_lineEdit_returnPressed()
Definition: rpcconsole.cpp:807
QStringList history
Definition: rpcconsole.h:144
void setClientModel(ClientModel *model)
Definition: rpcconsole.cpp:519
void setFontSize(int newSize)
Definition: rpcconsole.cpp:670
Ui::RPCConsole * ui
Definition: rpcconsole.h:142
void updateTrafficStats(quint64 totalBytesIn, quint64 totalBytesOut)
update traffic statistics
Definition: rpcconsole.cpp:935
void setTrafficGraphRange(int mins)
Definition: rpcconsole.cpp:929
void cmdRequest(const QString &command)
void updateNetworkState()
Update UI with latest network info from model.
Definition: rpcconsole.cpp:763
void disconnectSelectedNode()
Disconnect a selected node on the Peers tab.
@ BANTIME_COLUMN_WIDTH
Definition: rpcconsole.h:138
@ ADDRESS_COLUMN_WIDTH
Definition: rpcconsole.h:134
@ SUBVERSION_COLUMN_WIDTH
Definition: rpcconsole.h:135
@ PING_COLUMN_WIDTH
Definition: rpcconsole.h:136
@ BANSUBNET_COLUMN_WIDTH
Definition: rpcconsole.h:137
QCompleter * autoCompleter
Definition: rpcconsole.h:153
virtual bool eventFilter(QObject *obj, QEvent *event)
Definition: rpcconsole.cpp:475
void setMempoolSize(long numberOfTxs, size_t dynUsage)
Set size (number of transactions and memory usage) of the mempool in the UI.
Definition: rpcconsole.cpp:797
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:789
static bool RPCExecuteCommandLine(std::string &strResult, const std::string &strCommand, std::string *const pstrFilteredOut=NULL)
Definition: rpcconsole.h:40
void clear(bool clearHistory=true)
Definition: rpcconsole.cpp:695
void keyPressEvent(QKeyEvent *)
Definition: rpcconsole.cpp:739
RPCConsole(const PlatformStyle *platformStyle, QWidget *parent)
Definition: rpcconsole.cpp:413
void showPeersTableContextMenu(const QPoint &point)
Show custom context menu on Peers tab.
QList< NodeId > cachedNodeids
Definition: rpcconsole.h:147
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
Definition: rpcconsole.cpp:910
int consoleFontSize
Definition: rpcconsole.h:152
const PlatformStyle * platformStyle
Definition: rpcconsole.h:148
void stopExecutor()
void setNumConnections(int count)
Set number of connections shown in the UI.
Definition: rpcconsole.cpp:776
ClientModel * clientModel
Definition: rpcconsole.h:143
void banSelectedNode(int bantime)
Ban a selected node on the Peers tab.
int historyPtr
Definition: rpcconsole.h:145
void scrollToEnd()
Scroll console view to end.
Definition: rpcconsole.cpp:904
void hideEvent(QHideEvent *event)
void on_tabWidget_currentChanged(int index)
Definition: rpcconsole.cpp:891
void startExecutor()
Definition: rpcconsole.cpp:870
void setNetworkActive(bool networkActive)
Set network state shown in the UI.
Definition: rpcconsole.cpp:784
void fontBigger()
Definition: rpcconsole.cpp:660
QString cmdBeforeBrowsing
Definition: rpcconsole.h:146
void message(int category, const QString &message, bool html=false)
Append the message to the message widget.
Definition: rpcconsole.cpp:747
void on_openDebugLogfileButton_clicked()
open the debug.log from the current datadir
Definition: rpcconsole.cpp:899
void showBanTableContextMenu(const QPoint &point)
Show custom context menu on Bans tab.
void peerLayoutAboutToChange()
Handle selection caching before update.
Definition: rpcconsole.cpp:953
void setTabFocus(enum TabTypes tabType)
set which tab has the focus (is visible)
void showEvent(QShowEvent *event)
void showOrHideBanTableIfRequired()
Hides ban table if no bans are present.
QMenu * banTableContextMenu
Definition: rpcconsole.h:151
QThread thread
Definition: rpcconsole.h:154
void peerLayoutChanged()
Handle updated peer information.
Definition: rpcconsole.cpp:964
static QString FormatBytes(quint64 bytes)
Definition: rpcconsole.cpp:917
void reply(int category, const QString &command)
void request(const QString &command)
Definition: rpcconsole.cpp:381
Opaque base class for timers returned by NewTimerFunc.
Definition: server.h:100
RPC timer "driver".
Definition: server.h:109
const std::string & get_str() const
Definition: univalue.cpp:307
bool isArray() const
Definition: univalue.h:83
void clear()
Definition: univalue.cpp:80
std::string write(unsigned int prettyIndent=0, unsigned int indentLevel=0) const
bool isStr() const
Definition: univalue.h:81
bool push_back(const UniValue &val)
Definition: univalue.cpp:173
bool isObject() const
Definition: univalue.h:84
int get_int() const
Definition: univalue.cpp:314
UniValue RPCConvertValues(const std::string &strMethod, const std::vector< std::string > &strParams)
Convert positional arguments to command-specific RPC representation.
Definition: client.cpp:180
@ CONNECTIONS_IN
Definition: clientmodel.h:35
@ CONNECTIONS_OUT
Definition: clientmodel.h:36
std::unique_ptr< CConnman > g_connman
Definition: init.cpp:75
QString HtmlEscape(const QString &str, bool fMultiLine)
Definition: guiutil.cpp:255
QString formatPingTime(double dPingTime)
Definition: guiutil.cpp:939
void saveWindowGeometry(const QString &strSetting, QWidget *parent)
Save window size and position.
Definition: guiutil.cpp:829
QList< QModelIndex > getEntryData(QAbstractItemView *view, int column)
Return a field of the currently selected entry as a QString.
Definition: guiutil.cpp:287
void restoreWindowGeometry(const QString &strSetting, const QSize &defaultSize, QWidget *parent)
Restore window size and position.
Definition: guiutil.cpp:836
void openDebugLogfile()
Definition: guiutil.cpp:407
QString formatDurationStr(int secs)
Definition: guiutil.cpp:881
QString formatTimeOffset(int64_t nTimeOffset)
Definition: guiutil.cpp:944
QString formatServicesStr(quint64 mask)
Definition: guiutil.cpp:901
QFont fixedPitchFont()
Definition: guiutil.cpp:96
int64_t NodeId
Definition: net.h:96
bool LookupSubNet(const char *pszName, CSubNet &ret)
Definition: netbase.cpp:618
const int INITIAL_TRAFFIC_GRAPH_MINS
Definition: rpcconsole.cpp:52
const QSize FONT_RANGE(4, 40)
const struct @11 ICON_MAPPING[]
const int CONSOLE_HISTORY
Definition: rpcconsole.cpp:51
const char fontSizeSettingsKey[]
Definition: rpcconsole.cpp:54
const char * url
Definition: rpcconsole.cpp:57
const char * source
Definition: rpcconsole.cpp:58
void RPCSetTimerInterfaceIfUnset(RPCTimerInterface *iface)
Set the factory function for timer, but only, if unset.
Definition: server.cpp:535
void RPCUnsetTimerInterface(RPCTimerInterface *iface)
Unset factory function for timers.
Definition: server.cpp:546
CRPCTable tableRPC
Definition: server.cpp:569
CNodeStateStats nodeStateStats
CNodeStats nodeStats
const UniValue & find_value(const UniValue &obj, const std::string &name)
Definition: univalue.cpp:277
int atoi(const std::string &str)
int64_t GetSystemTimeInSeconds()
Definition: utiltime.cpp:49