PIVX Core  5.6.99
P2P Digital Currency
transactionrecord.h
Go to the documentation of this file.
1 // Copyright (c) 2011-2014 The Bitcoin developers
2 // Copyright (c) 2014-2016 The Dash developers
3 // Copyright (c) 2016-2021 The PIVX Core developers
4 // Distributed under the MIT/X11 software license, see the accompanying
5 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
6 
7 #ifndef PIVX_QT_TRANSACTIONRECORD_H
8 #define PIVX_QT_TRANSACTIONRECORD_H
9 
10 #include "amount.h"
11 #include "script/script.h"
12 #include "optional.h"
13 #include "uint256.h"
14 
15 #include <QList>
16 #include <QString>
17 
18 class CWallet;
19 class CWalletTx;
20 
24 {
25 public:
28  {
29  }
30 
31  enum Status : uint16_t{
32  Confirmed = 0,
42  };
43 
47  std::string sortKey;
48 
57  qint64 depth;
58  qint64 open_for;
65 
67 };
68 
73 {
74 public:
75  enum Type : uint16_t {
76  Other = 0,
92  StakeDelegated, // Received cold stake (owner)
93  StakeHot, // Staked via a delegated P2CS.
94  P2CSDelegation, // Non-spendable P2CS, staker side.
95  P2CSDelegationSent, // Non-spendable P2CS delegated utxo. (coin-owner transferred ownership to external wallet)
96  P2CSDelegationSentOwner, // Spendable P2CS delegated utxo. (coin-owner)
97  P2CSUnlockOwner, // Coin-owner spent the delegated utxo
98  P2CSUnlockStaker, // Staker watching the owner spent the delegated utxo
99  SendToShielded, // Shielded send
100  RecvWithShieldedAddress, // Shielded receive
101  RecvWithShieldedAddressMemo, // Shielded receive with memo
102  SendToSelfShieldedAddress, // Shielded send to self
103  SendToSelfShieldToTransparent, // Unshield coins to self
104  SendToSelfShieldToShieldChangeAddress, // Changing coins from one shielded address to another inside the wallet.
105  SendToNobody // Burned PIVs, op_return output.
106  };
107 
109  static const int RecommendedNumConfirmations = 6;
110 
111  explicit TransactionRecord(unsigned int size) : hash(), time(0), type(Other), address(""), debit(0), credit(0), size(size), idx(0)
112  {
113  }
114 
115  TransactionRecord(uint256 hash, qint64 time, unsigned int size) : hash(hash), time(time), type(Other), address(""), debit(0),
116  credit(0), size(size), idx(0)
117  {
118  }
119 
120  TransactionRecord(uint256 hash, qint64 time, unsigned int size, Type type, const std::string& address, const CAmount& debit, const CAmount& credit) : hash(hash), time(time), type(type), address(address), debit(debit), credit(credit),
121  size(size), idx(0)
122  {
123  }
124 
127  static QList<TransactionRecord> decomposeTransaction(const CWallet* wallet, const CWalletTx& wtx);
128 
130  static bool decomposeCoinStake(const CWallet* wallet, const CWalletTx& wtx,
131  const CAmount& nCredit, const CAmount& nDebit,
132  QList<TransactionRecord>& parts);
133 
134  static bool decomposeZcSpendTx(const CWallet* wallet, const CWalletTx& wtx,
135  const CAmount& nCredit, const CAmount& nDebit,
136  QList<TransactionRecord>& parts);
137 
138  static bool decomposeP2CS(const CWallet* wallet, const CWalletTx& wtx,
139  const CAmount& nCredit, const CAmount& nDebit,
140  QList<TransactionRecord>& parts);
141 
142  static bool decomposeCreditTransaction(const CWallet* wallet, const CWalletTx& wtx,
143  QList<TransactionRecord>& parts);
144 
145  static bool decomposeSendToSelfTransaction(const CWalletTx& wtx, const CAmount& nCredit,
146  const CAmount& nDebit, bool involvesWatchAddress,
147  QList<TransactionRecord>& parts, const CWallet* wallet);
148 
149  static bool decomposeDebitTransaction(const CWallet* wallet, const CWalletTx& wtx,
150  const CAmount& nDebit, bool involvesWatchAddress,
151  QList<TransactionRecord>& parts);
152 
153  static bool decomposeShieldedDebitTransaction(const CWallet* wallet, const CWalletTx& wtx, CAmount nTxFee,
154  bool involvesWatchAddress, QList<TransactionRecord>& parts);
155 
156  static std::string getValueOrReturnEmpty(const std::map<std::string, std::string>& mapValue, const std::string& key);
157  static void loadHotOrColdStakeOrContract(const CWallet* wallet, const CWalletTx& wtx,
158  TransactionRecord& record, bool isContract = false);
159  static void loadUnlockColdStake(const CWallet* wallet, const CWalletTx& wtx, TransactionRecord& record);
160 
164  qint64 time;
166  std::string address;
169  unsigned int size;
175  int idx;
176 
179 
181  bool involvesWatchAddress{false};
182 
184  int getOutputIndex() const;
185 
188  void updateStatus(const CWalletTx& wtx, int chainHeight);
189 
192  bool statusUpdateNeeded(int blockHeight) const;
193 
196  std::string statusToString();
197 
200  bool isCoinStake() const;
201 
203  bool isMNReward() const;
204 
207  bool isAnyColdStakingType() const;
208 
211  bool isNull() const;
212 
213 };
214 
215 #endif // PIVX_QT_TRANSACTIONRECORD_H
int64_t CAmount
Amount in PIV (Can be negative)
Definition: amount.h:13
false
Definition: bls_dkg.cpp:151
A CWallet is an extension of a keystore, which also maintains a set of transactions and balances,...
Definition: wallet.h:577
A transaction with a bunch of additional info that only the owner cares about.
Definition: wallet.h:325
UI model for a transaction.
TransactionRecord(unsigned int size)
bool isMNReward() const
Return true if the tx is a MN reward.
static bool decomposeShieldedDebitTransaction(const CWallet *wallet, const CWalletTx &wtx, CAmount nTxFee, bool involvesWatchAddress, QList< TransactionRecord > &parts)
std::string statusToString()
Return transaction status.
TransactionRecord(uint256 hash, qint64 time, unsigned int size, Type type, const std::string &address, const CAmount &debit, const CAmount &credit)
static std::string getValueOrReturnEmpty(const std::map< std::string, std::string > &mapValue, const std::string &key)
int idx
Subtransaction index, for sort key.
static void loadHotOrColdStakeOrContract(const CWallet *wallet, const CWalletTx &wtx, TransactionRecord &record, bool isContract=false)
static const int RecommendedNumConfirmations
Number of confirmation recommended for accepting a transaction.
Optional< CAmount > shieldedCredit
bool isCoinStake() const
Return true if the tx is a coinstake.
static void loadUnlockColdStake(const CWallet *wallet, const CWalletTx &wtx, TransactionRecord &record)
TransactionStatus status
Status: can change with block chain update.
void updateStatus(const CWalletTx &wtx, int chainHeight)
Update status from core wallet tx.
int getOutputIndex() const
Return the output index of the subtransaction
static bool decomposeCoinStake(const CWallet *wallet, const CWalletTx &wtx, const CAmount &nCredit, const CAmount &nDebit, QList< TransactionRecord > &parts)
Helpers.
static bool decomposeZcSpendTx(const CWallet *wallet, const CWalletTx &wtx, const CAmount &nCredit, const CAmount &nDebit, QList< TransactionRecord > &parts)
bool isAnyColdStakingType() const
Return true if the tx is a any cold staking type tx.
static bool decomposeCreditTransaction(const CWallet *wallet, const CWalletTx &wtx, QList< TransactionRecord > &parts)
Decompose a credit transaction into a record for each received output.
static bool decomposeDebitTransaction(const CWallet *wallet, const CWalletTx &wtx, const CAmount &nDebit, bool involvesWatchAddress, QList< TransactionRecord > &parts)
Decompose wtx outputs in records.
TransactionRecord(uint256 hash, qint64 time, unsigned int size)
bool isNull() const
Return true if the tx hash is null and/or if the size is 0.
static QList< TransactionRecord > decomposeTransaction(const CWallet *wallet, const CWalletTx &wtx)
Decompose CWallet transaction to model transaction records.
Optional< std::string > memo
bool statusUpdateNeeded(int blockHeight) const
Return whether a status update is needed.
static bool decomposeP2CS(const CWallet *wallet, const CWalletTx &wtx, const CAmount &nCredit, const CAmount &nDebit, QList< TransactionRecord > &parts)
bool involvesWatchAddress
Whether the transaction was sent/received with a watch-only address.
static bool decomposeSendToSelfTransaction(const CWalletTx &wtx, const CAmount &nCredit, const CAmount &nDebit, bool involvesWatchAddress, QList< TransactionRecord > &parts, const CWallet *wallet)
UI model for transaction status.
bool countsForBalance
Transaction counts towards available balance.
int cur_num_blocks
Current number of blocks (to know whether cached status is still valid)
@ Confirmed
Have 6 or more confirmations (normal tx) or fully mature (mined tx)
@ OpenUntilDate
Normal (sent/received) transactions.
@ Unconfirmed
Not yet mined into a block.
@ Immature
Generated (mined) transactions.
@ Confirming
Confirmed, but waiting for the recommended number of confirmations.
@ NotAccepted
Mined but not accepted.
@ OpenUntilBlock
Transaction not yet final, waiting for block.
@ Conflicted
Conflicts with other transaction or mempool.
qint64 open_for
Timestamp if status==OpenUntilDate, otherwise number of additional blocks that need to be mined befor...
std::string sortKey
Sorting key based on status.
256-bit opaque blob.
Definition: uint256.h:138
boost::optional< T > Optional
Substitute for C++17 std::optional.
Definition: optional.h:12