Changeset View
Changeset View
Standalone View
Standalone View
src/qt/paymentserver.cpp
Show First 20 Lines • Show All 208 Lines • ▼ Show 20 Lines | public: | ||||
const CChainParams &GetChainParams() const override { return params; } | const CChainParams &GetChainParams() const override { return params; } | ||||
private: | private: | ||||
const CChainParams ¶ms; | const CChainParams ¶ms; | ||||
}; | }; | ||||
} // ns anon | } // ns anon | ||||
static bool ipcParseURI(const QString &arg) { | |||||
std::vector<std::string> 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); | |||||
deadalnix: Putting that here makes it is very dangerous function to use in general. I would extract the… | |||||
return true; | |||||
} | |||||
return false; | |||||
} | |||||
// | // | ||||
// Sending to the server is done synchronously, at startup. | // Sending to the server is done synchronously, at startup. | ||||
// If the server isn't already running, startup continues, and the items in | // If the server isn't already running, startup continues, and the items in | ||||
// savedPaymentRequest will be handled when uiReady() is called. | // savedPaymentRequest will be handled when uiReady() is called. | ||||
// | // | ||||
// Warning: ipcSendCommandLine() is called early in init, so don't use "Q_EMIT | // Warning: ipcSendCommandLine() is called early in init, so don't use "Q_EMIT | ||||
// message()", but "QMessageBox::"! | // message()", but "QMessageBox::"! | ||||
// | // | ||||
void PaymentServer::ipcParseCommandLine(int argc, char *argv[]) { | void PaymentServer::ipcParseCommandLine(int argc, char *argv[]) { | ||||
for (int i = 1; i < argc; i++) { | for (int i = 1; i < argc; i++) { | ||||
QString arg(argv[i]); | QString arg(argv[i]); | ||||
if (arg.startsWith("-")) continue; | if (arg.startsWith("-")) continue; | ||||
SchemeCfgDummy cfg(Params(CBaseChainParams::MAIN)); | if (ipcParseURI(arg)) { | ||||
QString scheme = GUIUtil::bitcoinURIScheme(cfg); | continue; | ||||
// 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); | |||||
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 | // Filename | ||||
savedPaymentRequests.append(arg); | savedPaymentRequests.append(arg); | ||||
PaymentRequestPlus request; | PaymentRequestPlus request; | ||||
if (readPaymentRequestFromFile(arg, request)) { | if (readPaymentRequestFromFile(arg, request)) { | ||||
if (request.getDetails().network() == "main") { | if (request.getDetails().network() == "main") { | ||||
SelectParams(CBaseChainParams::MAIN); | SelectParams(CBaseChainParams::MAIN); | ||||
} else if (request.getDetails().network() == "test") { | } else if (request.getDetails().network() == "test") { | ||||
▲ Show 20 Lines • Show All 576 Lines • Show Last 20 Lines |
Putting that here makes it is very dangerous function to use in general. I would extract the loop and the SelectParams call in ipcParseCommandLine and keep the inner working of the loop in that function, which would now take networks as an argument.