Skip to content

Commit 73b5505

Browse files
hebastoinstagibbs
andcommitted
refactor: Move SendCoinsRecipient in own header
Co-authored-by: Gregory Sanders <[email protected]>
1 parent 3052130 commit 73b5505

11 files changed

+84
-57
lines changed

src/Makefile.qt.include

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ BITCOIN_QT_H = \
136136
qt/rpcconsole.h \
137137
qt/sendcoinsdialog.h \
138138
qt/sendcoinsentry.h \
139+
qt/sendcoinsrecipient.h \
139140
qt/signverifymessagedialog.h \
140141
qt/splashscreen.h \
141142
qt/trafficgraphwidget.h \

src/qt/guiutil.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <qt/bitcoinaddressvalidator.h>
88
#include <qt/bitcoinunits.h>
99
#include <qt/qvalidatedlineedit.h>
10+
#include <qt/sendcoinsrecipient.h>
1011
#include <qt/walletmodel.h>
1112

1213
#include <base58.h>

src/qt/openuridialog.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <qt/forms/ui_openuridialog.h>
77

88
#include <qt/guiutil.h>
9+
#include <qt/sendcoinsrecipient.h>
910
#include <qt/walletmodel.h>
1011

1112
#include <QUrl>

src/qt/paymentserver.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include <config/bitcoin-config.h>
3737
#endif
3838

39+
#include <qt/sendcoinsrecipient.h>
3940
#include <qt/walletmodel.h>
4041

4142
#include <QObject>

src/qt/receiverequestdialog.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#ifndef BITCOIN_QT_RECEIVEREQUESTDIALOG_H
66
#define BITCOIN_QT_RECEIVEREQUESTDIALOG_H
77

8+
#include <qt/sendcoinsrecipient.h>
89
#include <qt/walletmodel.h>
910

1011
#include <QDialog>

src/qt/recentrequeststablemodel.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#ifndef BITCOIN_QT_RECENTREQUESTSTABLEMODEL_H
66
#define BITCOIN_QT_RECENTREQUESTSTABLEMODEL_H
77

8+
#include <qt/sendcoinsrecipient.h>
89
#include <qt/walletmodel.h>
910

1011
#include <QAbstractTableModel>

src/qt/sendcoinsentry.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#ifndef BITCOIN_QT_SENDCOINSENTRY_H
66
#define BITCOIN_QT_SENDCOINSENTRY_H
77

8+
#include <qt/sendcoinsrecipient.h>
89
#include <qt/walletmodel.h>
910

1011
#include <QStackedWidget>

src/qt/sendcoinsrecipient.h

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// Copyright (c) 2011-2019 The Bitcoin Core developers
2+
// Distributed under the MIT software license, see the accompanying
3+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4+
5+
#ifndef BITCOIN_QT_SENDCOINSRECIPIENT_H
6+
#define BITCOIN_QT_SENDCOINSRECIPIENT_H
7+
8+
#if defined(HAVE_CONFIG_H)
9+
#include <config/bitcoin-config.h>
10+
#endif
11+
12+
#include <amount.h>
13+
#include <serialize.h>
14+
15+
#include <string>
16+
17+
#include <QString>
18+
19+
class SendCoinsRecipient
20+
{
21+
public:
22+
explicit SendCoinsRecipient() : amount(0), fSubtractFeeFromAmount(false), nVersion(SendCoinsRecipient::CURRENT_VERSION) { }
23+
explicit SendCoinsRecipient(const QString &addr, const QString &_label, const CAmount& _amount, const QString &_message):
24+
address(addr), label(_label), amount(_amount), message(_message), fSubtractFeeFromAmount(false), nVersion(SendCoinsRecipient::CURRENT_VERSION) {}
25+
26+
// If from an unauthenticated payment request, this is used for storing
27+
// the addresses, e.g. address-A<br />address-B<br />address-C.
28+
// Info: As we don't need to process addresses in here when using
29+
// payment requests, we can abuse it for displaying an address list.
30+
// Todo: This is a hack, should be replaced with a cleaner solution!
31+
QString address;
32+
QString label;
33+
CAmount amount;
34+
// If from a payment request, this is used for storing the memo
35+
QString message;
36+
// Keep the payment request around as a serialized string to ensure
37+
// load/store is lossless.
38+
std::string sPaymentRequest;
39+
// Empty if no authentication or invalid signature/cert/etc.
40+
QString authenticatedMerchant;
41+
42+
bool fSubtractFeeFromAmount; // memory only
43+
44+
static const int CURRENT_VERSION = 1;
45+
int nVersion;
46+
47+
ADD_SERIALIZE_METHODS;
48+
49+
template <typename Stream, typename Operation>
50+
inline void SerializationOp(Stream& s, Operation ser_action) {
51+
std::string sAddress = address.toStdString();
52+
std::string sLabel = label.toStdString();
53+
std::string sMessage = message.toStdString();
54+
std::string sAuthenticatedMerchant = authenticatedMerchant.toStdString();
55+
56+
READWRITE(this->nVersion);
57+
READWRITE(sAddress);
58+
READWRITE(sLabel);
59+
READWRITE(amount);
60+
READWRITE(sMessage);
61+
READWRITE(sPaymentRequest);
62+
READWRITE(sAuthenticatedMerchant);
63+
64+
if (ser_action.ForRead())
65+
{
66+
address = QString::fromStdString(sAddress);
67+
label = QString::fromStdString(sLabel);
68+
message = QString::fromStdString(sMessage);
69+
authenticatedMerchant = QString::fromStdString(sAuthenticatedMerchant);
70+
}
71+
}
72+
};
73+
74+
#endif // BITCOIN_QT_SENDCOINSRECIPIENT_H

