Bitcoin ABC  0.29.2
P2P Digital Currency
walletmodeltransaction.cpp
Go to the documentation of this file.
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.
4 
5 #ifdef HAVE_CONFIG_H
6 #include <config/bitcoin-config.h>
7 #endif
8 
10 
11 #include <policy/policy.h>
12 
14  const QList<SendCoinsRecipient> &_recipients)
15  : recipients(_recipients), fee() {}
16 
17 QList<SendCoinsRecipient> WalletModelTransaction::getRecipients() const {
18  return recipients;
19 }
20 
22  return wtx;
23 }
24 
26  return wtx ? wtx->GetTotalSize() : 0;
27 }
28 
30  return fee;
31 }
32 
34  fee = newFee;
35 }
36 
37 void WalletModelTransaction::reassignAmounts(int nChangePosRet) {
38  const CTransaction *walletTransaction = wtx.get();
39  int i = 0;
40  for (SendCoinsRecipient &rcp : recipients) {
41 #ifdef ENABLE_BIP70
42  if (rcp.paymentRequest.IsInitialized()) {
43  Amount subtotal = Amount::zero();
44  const payments::PaymentDetails &details =
45  rcp.paymentRequest.getDetails();
46  for (int j = 0; j < details.outputs_size(); j++) {
47  const payments::Output &out = details.outputs(j);
48  if (out.amount() <= 0) {
49  continue;
50  }
51 
52  if (i == nChangePosRet) {
53  i++;
54  }
55 
56  subtotal += walletTransaction->vout[i].nValue;
57  i++;
58  }
59  rcp.amount = subtotal;
60  }
61 
62  // normal recipient (no payment request)
63  else
64 #endif
65  {
66  if (i == nChangePosRet) {
67  i++;
68  }
69 
70  rcp.amount = walletTransaction->vout[i].nValue;
71  i++;
72  }
73  }
74 }
75 
77  Amount totalTransactionAmount = Amount::zero();
78  for (const SendCoinsRecipient &rcp : recipients) {
79  totalTransactionAmount += rcp.amount;
80  }
81  return totalTransactionAmount;
82 }
The basic transaction that is broadcasted on the network and contained in blocks.
Definition: transaction.h:192
const std::vector< CTxOut > vout
Definition: transaction.h:207
void reassignAmounts(int nChangePosRet)
void setTransactionFee(const Amount newFee)
QList< SendCoinsRecipient > getRecipients() const
QList< SendCoinsRecipient > recipients
Amount getTotalTransactionAmount() const
WalletModelTransaction(const QList< SendCoinsRecipient > &recipients)
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:315
Definition: amount.h:19
static constexpr Amount zero() noexcept
Definition: amount.h:32
int64_t amount
Definition: amount.h:21