2019-01-04 09:17:53 -03:00
|
|
|
// Copyright (c) 2011-2019 The Bitcoin Core developers
|
2014-12-13 01:09:33 -03:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
2013-11-04 12:20:43 -03:00
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
2014-11-03 12:16:40 -03:00
|
|
|
#ifndef BITCOIN_QT_RPCCONSOLE_H
|
|
|
|
#define BITCOIN_QT_RPCCONSOLE_H
|
2012-04-09 16:07:25 -03:00
|
|
|
|
2017-11-09 21:57:53 -03:00
|
|
|
#include <qt/guiutil.h>
|
|
|
|
#include <qt/peertablemodel.h>
|
2014-05-23 13:09:59 -04:00
|
|
|
|
2017-11-09 21:57:53 -03:00
|
|
|
#include <net.h>
|
2014-06-03 08:42:20 -04:00
|
|
|
|
2014-11-10 12:41:57 -03:00
|
|
|
#include <QWidget>
|
2016-02-27 00:57:12 -03:00
|
|
|
#include <QCompleter>
|
2016-11-18 12:35:14 -03:00
|
|
|
#include <QThread>
|
2012-04-09 16:07:25 -03:00
|
|
|
|
2013-04-13 02:13:08 -03:00
|
|
|
class ClientModel;
|
2015-07-28 10:20:14 -03:00
|
|
|
class PlatformStyle;
|
2015-08-28 11:46:20 -03:00
|
|
|
class RPCTimerInterface;
|
2016-09-09 17:55:59 -03:00
|
|
|
class WalletModel;
|
2013-04-13 02:13:08 -03:00
|
|
|
|
2018-04-07 04:42:02 -03:00
|
|
|
namespace interfaces {
|
2017-04-17 17:38:51 -03:00
|
|
|
class Node;
|
|
|
|
}
|
|
|
|
|
2012-04-09 16:07:25 -03:00
|
|
|
namespace Ui {
|
|
|
|
class RPCConsole;
|
|
|
|
}
|
|
|
|
|
2014-09-05 07:18:35 -04:00
|
|
|
QT_BEGIN_NAMESPACE
|
2015-06-01 10:32:25 -03:00
|
|
|
class QMenu;
|
2014-09-05 07:18:35 -04:00
|
|
|
class QItemSelection;
|
|
|
|
QT_END_NAMESPACE
|
|
|
|
|
2012-05-13 10:09:14 -04:00
|
|
|
/** Local Bitcoin RPC console. */
|
2014-11-10 12:41:57 -03:00
|
|
|
class RPCConsole: public QWidget
|
2012-04-09 16:07:25 -03:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2018-04-07 04:42:02 -03:00
|
|
|
explicit RPCConsole(interfaces::Node& node, const PlatformStyle *platformStyle, QWidget *parent);
|
2012-04-09 16:07:25 -03:00
|
|
|
~RPCConsole();
|
|
|
|
|
2019-01-04 09:17:53 -03:00
|
|
|
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);
|
|
|
|
static bool RPCExecuteCommandLine(interfaces::Node& node, std::string &strResult, const std::string &strCommand, std::string * const pstrFilteredOut = nullptr, const WalletModel* wallet_model = nullptr) {
|
|
|
|
return RPCParseCommandLine(&node, strResult, strCommand, true, pstrFilteredOut, wallet_model);
|
2016-11-16 07:56:32 -03:00
|
|
|
}
|
2016-08-20 06:19:35 -03:00
|
|
|
|
2020-05-19 09:11:45 -04:00
|
|
|
void setClientModel(ClientModel *model = nullptr, int bestblock_height = 0, int64_t bestblock_date = 0, double verification_progress = 0.0);
|
2017-10-12 04:22:48 -03:00
|
|
|
void addWallet(WalletModel * const walletModel);
|
2018-06-05 06:17:28 -04:00
|
|
|
void removeWallet(WalletModel* const walletModel);
|
2012-04-09 16:07:25 -03:00
|
|
|
|
|
|
|
enum MessageClass {
|
|
|
|
MC_ERROR,
|
|
|
|
MC_DEBUG,
|
|
|
|
CMD_REQUEST,
|
|
|
|
CMD_REPLY,
|
|
|
|
CMD_ERROR
|
|
|
|
};
|
|
|
|
|
2019-10-10 21:50:49 -03:00
|
|
|
enum class TabTypes {
|
|
|
|
INFO,
|
|
|
|
CONSOLE,
|
|
|
|
GRAPH,
|
|
|
|
PEERS
|
2015-11-12 08:59:26 -03:00
|
|
|
};
|
|
|
|
|
2019-10-10 21:50:49 -03:00
|
|
|
std::vector<TabTypes> tabs() const { return {TabTypes::INFO, TabTypes::CONSOLE, TabTypes::GRAPH, TabTypes::PEERS}; }
|
2018-12-11 10:13:48 -03:00
|
|
|
|
|
|
|
QString tabTitle(TabTypes tab_type) const;
|
2019-04-05 12:20:57 -03:00
|
|
|
QKeySequence tabShortcut(TabTypes tab_type) const;
|
2018-12-11 10:13:48 -03:00
|
|
|
|
2012-04-09 16:07:25 -03:00
|
|
|
protected:
|
2020-03-14 03:49:59 -03:00
|
|
|
virtual bool eventFilter(QObject* obj, QEvent *event) override;
|
|
|
|
void keyPressEvent(QKeyEvent *) override;
|
2012-04-09 16:07:25 -03:00
|
|
|
|
2015-07-14 08:59:05 -03:00
|
|
|
private Q_SLOTS:
|
2012-04-09 16:07:25 -03:00
|
|
|
void on_lineEdit_returnPressed();
|
2012-05-09 11:12:05 -04:00
|
|
|
void on_tabWidget_currentChanged(int index);
|
2012-05-18 08:11:55 -04:00
|
|
|
/** open the debug.log from the current datadir */
|
2012-05-09 16:07:00 -04:00
|
|
|
void on_openDebugLogfileButton_clicked();
|
2013-08-22 12:09:32 -04:00
|
|
|
/** change the time range of the network traffic graph */
|
|
|
|
void on_sldGraphRange_valueChanged(int value);
|
|
|
|
/** update traffic statistics */
|
|
|
|
void updateTrafficStats(quint64 totalBytesIn, quint64 totalBytesOut);
|
2020-03-14 03:49:59 -03:00
|
|
|
void resizeEvent(QResizeEvent *event) override;
|
|
|
|
void showEvent(QShowEvent *event) override;
|
|
|
|
void hideEvent(QHideEvent *event) override;
|
2015-06-01 10:32:25 -03:00
|
|
|
/** Show custom context menu on Peers tab */
|
2015-06-20 15:55:21 -03:00
|
|
|
void showPeersTableContextMenu(const QPoint& point);
|
|
|
|
/** Show custom context menu on Bans tab */
|
|
|
|
void showBanTableContextMenu(const QPoint& point);
|
2015-06-20 16:48:10 -03:00
|
|
|
/** Hides ban table if no bans are present */
|
|
|
|
void showOrHideBanTableIfRequired();
|
2015-06-26 05:23:51 -03:00
|
|
|
/** clear the selected node */
|
|
|
|
void clearSelectedNode();
|
2012-05-09 11:12:05 -04:00
|
|
|
|
2015-07-14 08:59:05 -03:00
|
|
|
public Q_SLOTS:
|
2016-03-11 13:57:10 -03:00
|
|
|
void clear(bool clearHistory = true);
|
2016-01-22 14:00:36 -03:00
|
|
|
void fontBigger();
|
|
|
|
void fontSmaller();
|
|
|
|
void setFontSize(int newSize);
|
2015-10-22 08:33:58 -03:00
|
|
|
/** Append the message to the message widget */
|
2018-06-24 11:18:22 -04:00
|
|
|
void message(int category, const QString &msg) { message(category, msg, false); }
|
|
|
|
void message(int category, const QString &message, bool html);
|
2012-04-09 16:07:25 -03:00
|
|
|
/** Set number of connections shown in the UI */
|
|
|
|
void setNumConnections(int count);
|
2013-03-25 23:07:06 -03:00
|
|
|
/** Set network state shown in the UI */
|
|
|
|
void setNetworkActive(bool networkActive);
|
2015-02-09 07:19:01 -03:00
|
|
|
/** Set number of blocks and last block date shown in the UI */
|
2016-04-28 11:18:45 -03:00
|
|
|
void setNumBlocks(int count, const QDateTime& blockDate, double nVerificationProgress, bool headers);
|
2015-11-09 07:45:07 -03:00
|
|
|
/** Set size (number of transactions and memory usage) of the mempool in the UI */
|
|
|
|
void setMempoolSize(long numberOfTxs, size_t dynUsage);
|
2012-04-09 16:07:25 -03:00
|
|
|
/** Go forward or back in history */
|
|
|
|
void browseHistory(int offset);
|
2012-05-14 12:17:12 -04:00
|
|
|
/** Scroll console view to end */
|
|
|
|
void scrollToEnd();
|
2014-05-23 13:09:59 -04:00
|
|
|
/** Handle selection of peer in peers list */
|
|
|
|
void peerSelected(const QItemSelection &selected, const QItemSelection &deselected);
|
2016-11-08 12:41:23 -03:00
|
|
|
/** Handle selection caching before update */
|
|
|
|
void peerLayoutAboutToChange();
|
2014-05-23 13:09:59 -04:00
|
|
|
/** Handle updated peer information */
|
|
|
|
void peerLayoutChanged();
|
2015-06-06 05:38:15 -03:00
|
|
|
/** Disconnect a selected node on the Peers tab */
|
2015-06-01 10:32:25 -03:00
|
|
|
void disconnectSelectedNode();
|
2015-06-19 08:24:34 -03:00
|
|
|
/** Ban a selected node on the Peers tab */
|
|
|
|
void banSelectedNode(int bantime);
|
2015-06-20 15:55:21 -03:00
|
|
|
/** Unban a selected node on the Bans tab */
|
|
|
|
void unbanSelectedNode();
|
2015-11-12 08:59:26 -03:00
|
|
|
/** set which tab has the focus (is visible) */
|
|
|
|
void setTabFocus(enum TabTypes tabType);
|
2013-11-08 04:13:08 -03:00
|
|
|
|
2015-07-14 08:59:05 -03:00
|
|
|
Q_SIGNALS:
|
2012-04-09 16:07:25 -03:00
|
|
|
// For RPC command executor
|
2019-01-04 09:17:53 -03:00
|
|
|
void cmdRequest(const QString &command, const WalletModel* wallet_model);
|
2012-04-09 16:07:25 -03:00
|
|
|
|
|
|
|
private:
|
2014-06-04 06:06:18 -04:00
|
|
|
void startExecutor();
|
2013-08-22 12:09:32 -04:00
|
|
|
void setTrafficGraphRange(int mins);
|
2014-06-04 06:06:18 -04:00
|
|
|
/** show detailed information on ui about selected node */
|
|
|
|
void updateNodeDetail(const CNodeCombinedStats *stats);
|
|
|
|
|
|
|
|
enum ColumnWidths
|
|
|
|
{
|
|
|
|
ADDRESS_COLUMN_WIDTH = 200,
|
2016-01-20 19:02:24 -03:00
|
|
|
SUBVERSION_COLUMN_WIDTH = 150,
|
2015-06-20 16:48:10 -03:00
|
|
|
PING_COLUMN_WIDTH = 80,
|
2015-06-26 09:55:52 -03:00
|
|
|
BANSUBNET_COLUMN_WIDTH = 200,
|
|
|
|
BANTIME_COLUMN_WIDTH = 250
|
2015-06-20 16:48:10 -03:00
|
|
|
|
2014-06-04 06:06:18 -04:00
|
|
|
};
|
2013-08-22 12:09:32 -04:00
|
|
|
|
2018-04-07 04:42:02 -03:00
|
|
|
interfaces::Node& m_node;
|
2018-05-02 08:56:20 -03:00
|
|
|
Ui::RPCConsole* const ui;
|
2018-04-09 20:23:24 -03:00
|
|
|
ClientModel *clientModel = nullptr;
|
2012-04-09 16:07:25 -03:00
|
|
|
QStringList history;
|
2018-04-09 20:23:24 -03:00
|
|
|
int historyPtr = 0;
|
2015-03-13 17:51:27 -03:00
|
|
|
QString cmdBeforeBrowsing;
|
2016-11-08 12:41:23 -03:00
|
|
|
QList<NodeId> cachedNodeids;
|
2018-05-02 08:56:20 -03:00
|
|
|
const PlatformStyle* const platformStyle;
|
2018-04-09 20:23:24 -03:00
|
|
|
RPCTimerInterface *rpcTimerInterface = nullptr;
|
|
|
|
QMenu *peersTableContextMenu = nullptr;
|
|
|
|
QMenu *banTableContextMenu = nullptr;
|
|
|
|
int consoleFontSize = 0;
|
2018-04-09 20:08:02 -03:00
|
|
|
QCompleter *autoCompleter = nullptr;
|
2016-11-18 12:35:14 -03:00
|
|
|
QThread thread;
|
2019-01-04 09:17:53 -03:00
|
|
|
WalletModel* m_last_wallet_model{nullptr};
|
2013-03-25 23:07:06 -03:00
|
|
|
|
|
|
|
/** Update UI with latest network info from model. */
|
|
|
|
void updateNetworkState();
|
2018-12-05 17:51:49 -03:00
|
|
|
|
|
|
|
private Q_SLOTS:
|
|
|
|
void updateAlerts(const QString& warnings);
|
2012-04-09 16:07:25 -03:00
|
|
|
};
|
|
|
|
|
2014-11-03 12:16:40 -03:00
|
|
|
#endif // BITCOIN_QT_RPCCONSOLE_H
|