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: SendCoinsRecipient()22 explicit SendCoinsRecipient() : amount(0), fSubtractFeeFromAmount(false), nVersion(SendCoinsRecipient::CURRENT_VERSION) { } SendCoinsRecipient(const QString & addr,const QString & _label,const CAmount & _amount,const QString & _message)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> SerializationOp(Stream & s,Operation ser_action)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 75