Dash Core Source Documentation (0.16.0.1)

Find detailed information regarding the Dash Core source code.

walletmodeltransaction.cpp
Go to the documentation of this file.
1 // Copyright (c) 2011-2015 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 
6 
7 #include <wallet/wallet.h>
8 
9 WalletModelTransaction::WalletModelTransaction(const QList<SendCoinsRecipient> &_recipients) :
10  recipients(_recipients),
11  walletTransaction(0),
12  fee(0)
13 {
15 }
16 
18 {
19  delete walletTransaction;
20 }
21 
22 QList<SendCoinsRecipient> WalletModelTransaction::getRecipients() const
23 {
24  return recipients;
25 }
26 
28 {
29  return walletTransaction;
30 }
31 
33 {
35 }
36 
38 {
39  return fee;
40 }
41 
43 {
44  fee = newFee;
45 }
46 
48 {
49  // For each recipient look for a matching CTxOut in walletTransaction and reassign amounts
50  for (QList<SendCoinsRecipient>::iterator it = recipients.begin(); it != recipients.end(); ++it)
51  {
52  SendCoinsRecipient& rcp = (*it);
53 
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  const unsigned char* scriptStr = (const unsigned char*)out.script().data();
63  CScript scriptPubKey(scriptStr, scriptStr+out.script().size());
64  for (const auto& txout : walletTransaction->tx->vout) {
65  if (txout.scriptPubKey == scriptPubKey) {
66  subtotal += txout.nValue;
67  break;
68  }
69  }
70  }
71  rcp.amount = subtotal;
72  }
73  else // normal recipient (no payment request)
74  {
75  for (const auto& txout : walletTransaction->tx->vout) {
76  CScript scriptPubKey = GetScriptForDestination(DecodeDestination(rcp.address.toStdString()));
77  if (txout.scriptPubKey == scriptPubKey) {
78  rcp.amount = txout.nValue;
79  break;
80  }
81  }
82  }
83  }
84 }
85 
87 {
88  CAmount totalTransactionAmount = 0;
89  for (const SendCoinsRecipient &rcp : recipients)
90  {
91  totalTransactionAmount += rcp.amount;
92  }
93  return totalTransactionAmount;
94 }
95 
97 {
98  keyChange.reset(new CReserveKey(wallet));
99 }
100 
102 {
103  return keyChange.get();
104 }
PaymentRequestPlus paymentRequest
Definition: walletmodel.h:58
CWalletTx * getTransaction() const
size_t GetSerializeSize(const T &t, int nType, int nVersion=0)
Definition: serialize.h:1295
CTxDestination DecodeDestination(const std::string &str)
Definition: base58.cpp:336
std::unique_ptr< CReserveKey > keyChange
QList< SendCoinsRecipient > getRecipients() const
void newPossibleKeyChange(CWallet *wallet)
void setTransactionFee(const CAmount &newFee)
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
WalletModelTransaction(const QList< SendCoinsRecipient > &recipients)
CTransactionRef tx
Definition: wallet.h:210
const payments::PaymentDetails & getDetails() const
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
Definition: standard.cpp:256
A transaction with a bunch of additional info that only the owner cares about.
Definition: wallet.h:280
A key allocated from the key pool.
Definition: wallet.h:1273
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:389
static const int PROTOCOL_VERSION
network protocol versioning
Definition: version.h:14
A CWallet is an extension of a keystore, which also maintains a set of transactions and balances...
Definition: wallet.h:715
CAmount getTotalTransactionAmount() const
QList< SendCoinsRecipient > recipients
Released under the MIT license