diff --git a/src/qt/walletmodeltransaction.cpp b/src/qt/walletmodeltransaction.cpp index 6b767c949b..68afbe7244 100644 --- a/src/qt/walletmodeltransaction.cpp +++ b/src/qt/walletmodeltransaction.cpp @@ -1,89 +1,88 @@ // Copyright (c) 2011-2016 The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include "walletmodeltransaction.h" #include "policy/policy.h" #include "wallet/wallet.h" WalletModelTransaction::WalletModelTransaction( const QList &_recipients) - : recipients(_recipients), walletTransaction(0), keyChange(0), fee() { + : recipients(_recipients), walletTransaction(0), fee() { walletTransaction = new CWalletTx(); } WalletModelTransaction::~WalletModelTransaction() { - delete keyChange; delete walletTransaction; } QList WalletModelTransaction::getRecipients() const { return recipients; } CWalletTx *WalletModelTransaction::getTransaction() const { return walletTransaction; } unsigned int WalletModelTransaction::getTransactionSize() { return !walletTransaction ? 0 : CTransaction(*walletTransaction).GetTotalSize(); } Amount WalletModelTransaction::getTransactionFee() const { return fee; } void WalletModelTransaction::setTransactionFee(const Amount newFee) { fee = newFee; } void WalletModelTransaction::reassignAmounts(int nChangePosRet) { int i = 0; for (SendCoinsRecipient &rcp : recipients) { if (rcp.paymentRequest.IsInitialized()) { Amount subtotal = Amount::zero(); const payments::PaymentDetails &details = rcp.paymentRequest.getDetails(); for (int j = 0; j < details.outputs_size(); j++) { const payments::Output &out = details.outputs(j); if (out.amount() <= 0) { continue; } if (i == nChangePosRet) { i++; } subtotal += walletTransaction->tx->vout[i].nValue; i++; } rcp.amount = subtotal; } else { // normal recipient (no payment request) if (i == nChangePosRet) { i++; } rcp.amount = walletTransaction->tx->vout[i].nValue; i++; } } } Amount WalletModelTransaction::getTotalTransactionAmount() const { Amount totalTransactionAmount = Amount::zero(); for (const SendCoinsRecipient &rcp : recipients) { totalTransactionAmount += rcp.amount; } return totalTransactionAmount; } void WalletModelTransaction::newPossibleKeyChange(CWallet *wallet) { - keyChange = new CReserveKey(wallet); + keyChange.reset(new CReserveKey(wallet)); } CReserveKey *WalletModelTransaction::getPossibleKeyChange() { - return keyChange; + return keyChange.get(); } diff --git a/src/qt/walletmodeltransaction.h b/src/qt/walletmodeltransaction.h index 91c32456a6..5a0d98ce77 100644 --- a/src/qt/walletmodeltransaction.h +++ b/src/qt/walletmodeltransaction.h @@ -1,48 +1,48 @@ // Copyright (c) 2011-2014 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_WALLETMODELTRANSACTION_H #define BITCOIN_QT_WALLETMODELTRANSACTION_H #include "walletmodel.h" #include class SendCoinsRecipient; class CReserveKey; class CWallet; class CWalletTx; /** Data model for a walletmodel transaction. */ class WalletModelTransaction { public: explicit WalletModelTransaction( const QList &recipients); ~WalletModelTransaction(); QList getRecipients() const; CWalletTx *getTransaction() const; unsigned int getTransactionSize(); void setTransactionFee(const Amount newFee); Amount getTransactionFee() const; Amount getTotalTransactionAmount() const; void newPossibleKeyChange(CWallet *wallet); CReserveKey *getPossibleKeyChange(); // needed for the subtract-fee-from-amount feature void reassignAmounts(int nChangePosRet); private: QList recipients; CWalletTx *walletTransaction; - CReserveKey *keyChange; + std::unique_ptr keyChange; Amount fee; }; #endif // BITCOIN_QT_WALLETMODELTRANSACTION_H