Merge #17513: refactor, qt: Nuke some circular dependencies

5f50599ae7 refactor: Cleanup headers from walletmodel.h (Hennadii Stepanov)
a53e9895db refactor: Nuke walletmodel circular dependency (Hennadii Stepanov)
49c4211c04 refactor: Nuke walletmodeltransaction circular dep (Hennadii Stepanov)
567cb44eb9 refactor: Nuke guiutil circular dependency (Hennadii Stepanov)
73b5505cfe refactor: Move SendCoinsRecipient in own header (Hennadii Stepanov)

Pull request description:

  This PR gets rid of the following circular dependencies:
  - `qt/guiutil` -> `qt/walletmodel` -> `qt/optionsmodel` -> `qt/guiutil`
  - `qt/walletmodel` -> `qt/walletmodeltransaction` -> `qt/walletmodel`
  - `qt/paymentserver` -> `qt/walletmodel` -> `qt/paymentserver`

ACKs for top commit:
  Sjors:
    ACK 5f50599ae7
  instagibbs:
    code review ACK 5f50599ae7
  practicalswift:
    ACK 5f50599ae7 -- diff looks correct
  promag:
    ACK 5f50599ae7.

Tree-SHA512: 070686ac82b5c68c3ef1b8b4c16b4b916b84d80d1e92e42287fdd9454671bea54779c0d2db4db623750aaaf180beaba212137190d6a427113905e2c4be5c60c5
This commit is contained in:
Wladimir J. van der Laan 2019-11-21 19:38:22 +01:00
commit 69a6f1ad1f
No known key found for this signature in database
GPG key ID: 1E4AED62986CD25D
17 changed files with 109 additions and 73 deletions

View file

@ -136,6 +136,7 @@ BITCOIN_QT_H = \
qt/rpcconsole.h \
qt/sendcoinsdialog.h \
qt/sendcoinsentry.h \
qt/sendcoinsrecipient.h \
qt/signverifymessagedialog.h \
qt/splashscreen.h \
qt/trafficgraphwidget.h \

View file

@ -7,7 +7,7 @@
#include <qt/bitcoinaddressvalidator.h>
#include <qt/bitcoinunits.h>
#include <qt/qvalidatedlineedit.h>
#include <qt/walletmodel.h>
#include <qt/sendcoinsrecipient.h>
#include <base58.h>
#include <chainparams.h>

View file

@ -6,7 +6,7 @@
#include <qt/forms/ui_openuridialog.h>
#include <qt/guiutil.h>
#include <qt/walletmodel.h>
#include <qt/sendcoinsrecipient.h>
#include <QUrl>

View file

@ -36,13 +36,17 @@
#include <config/bitcoin-config.h>
#endif
#include <qt/walletmodel.h>
#include <qt/sendcoinsrecipient.h>
#include <QObject>
#include <QString>
class OptionsModel;
namespace interfaces {
class Node;
} // namespace interfaces
QT_BEGIN_NAMESPACE
class QApplication;
class QByteArray;

View file

@ -8,6 +8,7 @@
#include <qt/bitcoinunits.h>
#include <qt/guiutil.h>
#include <qt/optionsmodel.h>
#include <qt/walletmodel.h>
#include <QClipboard>
#include <QPixmap>

View file

@ -5,10 +5,12 @@
#ifndef BITCOIN_QT_RECEIVEREQUESTDIALOG_H
#define BITCOIN_QT_RECEIVEREQUESTDIALOG_H
#include <qt/walletmodel.h>
#include <qt/sendcoinsrecipient.h>
#include <QDialog>
class WalletModel;
namespace Ui {
class ReceiveRequestDialog;
}

View file

@ -7,6 +7,7 @@
#include <qt/bitcoinunits.h>
#include <qt/guiutil.h>
#include <qt/optionsmodel.h>
#include <qt/walletmodel.h>
#include <clientversion.h>
#include <streams.h>

View file

