1 // Copyright (c) 2011-2016 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.
5 #include "walletmodeltransaction.h"
7 #include "policy/policy.h"
8 #include "wallet/wallet.h"
10 WalletModelTransaction::WalletModelTransaction(const QList
<SendCoinsRecipient
> &_recipients
) :
11 recipients(_recipients
),
16 walletTransaction
= new CWalletTx();
19 WalletModelTransaction::~WalletModelTransaction()
22 delete walletTransaction
;
25 QList
<SendCoinsRecipient
> WalletModelTransaction::getRecipients()
30 CWalletTx
*WalletModelTransaction::getTransaction()
32 return walletTransaction
;
35 unsigned int WalletModelTransaction::getTransactionSize()
37 return (!walletTransaction
? 0 : ::GetVirtualTransactionSize(*walletTransaction
));
40 CAmount
WalletModelTransaction::getTransactionFee()
45 void WalletModelTransaction::setTransactionFee(const CAmount
& newFee
)
50 void WalletModelTransaction::reassignAmounts(int nChangePosRet
)
53 for (QList
<SendCoinsRecipient
>::iterator it
= recipients
.begin(); it
!= recipients
.end(); ++it
)
55 SendCoinsRecipient
& rcp
= (*it
);
57 if (rcp
.paymentRequest
.IsInitialized())
60 const payments::PaymentDetails
& details
= rcp
.paymentRequest
.getDetails();
61 for (int j
= 0; j
< details
.outputs_size(); j
++)
63 const payments::Output
& out
= details
.outputs(j
);
64 if (out
.amount() <= 0) continue;
65 if (i
== nChangePosRet
)
67 subtotal
+= walletTransaction
->tx
->vout
[i
].nValue
;
70 rcp
.amount
= subtotal
;
72 else // normal recipient (no payment request)
74 if (i
== nChangePosRet
)
76 rcp
.amount
= walletTransaction
->tx
->vout
[i
].nValue
;
82 CAmount
WalletModelTransaction::getTotalTransactionAmount()
84 CAmount totalTransactionAmount
= 0;
85 for (const SendCoinsRecipient
&rcp
: recipients
)
87 totalTransactionAmount
+= rcp
.amount
;
89 return totalTransactionAmount
;
92 void WalletModelTransaction::newPossibleKeyChange(CWallet
*wallet
)
94 keyChange
= new CReserveKey(wallet
);
97 CReserveKey
*WalletModelTransaction::getPossibleKeyChange()