forked from dashpay/dash
-
Notifications
You must be signed in to change notification settings - Fork 717
/
coldstakingmodel.h
92 lines (75 loc) · 2.8 KB
/
coldstakingmodel.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// Copyright (c) 2019 The PIVX developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef COLDSTAKINGMODEL_H
#define COLDSTAKINGMODEL_H
#include <QAbstractTableModel>
#include "amount.h"
#include "transactiontablemodel.h"
#include "addresstablemodel.h"
#include "transactionrecord.h"
#include "walletmodel.h"
class CSDelegation {
public:
CSDelegation() {};
CSDelegation(const std::string& _stakingAddress, const std::string& _ownerAddress) :
stakingAddress(_stakingAddress), ownerAddress(_ownerAddress) {}
std::string stakingAddress{};
std::string ownerAddress{};
/// Map of txId --> index num for stakeable utxo delegations
QMap<QString, int> delegatedUtxo{};
// Sum of all delegations to this owner address
CAmount cachedTotalAmount{0};
// coin owner side, set to true if it can be spend
bool isSpendable{false};
bool operator==(const CSDelegation& obj) {
return obj.ownerAddress == ownerAddress;
}
};
class ColdStakingModel : public QAbstractTableModel
{
Q_OBJECT
public:
explicit ColdStakingModel(WalletModel* model, TransactionTableModel* _tableModel, AddressTableModel* _addressTableModel, QObject *parent = nullptr);
~ColdStakingModel() override {
model = nullptr;
tableModel = nullptr;
addressTableModel = nullptr;
cachedDelegations.clear();
}
enum ColumnIndex {
OWNER_ADDRESS = 0,
OWNER_ADDRESS_LABEL = 1,
STAKING_ADDRESS = 2,
STAKING_ADDRESS_LABEL = 3,
IS_WHITELISTED = 4,
IS_WHITELISTED_STRING = 5,
DELEGATED_UTXO_IDS = 6,
TOTAL_STACKEABLE_AMOUNT_STR = 7,
TOTAL_STACKEABLE_AMOUNT = 8,
IS_RECEIVED_DELEGATION = 9,
COLUMN_COUNT = 10
};
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
bool whitelist(const QModelIndex& modelIndex);
bool blacklist(const QModelIndex& index);
void removeRowAndEmitDataChanged(const int idx);
void updateCSList();
CAmount getTotalAmount() const { return cachedAmount; }
void refresh();
public Q_SLOTS:
void emitDataSetChanged();
private:
WalletModel* model = nullptr;
TransactionTableModel* tableModel = nullptr;
AddressTableModel* addressTableModel = nullptr;
/**
* List with all of the grouped delegations received by this wallet
*/
QList<CSDelegation> cachedDelegations;
CAmount cachedAmount;
bool parseCSDelegation(const CTxOut& out, CSDelegation& ret, const QString& txId, const int utxoIndex);
};
#endif // COLDSTAKINGMODEL_H