Skip to content

Commit

Permalink
qt: Remove network detection based on address in BIP21
Browse files Browse the repository at this point in the history
This is some very ugly and brittle code that switches the global network
based on a provided address, remove it. I think in practice it's very
unlikely for testnet BIP21 payment URIs to be used, and if so it's for
testing so it's easy enough to manually copy it. Or to specify
`-testnet` explicitly.

There is already no case for `-regtest` or `-signet`.
  • Loading branch information
laanwj committed Mar 10, 2022
1 parent c9ed992 commit b7dbc83
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/qt/bitcoin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ int GuiMain(int argc, char* argv[])
return EXIT_FAILURE;
}
#ifdef ENABLE_WALLET
// Parse URIs on command line -- this can affect Params()
// Parse URIs on command line
PaymentServer::ipcParseCommandLine(argc, argv);
#endif

Expand Down
23 changes: 1 addition & 22 deletions src/qt/paymentserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,32 +78,11 @@ void PaymentServer::ipcParseCommandLine(int argc, char* argv[])
for (int i = 1; i < argc; i++)
{
QString arg(argv[i]);
if (arg.startsWith("-"))
continue;
if (arg.startsWith("-")) continue;

// If the bitcoin: 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(BITCOIN_IPC_PREFIX, Qt::CaseInsensitive)) // bitcoin: URI
{
if (savedPaymentRequests.contains(arg)) continue;
savedPaymentRequests.insert(arg);

SendCoinsRecipient r;
if (GUIUtil::parseBitcoinURI(arg, &r) && !r.address.isEmpty())
{
auto tempChainParams = CreateChainParams(gArgs, CBaseChainParams::MAIN);

if (IsValidDestinationString(r.address.toStdString(), *tempChainParams)) {
SelectParams(CBaseChainParams::MAIN);
} else {
tempChainParams = CreateChainParams(gArgs, CBaseChainParams::TESTNET);
if (IsValidDestinationString(r.address.toStdString(), *tempChainParams)) {
SelectParams(CBaseChainParams::TESTNET);
}
}
}
}
}
}
Expand Down

0 comments on commit b7dbc83

Please sign in to comment.