@ -5,12 +5,14 @@
#ifndef BITCOIN_QT_RECENTREQUESTSTABLEMODEL_H
#define BITCOIN_QT_RECENTREQUESTSTABLEMODEL_H
#include <qt/walletmodel.h>
#include <qt/sendcoinsrecipient.h>
#include <QAbstractTableModel>
#include <QStringList>
#include <QDateTime>
class WalletModel;
class RecentRequestEntry
{
public:

View file

@ -14,6 +14,7 @@
#include <qt/guiutil.h>
#include <qt/optionsmodel.h>
#include <qt/platformstyle.h>
#include <qt/walletmodel.h>
#include <QApplication>
#include <QClipboard>

View file

@ -5,13 +5,17 @@
#ifndef BITCOIN_QT_SENDCOINSENTRY_H
#define BITCOIN_QT_SENDCOINSENTRY_H
#include <qt/walletmodel.h>
#include <qt/sendcoinsrecipient.h>
#include <QStackedWidget>
class WalletModel;
class PlatformStyle;
namespace interfaces {
class Node;
} // namespace interfaces
namespace Ui {
class SendCoinsEntry;
}

View file

@ -0,0 +1,74 @@
// Copyright (c) 2011-2019 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef BITCOIN_QT_SENDCOINSRECIPIENT_H
#define BITCOIN_QT_SENDCOINSRECIPIENT_H
#if defined(HAVE_CONFIG_H)
#include <config/bitcoin-config.h>
#endif
#include <amount.h>
#include <serialize.h>
#include <string>
#include <QString>
class SendCoinsRecipient
{
public:
explicit SendCoinsRecipient() : amount(0), fSubtractFeeFromAmount(false), nVersion(SendCoinsRecipient::CURRENT_VERSION) { }
explicit SendCoinsRecipient(const QString &addr, const QString &_label, const CAmount& _amount, const QString &_message):
address(addr), label(_label), amount(_amount), message(_message), fSubtractFeeFromAmount(false), nVersion(SendCoinsRecipient::CURRENT_VERSION) {}
// If from an unauthenticated payment request, this is used for storing
// the addresses, e.g. address-A<br />address-B<br />address-C.
// Info: As we don't need to process addresses in here when using
// payment requests, we can abuse it for displaying an address list.
// Todo: This is a hack, should be replaced with a cleaner solution!
QString address;
QString label;
CAmount amount;
// If from a payment request, this is used for storing the memo
QString message;
// Keep the payment request around as a serialized string to ensure
// load/store is lossless.
std::string sPaymentRequest;
// Empty if no authentication or invalid signature/cert/etc.
QString authenticatedMerchant;
bool fSubtractFeeFromAmount; // memory only
static const int CURRENT_VERSION = 1;
int nVersion;
ADD_SERIALIZE_METHODS;
template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action) {
std::string sAddress = address.toStdString();
std::string sLabel = label.toStdString();
std::string sMessage = message.toStdString();
std::string sAuthenticatedMerchant = authenticatedMerchant.toStdString();
READWRITE(this->nVersion);
READWRITE(sAddress);
READWRITE(sLabel);
READWRITE(amount);
READWRITE(sMessage);
READWRITE(sPaymentRequest);
READWRITE(sAuthenticatedMerchant);
if (ser_action.ForRead())
{
address = QString::fromStdString(sAddress);
label = QString::fromStdString(sLabel);
message = QString::fromStdString(sMessage);
authenticatedMerchant = QString::fromStdString(sAuthenticatedMerchant);
}
}
};
#endif // BITCOIN_QT_SENDCOINSRECIPIENT_H

View file

@ -15,11 +15,12 @@
#include <consensus/consensus.h>
#include <interfaces/node.h>
#include <interfaces/wallet.h>
#include <key_io.h>
#include <validation.h>
#include <policy/policy.h>
#include <script/script.h>
#include <util/system.h>
#include <policy/policy.h>
#include <validation.h>
#include <wallet/ismine.h>
#include <stdint.h>

View file

@ -2,17 +2,18 @@
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <qt/walletcontroller.h>
#include <qt/askpassphrasedialog.h>
#include <qt/createwalletdialog.h>
#include <qt/guiconstants.h>
#include <qt/guiutil.h>
#include <qt/walletcontroller.h>
#include <wallet/wallet.h>
#include <qt/walletmodel.h>
#include <interfaces/handler.h>
#include <interfaces/node.h>
#include <util/string.h>
#include <wallet/wallet.h>
#include <algorithm>

View file

@ -5,7 +5,7 @@
#ifndef BITCOIN_QT_WALLETCONTROLLER_H
#define BITCOIN_QT_WALLETCONTROLLER_H
#include <qt/walletmodel.h>
#include <qt/sendcoinsrecipient.h>
#include <support/allocators/secure.h>
#include <sync.h>
@ -23,10 +23,12 @@
class OptionsModel;
class PlatformStyle;
class WalletModel;
namespace interfaces {
class Handler;
class Node;
class Wallet;
} // namespace interfaces
class AskPassphraseDialog;

