BSHA3  0.17.99
P2P Blockchain, based on Bitcoin
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 <interfaces/node.h>
12 #include <policy/policy.h>
13 
14 WalletModelTransaction::WalletModelTransaction(const QList<SendCoinsRecipient> &_recipients) :
15  recipients(_recipients),
16  fee(0)
17 {
18 }
19 
20 QList<SendCoinsRecipient> WalletModelTransaction::getRecipients() const
21 {
22  return recipients;
23 }
24 
25 std::unique_ptr<interfaces::PendingWalletTx>& WalletModelTransaction::getWtx()
26 {
27  return wtx;
28 }
29 
31 {
32  return wtx ? wtx->getVirtualSize() : 0;
33 }
34 
36 {
37  return fee;
38 }
39 
41 {
42  fee = newFee;
43 }
44 
46 {
47  const CTransaction* walletTransaction = &wtx->get();
48  int i = 0;
49  for (QList<SendCoinsRecipient>::iterator it = recipients.begin(); it != recipients.end(); ++it)
50  {
51  SendCoinsRecipient& rcp = (*it);
52 
53 #ifdef ENABLE_BIP70
54  if (rcp.paymentRequest.IsInitialized())
55  {
56  CAmount subtotal = 0;
57  const payments::PaymentDetails& details = rcp.paymentRequest.getDetails();
58  for (int j = 0; j < details.outputs_size(); j++)
59  {
60  const payments::Output& out = details.outputs(j);
61  if (out.amount() <= 0) continue;
62  if (i == nChangePosRet)
63  i++;
64  subtotal += walletTransaction->vout[i].nValue;
65  i++;
66  }
67  rcp.amount = subtotal;
68  }
69  else // normal recipient (no payment request)
70 #endif
71  {
72  if (i == nChangePosRet)
73  i++;
74  rcp.amount = walletTransaction->vout[i].nValue;
75  i++;
76  }
77  }
78 }
79 
81 {
82  CAmount totalTransactionAmount = 0;
83  for (const SendCoinsRecipient &rcp : recipients)
84  {
85  totalTransactionAmount += rcp.amount;
86  }
87  return totalTransactionAmount;
88 }
std::unique_ptr< interfaces::PendingWalletTx > & getWtx()
QList< SendCoinsRecipient > getRecipients() const
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:282
std::unique_ptr< interfaces::PendingWalletTx > wtx
CAmount getTotalTransactionAmount() const
The basic transaction that is broadcasted on the network and contained in blocks. ...
Definition: transaction.h:264
QList< SendCoinsRecipient > recipients