Fabcoin Core  0.16.2
P2P Digital Currency
walletmodeltransaction.cpp
Go to the documentation of this file.
1 // Copyright (c) 2011-2017 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 
6 
7 #include <policy/policy.h>
8 #include <wallet/wallet.h>
9 
10 WalletModelTransaction::WalletModelTransaction(const QList<SendCoinsRecipient> &_recipients) :
11  recipients(_recipients),
12  walletTransaction(0),
13  keyChange(0),
14  fee(0)
15 {
17 }
18 
20 {
21  delete keyChange;
22  delete walletTransaction;
23 }
24 
25 QList<SendCoinsRecipient> WalletModelTransaction::getRecipients()
26 {
27  return recipients;
28 }
29 
31 {
32  return walletTransaction;
33 }
34 
36 {
38 }
39 
41 {
42  return fee;
43 }
44 
46 {
47  fee = newFee;
48 }
49 
51 {
52  int i = 0;
53  for (QList<SendCoinsRecipient>::iterator it = recipients.begin(); it != recipients.end(); ++it)
54  {
55  SendCoinsRecipient& rcp = (*it);
56 
57  if (rcp.paymentRequest.IsInitialized())
58  {
59  CAmount subtotal = 0;
60  const payments::PaymentDetails& details = rcp.paymentRequest.getDetails();
61  for (int j = 0; j < details.outputs_size(); j++)
62  {
63  const payments::Output& out = details.outputs(j);
64  if (out.amount() <= 0) continue;
65  if (i == nChangePosRet)
66  i++;
67  subtotal += walletTransaction->tx->vout[i].nValue;
68  i++;
69  }
70  rcp.amount = subtotal;
71  }
72  else // normal recipient (no payment request)
73  {
74  if (i == nChangePosRet)
75  i++;
76  rcp.amount = walletTransaction->tx->vout[i].nValue;
77  i++;
78  }
79  }
80 }
81 
83 {
84  CAmount totalTransactionAmount = 0;
85  for (const SendCoinsRecipient &rcp : recipients)
86  {
87  totalTransactionAmount += rcp.amount;
88  }
89  return totalTransactionAmount;
90 }
91 
93 {
94  keyChange = new CReserveKey(wallet);
95 }
96 
98 {
99  return keyChange;
100 }
int64_t GetVirtualTransactionSize(int64_t nWeight, int64_t nSigOpCost)
Compute the virtual transaction size (weight reinterpreted as bytes).
Definition: policy.cpp:254
PaymentRequestPlus paymentRequest
Definition: walletmodel.h:61
bool IsInitialized() const
void newPossibleKeyChange(CWallet *wallet)
void setTransactionFee(const CAmount &newFee)
int64_t CAmount
Amount in lius (Can be negative)
Definition: amount.h:15
WalletModelTransaction(const QList< SendCoinsRecipient > &recipients)
QList< SendCoinsRecipient > getRecipients()
CTransactionRef tx
Definition: wallet.h:211
void reassignAmounts(int nChangePosRet)
const ::payments::Output & outputs(int index) const
const payments::PaymentDetails & getDetails() const
inline::google::protobuf::uint64 amount() const
A transaction with a bunch of additional info that only the owner cares about.
Definition: wallet.h:287
A key allocated from the key pool.
Definition: wallet.h:1209
A CWallet is an extension of a keystore, which also maintains a set of transactions and balances...
Definition: wallet.h:672
QList< SendCoinsRecipient > recipients