PIVX Core  5.6.99
P2P Digital Currency
mnmodel.h
Go to the documentation of this file.
1 // Copyright (c) 2019-2022 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_MNMODEL_H
6 #define PIVX_QT_MNMODEL_H
7 
8 #include <QAbstractTableModel>
9 #include "masternodeconfig.h"
10 #include "qt/walletmodel.h"
11 
12 class CMasternode;
13 
14 class MNModel : public QAbstractTableModel
15 {
16  Q_OBJECT
17 
18 public:
19  explicit MNModel(QObject *parent);
20  ~MNModel() override {
21  nodes.clear();
22  collateralTxAccepted.clear();
23  }
24  void init();
25  void setWalletModel(WalletModel* _model) { walletModel = _model; };
26 
27  enum ColumnIndex {
28  ALIAS = 0,
29  ADDRESS = 1,
31  STATUS = 3,
33  PUB_KEY = 5,
36  PRIV_KEY = 8,
38  };
39 
40  int rowCount(const QModelIndex &parent = QModelIndex()) const override;
41  int columnCount(const QModelIndex &parent = QModelIndex()) const override;
42  QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
43  QModelIndex index(int row, int column, const QModelIndex& parent) const override;
44  bool removeMn(const QModelIndex& index);
46  void updateMNList();
47 
48 
49  bool isMNsNetworkSynced();
50  // Returns the MN activeState field.
51  int getMNState(const QString& mnAlias);
52  // Checks if the masternode is inactive
53  bool isMNInactive(const QString& mnAlias);
54  // Masternode is active if it's in PRE_ENABLED OR ENABLED state
55  bool isMNActive(const QString& mnAlias);
56  // Masternode collateral has enough confirmations
57  bool isMNCollateralMature(const QString& mnAlias);
58  // Validate string representing a masternode IP address
59  static bool validateMNIP(const QString& addrStr);
60 
61  // Return the specific chain amount value for the MN collateral output.
63  // Return the specific chain min conf for the collateral tx
65  // Generates the collateral transaction
66  bool createMNCollateral(const QString& alias, const QString& addr, COutPoint& ret_outpoint, QString& ret_error);
67  // Creates the mnb and broadcast it to the network
68  bool startLegacyMN(const CMasternodeConfig::CMasternodeEntry& mne, int chainHeight, std::string& strError);
69  void startAllLegacyMNs(bool onlyMissing, int& amountOfMnFailed, int& amountOfMnStarted,
70  std::string* aliasFilter = nullptr, std::string* error_ret = nullptr);
71 
73  const std::string& alias,
74  std::string& serviceAddr,
75  const std::string& port,
76  const std::string& mnKeyString,
77  QString& ret_error);
78 
79  bool removeLegacyMN(const std::string& alias_to_remove, const std::string& tx_id, unsigned int out_index, QString& ret_error);
81  void resetCoinControl();
82 
83 private:
86  // alias mn node ---> pair <ip, master node>
87  QMap<QString, std::pair<QString, CMasternode*>> nodes;
88  QMap<std::string, bool> collateralTxAccepted;
89 };
90 
91 #endif // PIVX_QT_MNMODEL_H
int64_t CAmount
Amount in PIV (Can be negative)
Definition: amount.h:13
Coin Control Features.
Definition: coincontrol.h:34
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition: transaction.h:72
MNModel(QObject *parent)
Definition: mnmodel.cpp:23
int getMNState(const QString &mnAlias)
Definition: mnmodel.cpp:164
QMap< QString, std::pair< QString, CMasternode * > > nodes
Definition: mnmodel.h:87
bool startLegacyMN(const CMasternodeConfig::CMasternodeEntry &mne, int chainHeight, std::string &strError)
Definition: mnmodel.cpp:272
bool createMNCollateral(const QString &alias, const QString &addr, COutPoint &ret_outpoint, QString &ret_error)
Definition: mnmodel.cpp:210
void setWalletModel(WalletModel *_model)
Definition: mnmodel.h:25
bool removeMn(const QModelIndex &index)
Definition: mnmodel.cpp:140
~MNModel() override
Definition: mnmodel.h:20
bool isMNActive(const QString &mnAlias)
Definition: mnmodel.cpp:177
CAmount getMNCollateralRequiredAmount()
Definition: mnmodel.cpp:200
static bool validateMNIP(const QString &addrStr)
Definition: mnmodel.cpp:195
void startAllLegacyMNs(bool onlyMissing, int &amountOfMnFailed, int &amountOfMnStarted, std::string *aliasFilter=nullptr, std::string *error_ret=nullptr)
Definition: mnmodel.cpp:286
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Definition: mnmodel.cpp:55
WalletModel * walletModel
Definition: mnmodel.h:84
bool addMn(CMasternodeConfig::CMasternodeEntry *entry)
Definition: mnmodel.cpp:151
bool isMNsNetworkSynced()
Definition: mnmodel.cpp:190
CMasternodeConfig::CMasternodeEntry * createLegacyMN(COutPoint &collateralOut, const std::string &alias, std::string &serviceAddr, const std::string &port, const std::string &mnKeyString, QString &ret_error)
Definition: mnmodel.cpp:318
int getMasternodeCollateralMinConf()
Definition: mnmodel.cpp:205
void resetCoinControl()
Definition: mnmodel.cpp:513
QMap< std::string, bool > collateralTxAccepted
Definition: mnmodel.h:88
CCoinControl * coinControl
Definition: mnmodel.h:85
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
Definition: mnmodel.cpp:70
int columnCount(const QModelIndex &parent=QModelIndex()) const override
Definition: mnmodel.cpp:62
bool removeLegacyMN(const std::string &alias_to_remove, const std::string &tx_id, unsigned int out_index, QString &ret_error)
Definition: mnmodel.cpp:417
bool isMNInactive(const QString &mnAlias)
Definition: mnmodel.cpp:171
void updateMNList()
Definition: mnmodel.cpp:30
QModelIndex index(int row, int column, const QModelIndex &parent) const override
Definition: mnmodel.cpp:125
ColumnIndex
Definition: mnmodel.h:27
@ PROTO_VERSION
Node protocol version.
Definition: mnmodel.h:30
@ ACTIVE_TIMESTAMP
Definition: mnmodel.h:32
@ PRIV_KEY
Definition: mnmodel.h:36
@ STATUS
Node status.
Definition: mnmodel.h:31
@ WAS_COLLATERAL_ACCEPTED
Definition: mnmodel.h:37
@ ALIAS
User specified MN alias.
Definition: mnmodel.h:28
@ COLLATERAL_ID
Definition: mnmodel.h:34
@ PUB_KEY
Definition: mnmodel.h:33
@ COLLATERAL_OUT_INDEX
Definition: mnmodel.h:35
@ ADDRESS
Node address.
Definition: mnmodel.h:29
void init()
Definition: mnmodel.cpp:25
void setCoinControl(CCoinControl *coinControl)
Definition: mnmodel.cpp:508
bool isMNCollateralMature(const QString &mnAlias)
Definition: mnmodel.cpp:183
Interface to PIVX wallet from Qt view code.
Definition: walletmodel.h:109