PIVX Core  5.6.99
P2P Digital Currency
coldstakingmodel.h
Go to the documentation of this file.
1 // Copyright (c) 2019-2021 The PIVX 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 #ifndef PIVX_QT_COLDSTAKINGMODEL_H
6 #define PIVX_QT_COLDSTAKINGMODEL_H
7 
8 #include <QAbstractTableModel>
9 #include "amount.h"
10 #include "transactiontablemodel.h"
11 #include "addresstablemodel.h"
12 #include "transactionrecord.h"
13 #include "walletmodel.h"
14 
15 class CSDelegation {
16 public:
17 
19  CSDelegation(const std::string& _stakingAddress, const std::string& _ownerAddress) :
20  stakingAddress(_stakingAddress), ownerAddress(_ownerAddress) {}
21 
22  std::string stakingAddress{};
23  std::string ownerAddress{};
25  QMap<QString, int> delegatedUtxo{};
26  // Sum of all delegations to this owner address
28 
29  // coin owner side, set to true if it can be spend
30  bool isSpendable{false};
31 
32  bool operator==(const CSDelegation& obj) {
33  return obj.ownerAddress == ownerAddress;
34  }
35 };
36 
37 class ColdStakingModel : public QAbstractTableModel
38 {
39  Q_OBJECT
40 
41 public:
42  explicit ColdStakingModel(WalletModel* model, TransactionTableModel* _tableModel, AddressTableModel* _addressTableModel, QObject *parent = nullptr);
43  ~ColdStakingModel() override {
44  model = nullptr;
45  tableModel = nullptr;
46  addressTableModel = nullptr;
47  cachedDelegations.clear();
48  }
49 
50  enum ColumnIndex {
61  COLUMN_COUNT = 10
62  };
63 
64  int rowCount(const QModelIndex &parent = QModelIndex()) const override;
65  int columnCount(const QModelIndex &parent = QModelIndex()) const override;
66  QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
67  bool whitelist(const QModelIndex& modelIndex);
68  bool blacklist(const QModelIndex& index);
69  void removeRowAndEmitDataChanged(const int idx);
70  void updateCSList();
71  CAmount getTotalAmount() const { return cachedAmount; }
72 
73  void refresh();
74 
75 public Q_SLOTS:
76  void emitDataSetChanged();
77 
78 private:
79  WalletModel* model = nullptr;
82 
86  QList<CSDelegation> cachedDelegations;
88 
89  bool parseCSDelegation(const CTxOut& out, CSDelegation& ret, const QString& txId, const int utxoIndex);
90 };
91 
92 #endif // PIVX_QT_COLDSTAKINGMODEL_H
int64_t CAmount
Amount in PIV (Can be negative)
Definition: amount.h:13
Qt model of the address book in the core.
bool operator==(const CSDelegation &obj)
CSDelegation(const std::string &_stakingAddress, const std::string &_ownerAddress)
std::string ownerAddress
std::string stakingAddress
QMap< QString, int > delegatedUtxo
Map of txId --> index num for stakeable utxo delegations.
CAmount cachedTotalAmount
An output of a transaction.
Definition: transaction.h:137
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
int rowCount(const QModelIndex &parent=QModelIndex()) const override
CAmount getTotalAmount() const
QList< CSDelegation > cachedDelegations
List with all of the grouped delegations received by this wallet.
bool whitelist(const QModelIndex &modelIndex)
void removeRowAndEmitDataChanged(const int idx)
bool blacklist(const QModelIndex &index)
TransactionTableModel * tableModel
WalletModel * model
bool parseCSDelegation(const CTxOut &out, CSDelegation &ret, const QString &txId, const int utxoIndex)
ColdStakingModel(WalletModel *model, TransactionTableModel *_tableModel, AddressTableModel *_addressTableModel, QObject *parent=nullptr)
int columnCount(const QModelIndex &parent=QModelIndex()) const override
~ColdStakingModel() override
AddressTableModel * addressTableModel
UI model for the transaction table of a wallet.
Interface to PIVX wallet from Qt view code.
Definition: walletmodel.h:109