Changeset View
Changeset View
Standalone View
Standalone View
src/qt/paymentserver.cpp
Show First 20 Lines • Show All 533 Lines • ▼ Show 20 Lines | if (request.IsInitialized()) { | ||||
return false; | return false; | ||||
} | } | ||||
recipient.paymentRequest = request; | recipient.paymentRequest = request; | ||||
recipient.message = GUIUtil::HtmlEscape(request.getDetails().memo()); | recipient.message = GUIUtil::HtmlEscape(request.getDetails().memo()); | ||||
request.getMerchant(certStore.get(), recipient.authenticatedMerchant); | request.getMerchant(certStore.get(), recipient.authenticatedMerchant); | ||||
QList<std::pair<CScript, CAmount>> sendingTos = request.getPayTo(); | QList<std::pair<CScript, Amount>> sendingTos = request.getPayTo(); | ||||
QStringList addresses; | QStringList addresses; | ||||
for (const std::pair<CScript, CAmount> &sendingTo : sendingTos) { | for (const std::pair<CScript, Amount> &sendingTo : sendingTos) { | ||||
// Extract and check destination addresses | // Extract and check destination addresses | ||||
CTxDestination dest; | CTxDestination dest; | ||||
if (ExtractDestination(sendingTo.first, dest)) { | if (ExtractDestination(sendingTo.first, dest)) { | ||||
// Append destination address | // Append destination address | ||||
addresses.append(QString::fromStdString(EncodeDestination(dest))); | addresses.append(QString::fromStdString(EncodeDestination(dest))); | ||||
} else if (!recipient.authenticatedMerchant.isEmpty()) { | } else if (!recipient.authenticatedMerchant.isEmpty()) { | ||||
// Unauthenticated payment requests to custom bitcoin addresses are | // Unauthenticated payment requests to custom bitcoin addresses are | ||||
// not supported | // not supported | ||||
// (there is no good way to tell the user where they are paying in a | // (there is no good way to tell the user where they are paying in a | ||||
// way they'd | // way they'd | ||||
// have a chance of understanding). | // have a chance of understanding). | ||||
Q_EMIT message(tr("Payment request rejected"), | Q_EMIT message(tr("Payment request rejected"), | ||||
tr("Unverified payment requests to custom payment " | tr("Unverified payment requests to custom payment " | ||||
"scripts are unsupported."), | "scripts are unsupported."), | ||||
CClientUIInterface::MSG_ERROR); | CClientUIInterface::MSG_ERROR); | ||||
return false; | return false; | ||||
} | } | ||||
// Bitcoin amounts are stored as (optional) uint64 in the protobuf | // Bitcoin amounts are stored as (optional) uint64 in the protobuf | ||||
// messages (see paymentrequest.proto), but CAmount is defined as | // messages (see paymentrequest.proto), but Amount is defined as | ||||
// int64_t. Because of that we need to verify that amounts are in a | // int64_t. Because of that we need to verify that amounts are in a | ||||
// valid range and no overflow has happened. | // valid range and no overflow has happened. | ||||
if (!verifyAmount(sendingTo.second)) { | if (!verifyAmount(sendingTo.second)) { | ||||
Q_EMIT message(tr("Payment request rejected"), | Q_EMIT message(tr("Payment request rejected"), | ||||
tr("Invalid payment request."), | tr("Invalid payment request."), | ||||
CClientUIInterface::MSG_ERROR); | CClientUIInterface::MSG_ERROR); | ||||
return false; | return false; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 223 Lines • ▼ Show 20 Lines | if (!fVerified) { | ||||
"(%2 bytes, allowed %3 bytes).") | "(%2 bytes, allowed %3 bytes).") | ||||
.arg(__func__) | .arg(__func__) | ||||
.arg(requestSize) | .arg(requestSize) | ||||
.arg(BIP70_MAX_PAYMENTREQUEST_SIZE); | .arg(BIP70_MAX_PAYMENTREQUEST_SIZE); | ||||
} | } | ||||
return fVerified; | return fVerified; | ||||
} | } | ||||
bool PaymentServer::verifyAmount(const CAmount &requestAmount) { | bool PaymentServer::verifyAmount(const Amount requestAmount) { | ||||
bool fVerified = MoneyRange(Amount(requestAmount)); | bool fVerified = MoneyRange(Amount(requestAmount)); | ||||
if (!fVerified) { | if (!fVerified) { | ||||
qWarning() << QString("PaymentServer::%1: Payment request amount out " | qWarning() << QString("PaymentServer::%1: Payment request amount out " | ||||
"of allowed range (%2, allowed 0 - %3).") | "of allowed range (%2, allowed 0 - %3).") | ||||
.arg(__func__) | .arg(__func__) | ||||
.arg(requestAmount) | .arg(requestAmount.GetSatoshis()) | ||||
.arg(MAX_MONEY.GetSatoshis()); | .arg(MAX_MONEY.GetSatoshis()); | ||||
} | } | ||||
return fVerified; | return fVerified; | ||||
} | } | ||||
X509_STORE *PaymentServer::getCertStore() { | X509_STORE *PaymentServer::getCertStore() { | ||||
return certStore.get(); | return certStore.get(); | ||||
} | } |