Changeset View
Changeset View
Standalone View
Standalone View
src/qt/paymentserver.cpp
Show First 20 Lines • Show All 704 Lines • ▼ Show 20 Lines | void PaymentServer::fetchRequest(const QUrl &url) { | ||||
netRequest.setAttribute(QNetworkRequest::User, | netRequest.setAttribute(QNetworkRequest::User, | ||||
BIP70_MESSAGE_PAYMENTREQUEST); | BIP70_MESSAGE_PAYMENTREQUEST); | ||||
netRequest.setUrl(url); | netRequest.setUrl(url); | ||||
netRequest.setRawHeader("User-Agent", CLIENT_NAME.c_str()); | netRequest.setRawHeader("User-Agent", CLIENT_NAME.c_str()); | ||||
netRequest.setRawHeader("Accept", BIP71_MIMETYPE_PAYMENTREQUEST); | netRequest.setRawHeader("Accept", BIP71_MIMETYPE_PAYMENTREQUEST); | ||||
netManager->get(netRequest); | netManager->get(netRequest); | ||||
} | } | ||||
void PaymentServer::fetchPaymentACK(WalletModel *walletModel, | void PaymentServer::fetchPaymentACK(interfaces::Wallet &wallet, | ||||
const SendCoinsRecipient &recipient, | const SendCoinsRecipient &recipient, | ||||
QByteArray transaction) { | QByteArray transaction) { | ||||
const payments::PaymentDetails &details = | const payments::PaymentDetails &details = | ||||
recipient.paymentRequest.getDetails(); | recipient.paymentRequest.getDetails(); | ||||
if (!details.has_payment_url()) { | if (!details.has_payment_url()) { | ||||
return; | return; | ||||
} | } | ||||
QNetworkRequest netRequest; | QNetworkRequest netRequest; | ||||
netRequest.setAttribute(QNetworkRequest::User, BIP70_MESSAGE_PAYMENTACK); | netRequest.setAttribute(QNetworkRequest::User, BIP70_MESSAGE_PAYMENTACK); | ||||
netRequest.setUrl(QString::fromStdString(details.payment_url())); | netRequest.setUrl(QString::fromStdString(details.payment_url())); | ||||
netRequest.setHeader(QNetworkRequest::ContentTypeHeader, | netRequest.setHeader(QNetworkRequest::ContentTypeHeader, | ||||
BIP71_MIMETYPE_PAYMENT); | BIP71_MIMETYPE_PAYMENT); | ||||
netRequest.setRawHeader("User-Agent", CLIENT_NAME.c_str()); | netRequest.setRawHeader("User-Agent", CLIENT_NAME.c_str()); | ||||
netRequest.setRawHeader("Accept", BIP71_MIMETYPE_PAYMENTACK); | netRequest.setRawHeader("Accept", BIP71_MIMETYPE_PAYMENTACK); | ||||
payments::Payment payment; | payments::Payment payment; | ||||
payment.set_merchant_data(details.merchant_data()); | payment.set_merchant_data(details.merchant_data()); | ||||
payment.add_transactions(transaction.data(), transaction.size()); | payment.add_transactions(transaction.data(), transaction.size()); | ||||
// Create a new refund address, or re-use: | // Create a new refund address, or re-use: | ||||
CTxDestination dest; | CTxDestination dest; | ||||
const OutputType change_type = | const OutputType change_type = | ||||
walletModel->wallet().getDefaultChangeType() != OutputType::CHANGE_AUTO | wallet.getDefaultChangeType() != OutputType::CHANGE_AUTO | ||||
? walletModel->wallet().getDefaultChangeType() | ? wallet.getDefaultChangeType() | ||||
: walletModel->wallet().getDefaultAddressType(); | : wallet.getDefaultAddressType(); | ||||
if (walletModel->wallet().getNewDestination(change_type, "", dest)) { | if (wallet.getNewDestination(change_type, "", dest)) { | ||||
// BIP70 requests encode the scriptPubKey directly, so we are not | // BIP70 requests encode the scriptPubKey directly, so we are not | ||||
// restricted to address types supported by the receiver. As a result, | // restricted to address types supported by the receiver. As a result, | ||||
// we choose the address format we also use for change. Despite an | // we choose the address format we also use for change. Despite an | ||||
// actual payment and not change, this is a close match: it's the output | // actual payment and not change, this is a close match: it's the output | ||||
// type we use subject to privacy issues, but not restricted by what | // type we use subject to privacy issues, but not restricted by what | ||||
// other software supports. | // other software supports. | ||||
std::string label = tr("Refund from %1") | std::string label = tr("Refund from %1") | ||||
.arg(recipient.authenticatedMerchant) | .arg(recipient.authenticatedMerchant) | ||||
.toStdString(); | .toStdString(); | ||||
walletModel->wallet().setAddressBook(dest, label, "refund"); | wallet.setAddressBook(dest, label, "refund"); | ||||
CScript s = GetScriptForDestination(dest); | CScript s = GetScriptForDestination(dest); | ||||
payments::Output *refund_to = payment.add_refund_to(); | payments::Output *refund_to = payment.add_refund_to(); | ||||
refund_to->set_script(&s[0], s.size()); | refund_to->set_script(&s[0], s.size()); | ||||
} else { | } else { | ||||
// This should never happen, because sending coins should have | // This should never happen, because sending coins should have | ||||
// just unlocked the wallet and refilled the keypool. | // just unlocked the wallet and refilled the keypool. | ||||
qWarning() << "PaymentServer::fetchPaymentACK: Error getting refund " | qWarning() << "PaymentServer::fetchPaymentACK: Error getting refund " | ||||
▲ Show 20 Lines • Show All 156 Lines • Show Last 20 Lines |