Bitcoin ABC  0.24.7
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 }
WalletModelTransaction::fee
Amount fee
Definition: walletmodeltransaction.h:43
policy.h
WalletModelTransaction::getTotalTransactionAmount
Amount getTotalTransactionAmount() const
Definition: walletmodeltransaction.cpp:76
WalletModelTransaction::recipients
QList< SendCoinsRecipient > recipients
Definition: walletmodeltransaction.h:41
WalletModelTransaction::getTransactionSize
unsigned int getTransactionSize()
Definition: walletmodeltransaction.cpp:25
WalletModelTransaction::wtx
CTransactionRef wtx
Definition: walletmodeltransaction.h:42
CTransaction
The basic transaction that is broadcasted on the network and contained in blocks.
Definition: transaction.h:194
Amount::zero
static constexpr Amount zero()
Definition: amount.h:42
WalletModelTransaction::WalletModelTransaction
WalletModelTransaction(const QList< SendCoinsRecipient > &recipients)
Definition: walletmodeltransaction.cpp:13
SendCoinsRecipient
Definition: sendcoinsrecipient.h:23
CTransaction::vout
const std::vector< CTxOut > vout
Definition: transaction.h:211
WalletModelTransaction::getTransactionFee
Amount getTransactionFee() const
Definition: walletmodeltransaction.cpp:29
Amount::amount
int64_t amount
Definition: amount.h:21
Amount
Definition: amount.h:19
WalletModelTransaction::getRecipients
QList< SendCoinsRecipient > getRecipients() const
Definition: walletmodeltransaction.cpp:17
walletmodeltransaction.h
CTransactionRef
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:319
WalletModelTransaction::getWtx
CTransactionRef & getWtx()
Definition: walletmodeltransaction.cpp:21
WalletModelTransaction::setTransactionFee
void setTransactionFee(const Amount newFee)
Definition: walletmodeltransaction.cpp:33
WalletModelTransaction::reassignAmounts
void reassignAmounts(int nChangePosRet)
Definition: walletmodeltransaction.cpp:37