@@ -84,12 +84,17 @@ const QStringList historyFilter = QStringList()
84
84
class RPCExecutor : public QObject
85
85
{
86
86
Q_OBJECT
87
+ public:
88
+ RPCExecutor (interface::Node& node) : m_node(node) {}
87
89
88
90
public Q_SLOTS:
89
91
void request (const QString &command, const QString &walletID);
90
92
91
93
Q_SIGNALS:
92
94
void reply (int category, const QString &command);
95
+
96
+ private:
97
+ interface::Node& m_node;
93
98
};
94
99
95
100
/* * Class for handling RPC timers
@@ -141,13 +146,14 @@ class QtRPCTimerInterface: public RPCTimerInterface
141
146
* - Within double quotes, only escape \c " and backslashes before a \c " or another backslash
142
147
* - Within single quotes, no escaping is possible and no special interpretation takes place
143
148
*
149
+ * @param[in] node optional node to execute command on
144
150
* @param[out] result stringified Result from the executed command(chain)
145
151
* @param[in] strCommand Command line to split
146
152
* @param[in] fExecute set true if you want the command to be executed
147
153
* @param[out] pstrFilteredOut Command line, filtered to remove any sensitive data
148
154
*/
149
155
150
- bool RPCConsole::RPCParseCommandLine (std::string &strResult, const std::string &strCommand, const bool fExecute , std::string * const pstrFilteredOut, const std::string *walletID)
156
+ bool RPCConsole::RPCParseCommandLine (interface::Node* node, std::string &strResult, const std::string &strCommand, const bool fExecute , std::string * const pstrFilteredOut, const std::string *walletID)
151
157
{
152
158
std::vector< std::vector<std::string> > stack;
153
159
stack.push_back (std::vector<std::string>());
@@ -301,16 +307,17 @@ bool RPCConsole::RPCParseCommandLine(std::string &strResult, const std::string &
301
307
if (fExecute ) {
302
308
// Convert argument list to JSON objects in method-dependent way,
303
309
// and pass it along with the method name to the dispatcher.
304
- JSONRPCRequest req ;
305
- req. params = RPCConvertValues (stack. back ()[ 0 ], std::vector<std:: string>(stack. back (). begin () + 1 , stack.back (). end ())) ;
306
- req. strMethod = stack. back ()[ 0 ] ;
310
+ UniValue params = RPCConvertValues (stack. back ()[ 0 ], std::vector<std::string>(stack. back (). begin () + 1 , stack. back (). end ())) ;
311
+ std::string method = stack.back ()[ 0 ] ;
312
+ std::string uri ;
307
313
#ifdef ENABLE_WALLET
308
314
if (walletID && !walletID->empty ()) {
309
315
QByteArray encodedName = QUrl::toPercentEncoding (QString::fromStdString (*walletID));
310
- req. URI = " /wallet/" +std::string (encodedName.constData (), encodedName.length ());
316
+ uri = " /wallet/" +std::string (encodedName.constData (), encodedName.length ());
311
317
}
312
318
#endif
313
- lastResult = tableRPC.execute (req);
319
+ assert (node);
320
+ lastResult = node->executeRpc (method, params, uri);
314
321
}
315
322
316
323
state = STATE_COMMAND_EXECUTED;
@@ -417,7 +424,7 @@ void RPCExecutor::request(const QString &command, const QString &walletID)
417
424
return ;
418
425
}
419
426
std::string wallet_id = walletID.toStdString ();
420
- if (!RPCConsole::RPCExecuteCommandLine (result, executableCommand, nullptr , &wallet_id))
427
+ if (!RPCConsole::RPCExecuteCommandLine (m_node, result, executableCommand, nullptr , &wallet_id))
421
428
{
422
429
Q_EMIT reply (RPCConsole::CMD_ERROR, QString (" Parse error: unbalanced ' or \" " ));
423
430
return ;
@@ -444,8 +451,9 @@ void RPCExecutor::request(const QString &command, const QString &walletID)
444
451
}
445
452
}
446
453
447
- RPCConsole::RPCConsole (const PlatformStyle *_platformStyle, QWidget *parent) :
454
+ RPCConsole::RPCConsole (interface::Node& node, const PlatformStyle *_platformStyle, QWidget *parent) :
448
455
QWidget(parent),
456
+ m_node(node),
449
457
ui(new Ui::RPCConsole),
450
458
clientModel(0 ),
451
459
historyPtr(0 ),
@@ -494,7 +502,7 @@ RPCConsole::RPCConsole(const PlatformStyle *_platformStyle, QWidget *parent) :
494
502
rpcTimerInterface = new QtRPCTimerInterface ();
495
503
// avoid accidentally overwriting an existing, non QTThread
496
504
// based timer interface
497
- RPCSetTimerInterfaceIfUnset (rpcTimerInterface);
505
+ m_node. rpcSetTimerInterfaceIfUnset (rpcTimerInterface);
498
506
499
507
setTrafficGraphRange (INITIAL_TRAFFIC_GRAPH_MINS);
500
508
@@ -509,7 +517,7 @@ RPCConsole::~RPCConsole()
509
517
{
510
518
QSettings settings;
511
519
settings.setValue (" RPCConsoleWindowGeometry" , saveGeometry ());
512
- RPCUnsetTimerInterface (rpcTimerInterface);
520
+ m_node. rpcUnsetTimerInterface (rpcTimerInterface);
513
521
delete rpcTimerInterface;
514
522
delete ui;
515
523
}
@@ -669,7 +677,7 @@ void RPCConsole::setClientModel(ClientModel *model)
669
677
670
678
// Setup autocomplete and attach it
671
679
QStringList wordList;
672
- std::vector<std::string> commandList = tableRPC. listCommands ();
680
+ std::vector<std::string> commandList = m_node. listRpcCommands ();
673
681
for (size_t i = 0 ; i < commandList.size (); ++i)
674
682
{
675
683
wordList << commandList[i].c_str ();
@@ -884,7 +892,7 @@ void RPCConsole::on_lineEdit_returnPressed()
884
892
std::string strFilteredCmd;
885
893
try {
886
894
std::string dummy;
887
- if (!RPCParseCommandLine (dummy, cmd.toStdString (), false , &strFilteredCmd)) {
895
+ if (!RPCParseCommandLine (nullptr , dummy, cmd.toStdString (), false , &strFilteredCmd)) {
888
896
// Failed to parse command, so we cannot even filter it for the history
889
897
throw std::runtime_error (" Invalid command line" );
890
898
}
@@ -957,7 +965,7 @@ void RPCConsole::browseHistory(int offset)
957
965
958
966
void RPCConsole::startExecutor ()
959
967
{
960
- RPCExecutor *executor = new RPCExecutor ();
968
+ RPCExecutor *executor = new RPCExecutor (m_node );
961
969
executor->moveToThread (&thread);
962
970
963
971
// Replies from executor object must go to this object
@@ -1183,24 +1191,21 @@ void RPCConsole::showBanTableContextMenu(const QPoint& point)
1183
1191
1184
1192
void RPCConsole::disconnectSelectedNode ()
1185
1193
{
1186
- if (!g_connman)
1187
- return ;
1188
-
1189
1194
// Get selected peer addresses
1190
1195
QList<QModelIndex> nodes = GUIUtil::getEntryData (ui->peerWidget , PeerTableModel::NetNodeId);
1191
1196
for (int i = 0 ; i < nodes.count (); i++)
1192
1197
{
1193
1198
// Get currently selected peer address
1194
1199
NodeId id = nodes.at (i).data ().toLongLong ();
1195
1200
// Find the node, disconnect it and clear the selected node
1196
- if (g_connman-> DisconnectNode (id))
1201
+ if (m_node. disconnect (id))
1197
1202
clearSelectedNode ();
1198
1203
}
1199
1204
}
1200
1205
1201
1206
void RPCConsole::banSelectedNode (int bantime)
1202
1207
{
1203
- if (!clientModel || !g_connman )
1208
+ if (!clientModel)
1204
1209
return ;
1205
1210
1206
1211
// Get selected peer addresses
@@ -1218,7 +1223,7 @@ void RPCConsole::banSelectedNode(int bantime)
1218
1223
// Find possible nodes, ban it and clear the selected node
1219
1224
const CNodeCombinedStats *stats = clientModel->getPeerTableModel ()->getNodeStats (detailNodeRow);
1220
1225
if (stats) {
1221
- g_connman-> Ban (stats->nodeStats .addr , BanReasonManuallyAdded, bantime);
1226
+ m_node. ban (stats->nodeStats .addr , BanReasonManuallyAdded, bantime);
1222
1227
}
1223
1228
}
1224
1229
clearSelectedNode ();
@@ -1239,9 +1244,8 @@ void RPCConsole::unbanSelectedNode()
1239
1244
CSubNet possibleSubnet;
1240
1245
1241
1246
LookupSubNet (strNode.toStdString ().c_str (), possibleSubnet);
1242
- if (possibleSubnet.IsValid () && g_connman )
1247
+ if (possibleSubnet.IsValid () && m_node. unban (possibleSubnet) )
1243
1248
{
1244
- g_connman->Unban (possibleSubnet);
1245
1249
clientModel->getBanTableModel ()->refresh ();
1246
1250
}
1247
1251
}
0 commit comments