Bitcoin ABC  0.22.12
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 }
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:338
static constexpr Amount zero()
Definition: amount.h:35
Amount getTotalTransactionAmount() const
Definition: amount.h:17
QList< SendCoinsRecipient > getRecipients() const
void setTransactionFee(const Amount newFee)
WalletModelTransaction(const QList< SendCoinsRecipient > &recipients)
void reassignAmounts(int nChangePosRet)
const std::vector< CTxOut > vout
Definition: transaction.h:228
int64_t amount
Definition: amount.h:19
The basic transaction that is broadcasted on the network and contained in blocks. ...
Definition: transaction.h:211
QList< SendCoinsRecipient > recipients