diff --git a/src/qt/paymentserver.cpp b/src/qt/paymentserver.cpp --- a/src/qt/paymentserver.cpp +++ b/src/qt/paymentserver.cpp @@ -214,6 +214,37 @@ } // ns anon +static bool ipcParseURI(const QString &arg) { + + std::vector networks = {CBaseChainParams::MAIN, + CBaseChainParams::TESTNET, + CBaseChainParams::REGTEST}; + + for (std::string net : networks) { + const CChainParams ¶ms(Params(net)); + SchemeCfgDummy cfg(params); + const QString scheme = GUIUtil::bitcoinURIScheme(cfg); + + if (!arg.startsWith(scheme + ":", Qt::CaseInsensitive)) { + continue; + } + + SendCoinsRecipient r; + if (!GUIUtil::parseBitcoinURI(scheme, arg, &r)) { + return false; + } + + if (!IsValidDestinationString(r.address.toStdString(), params)) { + return false; + } + + savedPaymentRequests.append(arg); + SelectParams(net); + return true; + } + return false; +} + // // Sending to the server is done synchronously, at startup. // If the server isn't already running, startup continues, and the items in @@ -227,31 +258,11 @@ QString arg(argv[i]); if (arg.startsWith("-")) continue; - SchemeCfgDummy cfg(Params(CBaseChainParams::MAIN)); - QString scheme = GUIUtil::bitcoinURIScheme(cfg); - // If the bitcoincash: URI contains a payment request, we are not able - // to detect the network as that would require fetching and parsing the - // payment request. That means clicking such an URI which contains a - // testnet payment request will start a mainnet instance and throw a - // "wrong network" error. - if (arg.startsWith(scheme + ":", - Qt::CaseInsensitive)) // bitcoincash: URI - { - savedPaymentRequests.append(arg); + if (ipcParseURI(arg)) { + continue; + } - SendCoinsRecipient r; - if (GUIUtil::parseBitcoinURI(scheme, arg, &r) && - !r.address.isEmpty()) { - if (IsValidDestinationString(r.address.toStdString(), - Params(CBaseChainParams::MAIN))) { - SelectParams(CBaseChainParams::MAIN); - } else if (IsValidDestinationString( - r.address.toStdString(), - Params(CBaseChainParams::TESTNET))) { - SelectParams(CBaseChainParams::TESTNET); - } - } - } else if (QFile::exists(arg)) { + if (QFile::exists(arg)) { // Filename savedPaymentRequests.append(arg);