Bitcoin ABC  0.22.12
P2P Digital Currency
sendcoinsrecipient.h
Go to the documentation of this file.
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 #ifdef ENABLE_BIP70
13 #include <qt/paymentrequestplus.h>
14 #endif
15 
16 #include <amount.h>
17 #include <serialize.h>
18 
19 #include <string>
20 
21 #include <QString>
22 
24 public:
25  explicit SendCoinsRecipient()
26  : amount(), fSubtractFeeFromAmount(false),
28  explicit SendCoinsRecipient(const QString &addr, const QString &_label,
29  const Amount _amount, const QString &_message)
30  : address(addr), label(_label), amount(_amount), message(_message),
33 
34  // If from an unauthenticated payment request, this is used for storing the
35  // addresses, e.g. address-A<br />address-B<br />address-C.
36  // Info: As we don't need to process addresses in here when using payment
37  // requests, we can abuse it for displaying an address list.
38  // TOFO: This is a hack, should be replaced with a cleaner solution!
39  QString address;
40  QString label;
42  // If from a payment request, this is used for storing the memo
43  QString message;
44 
45 #ifdef ENABLE_BIP70
46  // If from a payment request, paymentRequest.IsInitialized() will be true
47  PaymentRequestPlus paymentRequest;
48 #else
49  // If building with BIP70 is disabled, keep the payment request around as
50  // serialized string to ensure load/store is lossless
51  std::string sPaymentRequest;
52 #endif
53  // Empty if no authentication or invalid signature/cert/etc.
55 
56  // memory only
58 
59  static const int CURRENT_VERSION = 1;
60  int nVersion;
61 
63 
64  template <typename Stream, typename Operation>
65  inline void SerializationOp(Stream &s, Operation ser_action) {
66  std::string sAddress = address.toStdString();
67  std::string sLabel = label.toStdString();
68  std::string sMessage = message.toStdString();
69 #ifdef ENABLE_BIP70
70  std::string sPaymentRequest;
71  if (!ser_action.ForRead() && paymentRequest.IsInitialized()) {
72  paymentRequest.SerializeToString(&sPaymentRequest);
73  }
74 #endif
75 
76  std::string sAuthenticatedMerchant =
77  authenticatedMerchant.toStdString();
78 
79  READWRITE(this->nVersion);
80  READWRITE(sAddress);
81  READWRITE(sLabel);
82  READWRITE(amount);
83  READWRITE(sMessage);
84  READWRITE(sPaymentRequest);
85  READWRITE(sAuthenticatedMerchant);
86 
87  if (ser_action.ForRead()) {
88  address = QString::fromStdString(sAddress);
89  label = QString::fromStdString(sLabel);
90  message = QString::fromStdString(sMessage);
91 #ifdef ENABLE_BIP70
92  if (!sPaymentRequest.empty()) {
93  paymentRequest.parse(QByteArray::fromRawData(
94  sPaymentRequest.data(), sPaymentRequest.size()));
95  }
96 #endif
97 
98  authenticatedMerchant =
99  QString::fromStdString(sAuthenticatedMerchant);
100  }
101  }
102 };
103 
104 #endif // BITCOIN_QT_SENDCOINSRECIPIENT_H
SendCoinsRecipient(const QString &addr, const QString &_label, const Amount _amount, const QString &_message)
static const int CURRENT_VERSION
Definition: amount.h:17
bool SerializeToString(std::string *output) const
void SerializationOp(Stream &s, Operation ser_action)
bool parse(const QByteArray &data)
std::string sPaymentRequest
#define READWRITE(...)
Definition: serialize.h:191