mirror of
https://github.com/dashpay/dash.git
synced 2024-12-27 04:52:59 +01:00
Remove direct bitcoin calls from qt/paymentserver.cpp
This commit is contained in:
parent
50f7d661ab
commit
b2f7e1d1eb
@ -56,6 +56,7 @@ class NodeImpl : public Node
|
|||||||
bool softSetArg(const std::string& arg, const std::string& value) override { return gArgs.SoftSetArg(arg, value); }
|
bool softSetArg(const std::string& arg, const std::string& value) override { return gArgs.SoftSetArg(arg, value); }
|
||||||
bool softSetBoolArg(const std::string& arg, bool value) override { return gArgs.SoftSetBoolArg(arg, value); }
|
bool softSetBoolArg(const std::string& arg, bool value) override { return gArgs.SoftSetBoolArg(arg, value); }
|
||||||
void selectParams(const std::string& network) override { SelectParams(network); }
|
void selectParams(const std::string& network) override { SelectParams(network); }
|
||||||
|
std::string getNetwork() override { return Params().NetworkIDString(); }
|
||||||
void initLogging() override { InitLogging(); }
|
void initLogging() override { InitLogging(); }
|
||||||
void initParameterInteraction() override { InitParameterInteraction(); }
|
void initParameterInteraction() override { InitParameterInteraction(); }
|
||||||
std::string getWarnings(const std::string& type) override { return GetWarnings(type); }
|
std::string getWarnings(const std::string& type) override { return GetWarnings(type); }
|
||||||
|
@ -55,6 +55,9 @@ public:
|
|||||||
//! Choose network parameters.
|
//! Choose network parameters.
|
||||||
virtual void selectParams(const std::string& network) = 0;
|
virtual void selectParams(const std::string& network) = 0;
|
||||||
|
|
||||||
|
//! Get network name.
|
||||||
|
virtual std::string getNetwork() = 0;
|
||||||
|
|
||||||
//! Init logging.
|
//! Init logging.
|
||||||
virtual void initLogging() = 0;
|
virtual void initLogging() = 0;
|
||||||
|
|
||||||
|
@ -470,8 +470,8 @@ void BitcoinApplication::initializeResult(bool success)
|
|||||||
fFirstWallet = false;
|
fFirstWallet = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
connect(walletModel, SIGNAL(coinsSent(CWallet*,SendCoinsRecipient,QByteArray)),
|
connect(walletModel, SIGNAL(coinsSent(WalletModel*,SendCoinsRecipient,QByteArray)),
|
||||||
paymentServer, SLOT(fetchPaymentACK(CWallet*,const SendCoinsRecipient&,QByteArray)));
|
paymentServer, SLOT(fetchPaymentACK(WalletModel*,const SendCoinsRecipient&,QByteArray)));
|
||||||
|
|
||||||
m_wallet_models.push_back(walletModel);
|
m_wallet_models.push_back(walletModel);
|
||||||
}
|
}
|
||||||
@ -632,7 +632,7 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
#ifdef ENABLE_WALLET
|
#ifdef ENABLE_WALLET
|
||||||
// Parse URIs on command line -- this can affect Params()
|
// Parse URIs on command line -- this can affect Params()
|
||||||
PaymentServer::ipcParseCommandLine(argc, argv);
|
PaymentServer::ipcParseCommandLine(*node, argc, argv);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
QScopedPointer<const NetworkStyle> networkStyle(NetworkStyle::instantiate(QString::fromStdString(Params().NetworkIDString())));
|
QScopedPointer<const NetworkStyle> networkStyle(NetworkStyle::instantiate(QString::fromStdString(Params().NetworkIDString())));
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
#include <base58.h>
|
#include <base58.h>
|
||||||
#include <chainparams.h>
|
#include <chainparams.h>
|
||||||
|
#include <interface/node.h>
|
||||||
#include <policy/policy.h>
|
#include <policy/policy.h>
|
||||||
#include <ui_interface.h>
|
#include <ui_interface.h>
|
||||||
#include <util.h>
|
#include <util.h>
|
||||||
@ -190,7 +191,7 @@ void PaymentServer::LoadRootCAs(X509_STORE* _store)
|
|||||||
// Warning: ipcSendCommandLine() is called early in init,
|
// Warning: ipcSendCommandLine() is called early in init,
|
||||||
// so don't use "Q_EMIT message()", but "QMessageBox::"!
|
// so don't use "Q_EMIT message()", but "QMessageBox::"!
|
||||||
//
|
//
|
||||||
void PaymentServer::ipcParseCommandLine(int argc, char* argv[])
|
void PaymentServer::ipcParseCommandLine(interface::Node& node, int argc, char* argv[])
|
||||||
{
|
{
|
||||||
for (int i = 1; i < argc; i++)
|
for (int i = 1; i < argc; i++)
|
||||||
{
|
{
|
||||||
@ -212,11 +213,11 @@ void PaymentServer::ipcParseCommandLine(int argc, char* argv[])
|
|||||||
auto tempChainParams = CreateChainParams(CBaseChainParams::MAIN);
|
auto tempChainParams = CreateChainParams(CBaseChainParams::MAIN);
|
||||||
|
|
||||||
if (IsValidDestinationString(r.address.toStdString(), *tempChainParams)) {
|
if (IsValidDestinationString(r.address.toStdString(), *tempChainParams)) {
|
||||||
SelectParams(CBaseChainParams::MAIN);
|
node.selectParams(CBaseChainParams::MAIN);
|
||||||
} else {
|
} else {
|
||||||
tempChainParams = CreateChainParams(CBaseChainParams::TESTNET);
|
tempChainParams = CreateChainParams(CBaseChainParams::TESTNET);
|
||||||
if (IsValidDestinationString(r.address.toStdString(), *tempChainParams)) {
|
if (IsValidDestinationString(r.address.toStdString(), *tempChainParams)) {
|
||||||
SelectParams(CBaseChainParams::TESTNET);
|
node.selectParams(CBaseChainParams::TESTNET);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -230,11 +231,11 @@ void PaymentServer::ipcParseCommandLine(int argc, char* argv[])
|
|||||||
{
|
{
|
||||||
if (request.getDetails().network() == "main")
|
if (request.getDetails().network() == "main")
|
||||||
{
|
{
|
||||||
SelectParams(CBaseChainParams::MAIN);
|
node.selectParams(CBaseChainParams::MAIN);
|
||||||
}
|
}
|
||||||
else if (request.getDetails().network() == "test")
|
else if (request.getDetails().network() == "test")
|
||||||
{
|
{
|
||||||
SelectParams(CBaseChainParams::TESTNET);
|
node.selectParams(CBaseChainParams::TESTNET);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -508,7 +509,7 @@ bool PaymentServer::processPaymentRequest(const PaymentRequestPlus& request, Sen
|
|||||||
|
|
||||||
if (request.IsInitialized()) {
|
if (request.IsInitialized()) {
|
||||||
// Payment request network matches client network?
|
// Payment request network matches client network?
|
||||||
if (!verifyNetwork(request.getDetails())) {
|
if (!verifyNetwork(optionsModel->node(), request.getDetails())) {
|
||||||
Q_EMIT message(tr("Payment request rejected"), tr("Payment request network doesn't match client network."),
|
Q_EMIT message(tr("Payment request rejected"), tr("Payment request network doesn't match client network."),
|
||||||
CClientUIInterface::MSG_ERROR);
|
CClientUIInterface::MSG_ERROR);
|
||||||
|
|
||||||
@ -565,7 +566,7 @@ bool PaymentServer::processPaymentRequest(const PaymentRequestPlus& request, Sen
|
|||||||
|
|
||||||
// Extract and check amounts
|
// Extract and check amounts
|
||||||
CTxOut txOut(sendingTo.second, sendingTo.first);
|
CTxOut txOut(sendingTo.second, sendingTo.first);
|
||||||
if (IsDust(txOut, ::dustRelayFee)) {
|
if (IsDust(txOut, optionsModel->node().getDustRelayFee())) {
|
||||||
Q_EMIT message(tr("Payment request error"), tr("Requested payment amount of %1 is too small (considered dust).")
|
Q_EMIT message(tr("Payment request error"), tr("Requested payment amount of %1 is too small (considered dust).")
|
||||||
.arg(BitcoinUnits::formatWithUnit(optionsModel->getDisplayUnit(), sendingTo.second)),
|
.arg(BitcoinUnits::formatWithUnit(optionsModel->getDisplayUnit(), sendingTo.second)),
|
||||||
CClientUIInterface::MSG_ERROR);
|
CClientUIInterface::MSG_ERROR);
|
||||||
@ -603,7 +604,7 @@ void PaymentServer::fetchRequest(const QUrl& url)
|
|||||||
netManager->get(netRequest);
|
netManager->get(netRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PaymentServer::fetchPaymentACK(CWallet* wallet, const SendCoinsRecipient& recipient, QByteArray transaction)
|
void PaymentServer::fetchPaymentACK(WalletModel* walletModel, const SendCoinsRecipient& recipient, QByteArray transaction)
|
||||||
{
|
{
|
||||||
const payments::PaymentDetails& details = recipient.paymentRequest.getDetails();
|
const payments::PaymentDetails& details = recipient.paymentRequest.getDetails();
|
||||||
if (!details.has_payment_url())
|
if (!details.has_payment_url())
|
||||||
@ -743,14 +744,14 @@ void PaymentServer::handlePaymentACK(const QString& paymentACKMsg)
|
|||||||
Q_EMIT message(tr("Payment acknowledged"), paymentACKMsg, CClientUIInterface::ICON_INFORMATION | CClientUIInterface::MODAL);
|
Q_EMIT message(tr("Payment acknowledged"), paymentACKMsg, CClientUIInterface::ICON_INFORMATION | CClientUIInterface::MODAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PaymentServer::verifyNetwork(const payments::PaymentDetails& requestDetails)
|
bool PaymentServer::verifyNetwork(interface::Node& node, const payments::PaymentDetails& requestDetails)
|
||||||
{
|
{
|
||||||
bool fVerified = requestDetails.network() == Params().NetworkIDString();
|
bool fVerified = requestDetails.network() == node.getNetwork();
|
||||||
if (!fVerified) {
|
if (!fVerified) {
|
||||||
qWarning() << QString("PaymentServer::%1: Payment request network \"%2\" doesn't match client network \"%3\".")
|
qWarning() << QString("PaymentServer::%1: Payment request network \"%2\" doesn't match client network \"%3\".")
|
||||||
.arg(__func__)
|
.arg(__func__)
|
||||||
.arg(QString::fromStdString(requestDetails.network()))
|
.arg(QString::fromStdString(requestDetails.network()))
|
||||||
.arg(QString::fromStdString(Params().NetworkIDString()));
|
.arg(QString::fromStdString(node.getNetwork()));
|
||||||
}
|
}
|
||||||
return fVerified;
|
return fVerified;
|
||||||
}
|
}
|
||||||
|
@ -40,8 +40,6 @@
|
|||||||
|
|
||||||
class OptionsModel;
|
class OptionsModel;
|
||||||
|
|
||||||
class CWallet;
|
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
class QApplication;
|
class QApplication;
|
||||||
class QByteArray;
|
class QByteArray;
|
||||||
@ -62,7 +60,7 @@ class PaymentServer : public QObject
|
|||||||
public:
|
public:
|
||||||
// Parse URIs on command line
|
// Parse URIs on command line
|
||||||
// Returns false on error
|
// Returns false on error
|
||||||
static void ipcParseCommandLine(int argc, char *argv[]);
|
static void ipcParseCommandLine(interface::Node& node, int argc, char *argv[]);
|
||||||
|
|
||||||
// Returns true if there were URIs on the command line
|
// Returns true if there were URIs on the command line
|
||||||
// which were successfully sent to an already-running
|
// which were successfully sent to an already-running
|
||||||
@ -89,7 +87,7 @@ public:
|
|||||||
void setOptionsModel(OptionsModel *optionsModel);
|
void setOptionsModel(OptionsModel *optionsModel);
|
||||||
|
|
||||||
// Verify that the payment request network matches the client network
|
// Verify that the payment request network matches the client network
|
||||||
static bool verifyNetwork(const payments::PaymentDetails& requestDetails);
|
static bool verifyNetwork(interface::Node& node, const payments::PaymentDetails& requestDetails);
|
||||||
// Verify if the payment request is expired
|
// Verify if the payment request is expired
|
||||||
static bool verifyExpired(const payments::PaymentDetails& requestDetails);
|
static bool verifyExpired(const payments::PaymentDetails& requestDetails);
|
||||||
// Verify the payment request size is valid as per BIP70
|
// Verify the payment request size is valid as per BIP70
|
||||||
@ -113,7 +111,7 @@ public Q_SLOTS:
|
|||||||
void uiReady();
|
void uiReady();
|
||||||
|
|
||||||
// Submit Payment message to a merchant, get back PaymentACK:
|
// Submit Payment message to a merchant, get back PaymentACK:
|
||||||
void fetchPaymentACK(CWallet* wallet, const SendCoinsRecipient& recipient, QByteArray transaction);
|
void fetchPaymentACK(WalletModel* walletModel, const SendCoinsRecipient& recipient, QByteArray transaction);
|
||||||
|
|
||||||
// Handle an incoming URI, URI with local file scheme or file
|
// Handle an incoming URI, URI with local file scheme or file
|
||||||
void handleURIOrFile(const QString& s);
|
void handleURIOrFile(const QString& s);
|
||||||
|
@ -146,7 +146,7 @@ void PaymentServerTests::paymentServerTests()
|
|||||||
// Ensure the request is initialized, because network "main" is default, even for
|
// Ensure the request is initialized, because network "main" is default, even for
|
||||||
// uninitialized payment requests and that will fail our test here.
|
// uninitialized payment requests and that will fail our test here.
|
||||||
QVERIFY(r.paymentRequest.IsInitialized());
|
QVERIFY(r.paymentRequest.IsInitialized());
|
||||||
QCOMPARE(PaymentServer::verifyNetwork(r.paymentRequest.getDetails()), false);
|
QCOMPARE(PaymentServer::verifyNetwork(*node, r.paymentRequest.getDetails()), false);
|
||||||
|
|
||||||
// Expired payment request (expires is set to 1 = 1970-01-01 00:00:01):
|
// Expired payment request (expires is set to 1 = 1970-01-01 00:00:01):
|
||||||
data = DecodeBase64(paymentrequest2_cert2_BASE64);
|
data = DecodeBase64(paymentrequest2_cert2_BASE64);
|
||||||
|
@ -333,7 +333,7 @@ WalletModel::SendCoinsReturn WalletModel::sendCoins(WalletModelTransaction &tran
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Q_EMIT coinsSent(cwallet, rcp, transaction_array);
|
Q_EMIT coinsSent(this, rcp, transaction_array);
|
||||||
}
|
}
|
||||||
|
|
||||||
checkBalanceChanged(m_wallet->getBalances()); // update balance immediately, otherwise there could be a short noticeable delay until pollBalanceChanged hits
|
checkBalanceChanged(m_wallet->getBalances()); // update balance immediately, otherwise there could be a short noticeable delay until pollBalanceChanged hits
|
||||||
|
@ -258,7 +258,7 @@ Q_SIGNALS:
|
|||||||
void message(const QString &title, const QString &message, unsigned int style);
|
void message(const QString &title, const QString &message, unsigned int style);
|
||||||
|
|
||||||
// Coins sent: from wallet, to recipient, in (serialized) transaction:
|
// Coins sent: from wallet, to recipient, in (serialized) transaction:
|
||||||
void coinsSent(CWallet* wallet, SendCoinsRecipient recipient, QByteArray transaction);
|
void coinsSent(WalletModel* wallet, SendCoinsRecipient recipient, QByteArray transaction);
|
||||||
|
|
||||||
// Show progress dialog e.g. for rescan
|
// Show progress dialog e.g. for rescan
|
||||||
void showProgress(const QString &title, int nProgress);
|
void showProgress(const QString &title, int nProgress);
|
||||||
|
Loading…
Reference in New Issue
Block a user