sendcoinsrecipient.h raw
1 // Copyright (c) 2011-present 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 #include <consensus/amount.h>
9 #include <serialize.h>
10
11 #include <string>
12
13 #include <QString>
14
15 class SendCoinsRecipient
16 {
17 public:
18 explicit SendCoinsRecipient() : amount(0), fSubtractFeeFromAmount(false), nVersion(SendCoinsRecipient::CURRENT_VERSION) { }
19 explicit SendCoinsRecipient(const QString &addr, const QString &_label, const CAmount& _amount, const QString &_message):
20 address(addr), label(_label), amount(_amount), message(_message), fSubtractFeeFromAmount(false), nVersion(SendCoinsRecipient::CURRENT_VERSION) {}
21
22 // If from an unauthenticated payment request, this is used for storing
23 // the addresses, e.g. address-A<br />address-B<br />address-C.
24 // Info: As we don't need to process addresses in here when using
25 // payment requests, we can abuse it for displaying an address list.
26 // Todo: This is a hack, should be replaced with a cleaner solution!
27 QString address;
28 QString label;
29 CAmount amount;
30 // If from a payment request, this is used for storing the memo
31 QString message;
32 // Keep the payment request around as a serialized string to ensure
33 // load/store is lossless.
34 std::string sPaymentRequest;
35 // Empty if no authentication or invalid signature/cert/etc.
36 QString authenticatedMerchant;
37
38 bool fSubtractFeeFromAmount; // memory only
39
40 static const int CURRENT_VERSION = 1;
41 int nVersion;
42
43 SERIALIZE_METHODS(SendCoinsRecipient, obj)
44 {
45 std::string address_str, label_str, message_str, auth_merchant_str;
46
47 SER_WRITE(obj, address_str = obj.address.toStdString());
48 SER_WRITE(obj, label_str = obj.label.toStdString());
49 SER_WRITE(obj, message_str = obj.message.toStdString());
50 SER_WRITE(obj, auth_merchant_str = obj.authenticatedMerchant.toStdString());
51
52 READWRITE(obj.nVersion, address_str, label_str, obj.amount, message_str, obj.sPaymentRequest, auth_merchant_str);
53
54 SER_READ(obj, obj.address = QString::fromStdString(address_str));
55 SER_READ(obj, obj.label = QString::fromStdString(label_str));
56 SER_READ(obj, obj.message = QString::fromStdString(message_str));
57 SER_READ(obj, obj.authenticatedMerchant = QString::fromStdString(auth_merchant_str));
58 }
59 };
60
61 #endif // BITCOIN_QT_SENDCOINSRECIPIENT_H
62