Raven Core  3.0.0
P2P Digital Currency
walletmodeltransaction.cpp
Go to the documentation of this file.
1 // Copyright (c) 2011-2016 The Bitcoin Core developers
2 // Copyright (c) 2017-2019 The Raven Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
7 
8 #include "policy/policy.h"
9 #include "wallet/wallet.h"
10 
11 WalletModelTransaction::WalletModelTransaction(const QList<SendCoinsRecipient> &_recipients) :
12  recipients(_recipients),
13  walletTransaction(0),
14  keyChange(0),
15  fee(0)
16 {
18 }
19 
21 {
22  delete keyChange;
23  delete walletTransaction;
24 }
25 
26 QList<SendCoinsRecipient> WalletModelTransaction::getRecipients() const
27 {
28  return recipients;
29 }
30 
32 {
33  return walletTransaction;
34 }
35 
37 {
39 }
40 
42 {
43  return fee;
44 }
45 
47 {
48  fee = newFee;
49 }
50 
52 {
53  int i = 0;
54  for (QList<SendCoinsRecipient>::iterator it = recipients.begin(); it != recipients.end(); ++it)
55  {
56  SendCoinsRecipient& rcp = (*it);
57 
58  if (rcp.paymentRequest.IsInitialized())
59  {
60  CAmount subtotal = 0;
61  const payments::PaymentDetails& details = rcp.paymentRequest.getDetails();
62  for (int j = 0; j < details.outputs_size(); j++)
63  {
64  const payments::Output& out = details.outputs(j);
65  if (out.amount() <= 0) continue;
66  if (i == nChangePosRet)
67  i++;
68  subtotal += walletTransaction->tx->vout[i].nValue;
69  i++;
70  }
71  rcp.amount = subtotal;
72  }
73  else // normal recipient (no payment request)
74  {
75  if (i == nChangePosRet)
76  i++;
77  rcp.amount = walletTransaction->tx->vout[i].nValue;
78  i++;
79  }
80  }
81 }
82 
84 {
85  CAmount totalTransactionAmount = 0;
86  for (const SendCoinsRecipient &rcp : recipients)
87  {
88  totalTransactionAmount += rcp.amount;
89  }
90  return totalTransactionAmount;
91 }
92 
94 {
95  keyChange = new CReserveKey(wallet);
96 }
97 
99 {
100  return keyChange;
101 }
int64_t GetVirtualTransactionSize(int64_t nWeight, int64_t nSigOpCost)
Compute the virtual transaction size (weight reinterpreted as bytes).
Definition: policy.cpp:266
PaymentRequestPlus paymentRequest
Definition: walletmodel.h:60
CWalletTx * getTransaction() const
QList< SendCoinsRecipient > getRecipients() const
void newPossibleKeyChange(CWallet *wallet)
void setTransactionFee(const CAmount &newFee)
int64_t CAmount
Amount in corbies (Can be negative)
Definition: amount.h:13
WalletModelTransaction(const QList< SendCoinsRecipient > &recipients)
CTransactionRef tx
Definition: wallet.h:211
void reassignAmounts(int nChangePosRet)
const payments::PaymentDetails & getDetails() const
A transaction with a bunch of additional info that only the owner cares about.
Definition: wallet.h:285
A key allocated from the key pool.
Definition: wallet.h:1193
A CWallet is an extension of a keystore, which also maintains a set of transactions and balances...
Definition: wallet.h:673
CAmount getTotalTransactionAmount() const
QList< SendCoinsRecipient > recipients