View file

@ -9,9 +9,7 @@
#include <config/bitcoin-config.h>
#endif
#include <amount.h>
#include <key.h>
#include <serialize.h>
#include <script/standard.h>
#include <qt/walletmodeltransaction.h>
@ -29,6 +27,7 @@ class AddressTableModel;
class OptionsModel;
class PlatformStyle;
class RecentRequestsTableModel;
class SendCoinsRecipient;
class TransactionTableModel;
class WalletModelTransaction;
@ -47,61 +46,6 @@ QT_BEGIN_NAMESPACE
class QTimer;
QT_END_NAMESPACE
class SendCoinsRecipient
{
public:
explicit SendCoinsRecipient() : amount(0), fSubtractFeeFromAmount(false), nVersion(SendCoinsRecipient::CURRENT_VERSION) { }
explicit SendCoinsRecipient(const QString &addr, const QString &_label, const CAmount& _amount, const QString &_message):
address(addr), label(_label), amount(_amount), message(_message), fSubtractFeeFromAmount(false), nVersion(SendCoinsRecipient::CURRENT_VERSION) {}
// If from an unauthenticated payment request, this is used for storing
// the addresses, e.g. address-A<br />address-B<br />address-C.
// Info: As we don't need to process addresses in here when using
// payment requests, we can abuse it for displaying an address list.
// Todo: This is a hack, should be replaced with a cleaner solution!
QString address;
QString label;
CAmount amount;
// If from a payment request, this is used for storing the memo
QString message;
// Keep the payment request around as a serialized string to ensure
// load/store is lossless.
std::string sPaymentRequest;
// Empty if no authentication or invalid signature/cert/etc.
QString authenticatedMerchant;
bool fSubtractFeeFromAmount; // memory only
static const int CURRENT_VERSION = 1;
int nVersion;
ADD_SERIALIZE_METHODS;
template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action) {
std::string sAddress = address.toStdString();
std::string sLabel = label.toStdString();
std::string sMessage = message.toStdString();
std::string sAuthenticatedMerchant = authenticatedMerchant.toStdString();
READWRITE(this->nVersion);
READWRITE(sAddress);
READWRITE(sLabel);
READWRITE(amount);
READWRITE(sMessage);
READWRITE(sPaymentRequest);
READWRITE(sAuthenticatedMerchant);
if (ser_action.ForRead())
{
address = QString::fromStdString(sAddress);
label = QString::fromStdString(sLabel);
message = QString::fromStdString(sMessage);
authenticatedMerchant = QString::fromStdString(sAuthenticatedMerchant);
}
}
};
/** Interface to Bitcoin wallet from Qt view code. */
class WalletModel : public QObject
{

View file

@ -5,7 +5,8 @@
#ifndef BITCOIN_QT_WALLETMODELTRANSACTION_H
#define BITCOIN_QT_WALLETMODELTRANSACTION_H
#include <qt/walletmodel.h>
#include <primitives/transaction.h>
#include <qt/sendcoinsrecipient.h>
#include <amount.h>

View file

@ -18,17 +18,14 @@ EXPECTED_CIRCULAR_DEPENDENCIES=(
"qt/bitcoingui -> qt/walletframe -> qt/bitcoingui"
"qt/bitcoingui -> qt/walletview -> qt/bitcoingui"
"qt/clientmodel -> qt/peertablemodel -> qt/clientmodel"
"qt/paymentserver -> qt/walletmodel -> qt/paymentserver"
"qt/recentrequeststablemodel -> qt/walletmodel -> qt/recentrequeststablemodel"
"qt/sendcoinsdialog -> qt/walletmodel -> qt/sendcoinsdialog"
"qt/transactiontablemodel -> qt/walletmodel -> qt/transactiontablemodel"
"qt/walletmodel -> qt/walletmodeltransaction -> qt/walletmodel"
"txmempool -> validation -> txmempool"
"wallet/coincontrol -> wallet/wallet -> wallet/coincontrol"
"wallet/fees -> wallet/wallet -> wallet/fees"
"wallet/wallet -> wallet/walletdb -> wallet/wallet"
"policy/fees -> txmempool -> validation -> policy/fees"
"qt/guiutil -> qt/walletmodel -> qt/optionsmodel -> qt/guiutil"
"txmempool -> validation -> validationinterface -> txmempool"
"wallet/scriptpubkeyman -> wallet/wallet -> wallet/scriptpubkeyman"
)