mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-09-14 20:09:19 +02:00
gui: Show error if unrecognized command line args are present
Starting bitcoin-qt with non-dash ("-") arguments causes it to silently ignore any later valid options. This change makes the client exit with an error message if any such "loose" arguments are encountered. However, allow BIP-21 'bitcoin:' URIs only if no other options follow.
This commit is contained in:
@@ -543,6 +543,34 @@ int GuiMain(int argc, char* argv[])
|
|||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Error out when loose non-argument tokens are encountered on command line
|
||||||
|
// However, allow BIP-21 URIs only if no options follow
|
||||||
|
bool payment_server_token_seen = false;
|
||||||
|
for (int i = 1; i < argc; i++) {
|
||||||
|
QString arg(argv[i]);
|
||||||
|
bool invalid_token = !arg.startsWith("-");
|
||||||
|
#ifdef ENABLE_WALLET
|
||||||
|
if (arg.startsWith(BITCOIN_IPC_PREFIX, Qt::CaseInsensitive)) {
|
||||||
|
invalid_token &= false;
|
||||||
|
payment_server_token_seen = true;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
if (payment_server_token_seen && arg.startsWith("-")) {
|
||||||
|
InitError(Untranslated(strprintf("Options ('%s') cannot follow a BIP-21 payment URI", argv[i])));
|
||||||
|
QMessageBox::critical(nullptr, PACKAGE_NAME,
|
||||||
|
// message cannot be translated because translations have not been initialized
|
||||||
|
QString::fromStdString("Options ('%1') cannot follow a BIP-21 payment URI").arg(QString::fromStdString(argv[i])));
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
if (invalid_token) {
|
||||||
|
InitError(Untranslated(strprintf("Command line contains unexpected token '%s', see bitcoin-qt -h for a list of options.", argv[i])));
|
||||||
|
QMessageBox::critical(nullptr, PACKAGE_NAME,
|
||||||
|
// message cannot be translated because translations have not been initialized
|
||||||
|
QString::fromStdString("Command line contains unexpected token '%1', see bitcoin-qt -h for a list of options.").arg(QString::fromStdString(argv[i])));
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Now that the QApplication is setup and we have parsed our parameters, we can set the platform style
|
// Now that the QApplication is setup and we have parsed our parameters, we can set the platform style
|
||||||
app.setupPlatformStyle();
|
app.setupPlatformStyle();
|
||||||
|
|
||||||
|
@@ -54,6 +54,8 @@ class QLocalServer;
|
|||||||
class QUrl;
|
class QUrl;
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
|
extern const QString BITCOIN_IPC_PREFIX;
|
||||||
|
|
||||||
class PaymentServer : public QObject
|
class PaymentServer : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
Reference in New Issue
Block a user