Use Params().NetworkID() instead of TestNet() from the payment protocol

This commit is contained in:
jtimon 2014-06-04 15:25:58 +02:00
parent 2871889e83
commit f0a83fc256
2 changed files with 13 additions and 2 deletions

View file

@ -490,6 +490,17 @@ bool PaymentServer::readPaymentRequest(const QString& filename, PaymentRequestPl
return request.parse(data); return request.parse(data);
} }
std::string PaymentServer::mapNetworkIdToName(CChainParams::Network networkId)
{
if (networkId == CChainParams::MAIN)
return "main";
if (networkId == CChainParams::TESTNET)
return "test";
if (networkId == CChainParams::REGTEST)
return "regtest";
return "";
}
bool PaymentServer::processPaymentRequest(PaymentRequestPlus& request, SendCoinsRecipient& recipient) bool PaymentServer::processPaymentRequest(PaymentRequestPlus& request, SendCoinsRecipient& recipient)
{ {
if (!optionsModel) if (!optionsModel)
@ -499,8 +510,7 @@ bool PaymentServer::processPaymentRequest(PaymentRequestPlus& request, SendCoins
const payments::PaymentDetails& details = request.getDetails(); const payments::PaymentDetails& details = request.getDetails();
// Payment request network matches client network? // Payment request network matches client network?
if ((details.network() == "main" && TestNet()) || if (details.network() != mapNetworkIdToName(Params().NetworkID()))
(details.network() == "test" && !TestNet()))
{ {
emit message(tr("Payment request rejected"), tr("Payment request network doesn't match client network."), emit message(tr("Payment request rejected"), tr("Payment request network doesn't match client network."),
CClientUIInterface::MSG_ERROR); CClientUIInterface::MSG_ERROR);

View file

@ -118,6 +118,7 @@ protected:
private: private:
static bool readPaymentRequest(const QString& filename, PaymentRequestPlus& request); static bool readPaymentRequest(const QString& filename, PaymentRequestPlus& request);
std::string mapNetworkIdToName(CChainParams::Network networkId);
bool processPaymentRequest(PaymentRequestPlus& request, SendCoinsRecipient& recipient); bool processPaymentRequest(PaymentRequestPlus& request, SendCoinsRecipient& recipient);
void fetchRequest(const QUrl& url); void fetchRequest(const QUrl& url);