Merge #9226: Remove fNetworkNode and pnodeLocalHost.
[bitcoinplatinum.git] / src / qt / walletmodeltransaction.cpp
blobfdec6a1c863a00eeb6eac0ba0fbb62650866eb57
1 // Copyright (c) 2011-2015 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),
12 walletTransaction(0),
13 keyChange(0),
14 fee(0)
16 walletTransaction = new CWalletTx();
19 WalletModelTransaction::~WalletModelTransaction()
21 delete keyChange;
22 delete walletTransaction;
25 QList<SendCoinsRecipient> WalletModelTransaction::getRecipients()
27 return recipients;
30 CWalletTx *WalletModelTransaction::getTransaction()
32 return walletTransaction;
35 unsigned int WalletModelTransaction::getTransactionSize()
37 return (!walletTransaction ? 0 : ::GetVirtualTransactionSize(*walletTransaction));
40 CAmount WalletModelTransaction::getTransactionFee()
42 return fee;
45 void WalletModelTransaction::setTransactionFee(const CAmount& newFee)
47 fee = newFee;
50 void WalletModelTransaction::reassignAmounts(int nChangePosRet)
52 int i = 0;
53 for (QList<SendCoinsRecipient>::iterator it = recipients.begin(); it != recipients.end(); ++it)
55 SendCoinsRecipient& rcp = (*it);
57 if (rcp.paymentRequest.IsInitialized())
59 CAmount subtotal = 0;
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)
66 i++;
67 subtotal += walletTransaction->vout[i].nValue;
68 i++;
70 rcp.amount = subtotal;
72 else // normal recipient (no payment request)
74 if (i == nChangePosRet)
75 i++;
76 rcp.amount = walletTransaction->vout[i].nValue;
77 i++;
82 CAmount WalletModelTransaction::getTotalTransactionAmount()
84 CAmount totalTransactionAmount = 0;
85 Q_FOREACH(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()
99 return keyChange;