Bitcoin Core  0.18.99
P2P Digital Currency
walletmodeltransaction.cpp
Go to the documentation of this file.
1 // Copyright (c) 2011-2018 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 #ifdef HAVE_CONFIG_H
7 #endif
8 
10 
11 #include <policy/policy.h>
12 
13 WalletModelTransaction::WalletModelTransaction(const QList<SendCoinsRecipient> &_recipients) :
14  recipients(_recipients),
15  fee(0)
16 {
17 }
18 
19 QList<SendCoinsRecipient> WalletModelTransaction::getRecipients() const
20 {
21  return recipients;
22 }
23 
25 {
26  return wtx;
27 }
28 
30 {
31  return wtx ? GetVirtualTransactionSize(*wtx) : 0;
32 }
33 
35 {
36  return fee;
37 }
38 
40 {
41  fee = newFee;
42 }
43 
45 {
46  const CTransaction* walletTransaction = wtx.get();
47  int i = 0;
48  for (QList<SendCoinsRecipient>::iterator it = recipients.begin(); it != recipients.end(); ++it)
49  {
50  SendCoinsRecipient& rcp = (*it);
51 
52 #ifdef ENABLE_BIP70
53  if (rcp.paymentRequest.IsInitialized())
54  {
55  CAmount subtotal = 0;
56  const payments::PaymentDetails& details = rcp.paymentRequest.getDetails();
57  for (int j = 0; j < details.outputs_size(); j++)
58  {
59  const payments::Output& out = details.outputs(j);
60  if (out.amount() <= 0) continue;
61  if (i == nChangePosRet)
62  i++;
63  subtotal += walletTransaction->vout[i].nValue;
64  i++;
65  }
66  rcp.amount = subtotal;
67  }
68  else // normal recipient (no payment request)
69 #endif
70  {
71  if (i == nChangePosRet)
72  i++;
73  rcp.amount = walletTransaction->vout[i].nValue;
74  i++;
75  }
76  }
77 }
78 
80 {
81  CAmount totalTransactionAmount = 0;
82  for (const SendCoinsRecipient &rcp : recipients)
83  {
84  totalTransactionAmount += rcp.amount;
85  }
86  return totalTransactionAmount;
87 }
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:408
QList< SendCoinsRecipient > getRecipients() const
int64_t GetVirtualTransactionSize(int64_t nWeight, int64_t nSigOpCost, unsigned int bytes_per_sigop)
Compute the virtual transaction size (weight reinterpreted as bytes).
Definition: policy.cpp:238
void setTransactionFee(const CAmount &newFee)
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
WalletModelTransaction(const QList< SendCoinsRecipient > &recipients)
void reassignAmounts(int nChangePosRet)
const std::vector< CTxOut > vout
Definition: transaction.h:288
CAmount getTotalTransactionAmount() const
The basic transaction that is broadcasted on the network and contained in blocks. ...
Definition: transaction.h:270
auto it
Definition: validation.cpp:366
QList< SendCoinsRecipient > recipients