src/qt/walletcontroller.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#ifndef BITCOIN_QT_WALLETCONTROLLER_H
66
#define BITCOIN_QT_WALLETCONTROLLER_H
77

8+
#include <qt/sendcoinsrecipient.h>
89
#include <qt/walletmodel.h>
910
#include <support/allocators/secure.h>
1011
#include <sync.h>

src/qt/walletmodel.h

Lines changed: 1 addition & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99
#include <config/bitcoin-config.h>
1010
#endif
1111

12-
#include <amount.h>
1312
#include <key.h>
14-
#include <serialize.h>
1513
#include <script/standard.h>
1614

1715
#include <qt/walletmodeltransaction.h>
@@ -29,6 +27,7 @@ class AddressTableModel;
2927
class OptionsModel;
3028
class PlatformStyle;
3129
class RecentRequestsTableModel;
30+
class SendCoinsRecipient;
3231
class TransactionTableModel;
3332
class WalletModelTransaction;
3433

@@ -47,61 +46,6 @@ QT_BEGIN_NAMESPACE
4746
class QTimer;
4847
QT_END_NAMESPACE
4948

50-
class SendCoinsRecipient
51-
{
52-
public:
53-
explicit SendCoinsRecipient() : amount(0), fSubtractFeeFromAmount(false), nVersion(SendCoinsRecipient::CURRENT_VERSION) { }
54-
explicit SendCoinsRecipient(const QString &addr, const QString &_label, const CAmount& _amount, const QString &_message):
55-
address(addr), label(_label), amount(_amount), message(_message), fSubtractFeeFromAmount(false), nVersion(SendCoinsRecipient::CURRENT_VERSION) {}
56-
57-
// If from an unauthenticated payment request, this is used for storing
58-
// the addresses, e.g. address-A<br />address-B<br />address-C.
59-
// Info: As we don't need to process addresses in here when using
60-
// payment requests, we can abuse it for displaying an address list.
61-
// Todo: This is a hack, should be replaced with a cleaner solution!
62-
QString address;
63-
QString label;
64-
CAmount amount;
65-
// If from a payment request, this is used for storing the memo
66-
QString message;
67-
// Keep the payment request around as a serialized string to ensure
68-
// load/store is lossless.
69-
std::string sPaymentRequest;
70-
// Empty if no authentication or invalid signature/cert/etc.
71-
QString authenticatedMerchant;
72-
73-
bool fSubtractFeeFromAmount; // memory only
74-
75-
static const int CURRENT_VERSION = 1;
76-
int nVersion;
77-
78-
ADD_SERIALIZE_METHODS;
79-
80-
template <typename Stream, typename Operation>
81-
inline void SerializationOp(Stream& s, Operation ser_action) {
82-
std::string sAddress = address.toStdString();
83-
std::string sLabel = label.toStdString();
84-
std::string sMessage = message.toStdString();
85-
std::string sAuthenticatedMerchant = authenticatedMerchant.toStdString();
86-
87-
READWRITE(this->nVersion);
88-
READWRITE(sAddress);
89-
READWRITE(sLabel);
90-
READWRITE(amount);
91-
READWRITE(sMessage);
92-
READWRITE(sPaymentRequest);
93-
READWRITE(sAuthenticatedMerchant);
94-
95-
if (ser_action.ForRead())
96-
{
97-
address = QString::fromStdString(sAddress);
98-
label = QString::fromStdString(sLabel);
99-
message = QString::fromStdString(sMessage);
100-
authenticatedMerchant = QString::fromStdString(sAuthenticatedMerchant);
101-
}
102-
}
103-
};
104-
10549
/** Interface to Bitcoin wallet from Qt view code. */
10650
class WalletModel : public QObject
10751
{

0 commit comments

Comments
 (0)