You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

transactionrecord.h 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. // Copyright (c) 2011-2016 The Starwels developers
  2. // Distributed under the MIT software license, see the accompanying
  3. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
  4. #ifndef STARWELS_QT_TRANSACTIONRECORD_H
  5. #define STARWELS_QT_TRANSACTIONRECORD_H
  6. #include "amount.h"
  7. #include "uint256.h"
  8. #include <QList>
  9. #include <QString>
  10. class CWallet;
  11. class CWalletTx;
  12. /** UI model for transaction status. The transaction status is the part of a transaction that will change over time.
  13. */
  14. class TransactionStatus
  15. {
  16. public:
  17. TransactionStatus():
  18. countsForBalance(false), sortKey(""),
  19. matures_in(0), status(Offline), depth(0), open_for(0), cur_num_blocks(-1)
  20. { }
  21. enum Status {
  22. Confirmed, /**< Have 6 or more confirmations (normal tx) or fully mature (mined tx) **/
  23. /// Normal (sent/received) transactions
  24. OpenUntilDate, /**< Transaction not yet final, waiting for date */
  25. OpenUntilBlock, /**< Transaction not yet final, waiting for block */
  26. Offline, /**< Not sent to any other nodes **/
  27. Unconfirmed, /**< Not yet mined into a block **/
  28. Confirming, /**< Confirmed, but waiting for the recommended number of confirmations **/
  29. Conflicted, /**< Conflicts with other transaction or mempool **/
  30. Abandoned, /**< Abandoned from the wallet **/
  31. /// Generated (mined) transactions
  32. Immature, /**< Mined but waiting for maturity */
  33. MaturesWarning, /**< Transaction will likely not mature because no nodes have confirmed */
  34. NotAccepted /**< Mined but not accepted */
  35. };
  36. /// Transaction counts towards available balance
  37. bool countsForBalance;
  38. /// Sorting key based on status
  39. std::string sortKey;
  40. /** @name Generated (mined) transactions
  41. @{*/
  42. int matures_in;
  43. /**@}*/
  44. /** @name Reported status
  45. @{*/
  46. Status status;
  47. qint64 depth;
  48. qint64 open_for; /**< Timestamp if status==OpenUntilDate, otherwise number
  49. of additional blocks that need to be mined before
  50. finalization */
  51. /**@}*/
  52. /** Current number of blocks (to know whether cached status is still valid) */
  53. int cur_num_blocks;
  54. bool needsUpdate;
  55. };
  56. /** UI model for a transaction. A core transaction can be represented by multiple UI transactions if it has
  57. multiple outputs.
  58. */
  59. class TransactionRecord
  60. {
  61. public:
  62. enum Type
  63. {
  64. Other,
  65. Generated,
  66. SendToAddress,
  67. SendToOther,
  68. RecvWithAddress,
  69. RecvFromOther,
  70. SendToSelf
  71. };
  72. /** Number of confirmation recommended for accepting a transaction */
  73. static const int RecommendedNumConfirmations = 6;
  74. TransactionRecord():
  75. hash(), time(0), type(Other), address(""), debit(0), credit(0), idx(0)
  76. {
  77. }
  78. TransactionRecord(uint256 _hash, qint64 _time):
  79. hash(_hash), time(_time), type(Other), address(""), debit(0),
  80. credit(0), idx(0)
  81. {
  82. }
  83. TransactionRecord(uint256 _hash, qint64 _time,
  84. Type _type, const std::string &_address,
  85. const CAmount& _debit, const CAmount& _credit):
  86. hash(_hash), time(_time), type(_type), address(_address), debit(_debit), credit(_credit),
  87. idx(0)
  88. {
  89. }
  90. /** Decompose CWallet transaction to model transaction records.
  91. */
  92. static bool showTransaction(const CWalletTx &wtx);
  93. static QList<TransactionRecord> decomposeTransaction(const CWallet *wallet, const CWalletTx &wtx);
  94. /** @name Immutable transaction attributes
  95. @{*/
  96. uint256 hash;
  97. qint64 time;
  98. Type type;
  99. std::string address;
  100. CAmount debit;
  101. CAmount credit;
  102. /**@}*/
  103. /** Subtransaction index, for sort key */
  104. int idx;
  105. /** Status: can change with block chain update */
  106. TransactionStatus status;
  107. /** Whether the transaction was sent/received with a watch-only address */
  108. bool involvesWatchAddress;
  109. /** Return the unique identifier for this transaction (part) */
  110. QString getTxID() const;
  111. /** Return the output index of the subtransaction */
  112. int getOutputIndex() const;
  113. /** Update status from core wallet tx.
  114. */
  115. void updateStatus(const CWalletTx &wtx);
  116. /** Return whether a status update is needed.
  117. */
  118. bool statusUpdateNeeded();
  119. };
  120. #endif // STARWELS_QT_TRANSACTIONRECORD_H