14 #include "json/json_spirit_value.h"
15 #include <openssl/crypto.h>
21 #if QT_VERSION < 0x050000
38 {
"cmd-request",
":/icons/tx_input"},
39 {
"cmd-reply",
":/icons/tx_output"},
40 {
"cmd-error",
":/icons/tx_output"},
41 {
"misc",
":/icons/tx_inout"},
52 void request(
const QString &command);
55 void reply(
int category,
const QString &command);
58 #include "rpcconsole.moc"
83 STATE_ESCAPE_DOUBLEQUOTED
84 } state = STATE_EATING_SPACES;
86 foreach(
char ch, strCommand)
91 case STATE_EATING_SPACES:
94 case '"': state = STATE_DOUBLEQUOTED;
break;
95 case '\'': state = STATE_SINGLEQUOTED;
break;
96 case '\\': state = STATE_ESCAPE_OUTER;
break;
97 case ' ':
case '\n':
case '\t':
98 if(state == STATE_ARGUMENT)
100 args.push_back(curarg);
103 state = STATE_EATING_SPACES;
105 default: curarg += ch; state = STATE_ARGUMENT;
108 case STATE_SINGLEQUOTED:
111 case '\'': state = STATE_ARGUMENT;
break;
112 default: curarg += ch;
115 case STATE_DOUBLEQUOTED:
118 case '"': state = STATE_ARGUMENT;
break;
119 case '\\': state = STATE_ESCAPE_DOUBLEQUOTED;
break;
120 default: curarg += ch;
123 case STATE_ESCAPE_OUTER:
124 curarg += ch; state = STATE_ARGUMENT;
126 case STATE_ESCAPE_DOUBLEQUOTED:
127 if(ch !=
'"' && ch !=
'\\') curarg +=
'\\';
128 curarg += ch; state = STATE_DOUBLEQUOTED;
134 case STATE_EATING_SPACES:
137 args.push_back(curarg);
146 std::vector<std::string> args;
156 std::string strPrint;
161 RPCConvertValues(args[0], std::vector<std::string>(args.begin() + 1, args.end())));
164 if (result.type() == json_spirit::null_type)
166 else if (result.type() == json_spirit::str_type)
167 strPrint = result.get_str();
169 strPrint = write_string(result,
true);
173 catch (json_spirit::Object& objError)
177 int code = find_value(objError,
"code").get_int();
178 std::string message = find_value(objError,
"message").get_str();
181 catch(std::runtime_error &)
186 catch (std::exception& e)
230 if(event->type() == QEvent::KeyPress)
232 QKeyEvent *keyevt =
static_cast<QKeyEvent*
>(event);
233 int key = keyevt->key();
234 Qt::KeyboardModifiers mod = keyevt->modifiers();
240 case Qt::Key_PageDown:
251 (!mod && !keyevt->text().isEmpty() && key != Qt::Key_Tab) ||
252 ((mod & Qt::ControlModifier) && key == Qt::Key_V) ||
253 ((mod & Qt::ShiftModifier) && key == Qt::Key_Insert)))
256 QApplication::postEvent(
ui->
lineEdit,
new QKeyEvent(*keyevt));
261 return QDialog::eventFilter(obj, event);
272 connect(model, SIGNAL(numConnectionsChanged(
int)),
this, SLOT(
setNumConnections(
int)));
275 connect(model, SIGNAL(numBlocksChanged(
int)),
this, SLOT(
setNumBlocks(
int)));
278 connect(model, SIGNAL(bytesChanged(quint64,quint64)),
this, SLOT(
updateTrafficStats(quint64, quint64)));
297 default:
return "misc";
314 QTextDocument::ImageResource,
322 "td.time { color: #808080; padding-top: 3px; } "
323 "td.message { font-family: monospace; font-size: 12px; } "
324 "td.cmd-request { color: #006060; } "
325 "td.cmd-error { color: red; } "
326 "b { color: #006060; } "
330 tr(
"Use up and down arrows to navigate history, and <b>Ctrl-L</b> to clear screen.") +
"<br>" +
331 tr(
"Type <b>help</b> for an overview of available commands.")),
true);
337 if(windowType() != Qt::Widget)
343 QTime time = QTime::currentTime();
344 QString timeString = time.toString();
346 out +=
"<table><tr><td class=\"time\" width=\"65\">" + timeString +
"</td>";
347 out +=
"<td class=\"icon\" width=\"32\"><img src=\"" +
categoryClass(category) +
"\"></td>";
348 out +=
"<td class=\"message " +
categoryClass(category) +
"\" valign=\"middle\">";
353 out +=
"</td></tr></table>";
362 QString connections = QString::number(count) +
" (";
414 QThread *thread =
new QThread;
416 executor->moveToThread(thread);
419 connect(executor, SIGNAL(reply(
int,QString)),
this, SLOT(
message(
int,QString)));
421 connect(
this, SIGNAL(
cmdRequest(QString)), executor, SLOT(request(QString)));
426 connect(
this, SIGNAL(
stopExecutor()), executor, SLOT(deleteLater()));
427 connect(
this, SIGNAL(
stopExecutor()), thread, SLOT(quit()));
429 connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
452 scrollbar->setValue(scrollbar->maximum());
457 const int multiplier = 5;
458 int mins = value * multiplier;
465 return QString(tr(
"%1 B")).arg(bytes);
466 if(bytes < 1024 * 1024)
467 return QString(tr(
"%1 KB")).arg(bytes / 1024);
468 if(bytes < 1024 * 1024 * 1024)
469 return QString(tr(
"%1 MB")).arg(bytes / 1024 / 1024);
471 return QString(tr(
"%1 GB")).arg(bytes / 1024 / 1024 / 1024);
480 int hours = mins / 60;
481 int minsLeft = mins % 60;
485 ui->
lblGraphRange->setText(QString(tr(
"%1 h %2 m")).arg(hours).arg(minsLeft));
Local Bitcoin RPC console.
static QString FormatBytes(quint64 bytes)
QPushButton * openDebugLogfileButton
void on_lineEdit_returnPressed()
QLabel * numberOfConnections
void message(int category, const QString &message, bool html=false)
quint64 getTotalBytesRecv() const
bool parseCommandLine(std::vector< std::string > &args, const std::string &strCommand)
Split shell command line into a list of arguments.
QTextEdit * messagesWidget
int getNumConnections(unsigned int flags=CONNECTIONS_ALL) const
Return number of connections, default is in- and outbound (total)
void scrollToEnd()
Scroll console view to end.
json_spirit::Value execute(const std::string &method, const json_spirit::Array ¶ms) const
Execute a method.
static QString categoryClass(int category)
QString HtmlEscape(const QString &str, bool fMultiLine)
const struct @5 ICON_MAPPING[]
QString formatClientStartupTime() const
void setupUi(QDialog *RPCConsole)
void on_tabWidget_currentChanged(int index)
void saveWindowGeometry(const QString &strSetting, QWidget *parent)
Save window size and position.
QPushButton * btnClearTrafficGraph
QString getNetworkName() const
Return network (main, testnet3, regtest)
void setClientModel(ClientModel *model)
void reply(int category, const QString &command)
void browseHistory(int offset)
Go forward or back in history.
const QSize ICON_SIZE(24, 24)
const int CONSOLE_HISTORY
QDateTime getLastBlockDate() const
QPushButton * clearButton
void request(const QString &command)
QString clientName() const
QString formatBuildDate() const
void on_openDebugLogfileButton_clicked()
open the debug.log from the current datadir
void restoreWindowGeometry(const QString &strSetting, const QSize &defaultSize, QWidget *parent)
Restore window size and position.
Model for Bitcoin network client.
ClientModel * clientModel
TrafficGraphWidget * trafficGraph
virtual bool eventFilter(QObject *obj, QEvent *event)
void setTrafficGraphRange(int mins)
quint64 getTotalBytesSent() const
RPCConsole(QWidget *parent)
void updateTrafficStats(quint64 totalBytesIn, quint64 totalBytesOut)
update traffic statistics
void setNumConnections(int count)
Set number of connections shown in the UI.
void on_sldGraphRange_valueChanged(int value)
change the time range of the network traffic graph
const int INITIAL_TRAFFIC_GRAPH_MINS
void setNumBlocks(int count)
Set number of blocks shown in the UI.
QString formatFullVersion() const
void cmdRequest(const QString &command)
Array RPCConvertValues(const std::string &strMethod, const std::vector< std::string > &strParams)