PIVX Core  5.6.99
P2P Digital Currency
activemasternode.h
Go to the documentation of this file.
1 // Copyright (c) 2014-2021 The Dash Core developers
2 // Copyright (c) 2015-2022 The PIVX Core developers
3 // Distributed under the MIT/X11 software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
6 #ifndef PIVX_ACTIVEMASTERNODE_H
7 #define PIVX_ACTIVEMASTERNODE_H
8 
9 #include "key.h"
10 #include "evo/deterministicmns.h"
11 #include "operationresult.h"
12 #include "sync.h"
13 #include "validationinterface.h"
14 
16 class CBLSPublicKey;
17 class CBLSSecretKey;
18 
19 #define ACTIVE_MASTERNODE_INITIAL 0 // initial state
20 #define ACTIVE_MASTERNODE_SYNC_IN_PROCESS 1
21 #define ACTIVE_MASTERNODE_NOT_CAPABLE 3
22 #define ACTIVE_MASTERNODE_STARTED 4
23 
25 
27 {
28  // Keys for the active Masternode
31  // Initialized while registering Masternode
34 };
35 
37 {
38 public:
47  };
48 
49 private:
51  std::string strError;
53 
54 public:
56  void UpdatedBlockTip(const CBlockIndex* pindexNew, const CBlockIndex* pindexFork, bool fInitialDownload) override;
57 
58  void Init(const CBlockIndex* pindexTip);
59  void Reset(masternode_state_t _state, const CBlockIndex* pindexTip);
60  // Sets the Deterministic Masternode Operator's private/public key
61  OperationResult SetOperatorKey(const std::string& strMNOperatorPrivKey);
62  // If the active masternode is ready, and the keyID matches with the registered one,
63  // return private key, keyID, and pointer to dmn.
65  // Directly return the operator secret key saved in the manager, without performing any validation
66  const CBLSSecretKey* OperatorKey() const { return &info.keyOperator; }
68  const uint256 GetProTx() const { return info.proTxHash; }
69 
70  const CActiveMasternodeInfo* GetInfo() const { return &info; }
71  masternode_state_t GetState() const { return state; }
72  std::string GetStatus() const;
73  bool IsReady() const { return state == MASTERNODE_READY; }
74 
75  static bool IsValidNetAddr(const CService& addrIn);
76 };
77 
78 // Responsible for initializing the masternode
79 OperationResult initMasternode(const std::string& strMasterNodePrivKey, const std::string& strMasterNodeAddr, bool isFromInit);
80 
81 
82 // Responsible for activating the Masternode and pinging the network (legacy MN list)
84 {
85 private:
87  std::string notCapableReason;
88 
89 public:
90  CActiveMasternode() = default;
91 
92  // Initialized by init.cpp
93  // Keys for the main Masternode
96 
97  // Initialized while registering Masternode
98  Optional<CTxIn> vin{nullopt};
100 
102  void ManageStatus();
103  void ResetStatus();
104  std::string GetStatusMessage() const;
105  int GetStatus() const { return status; }
106 
108  bool SendMasternodePing(std::string& errorMessage);
111 
113 };
114 
115 // Compatibility code: get vin and keys for either legacy or deterministic masternode
117 // Get active masternode BLS operator keys for DMN
118 bool GetActiveDMNKeys(CBLSSecretKey& key, CTxIn& vin);
119 
120 #endif // PIVX_ACTIVEMASTERNODE_H
CActiveDeterministicMasternodeManager * activeMasternodeManager
OperationResult initMasternode(const std::string &strMasterNodePrivKey, const std::string &strMasterNodeAddr, bool isFromInit)
bool GetActiveDMNKeys(CBLSSecretKey &key, CTxIn &vin)
#define ACTIVE_MASTERNODE_INITIAL
bool GetActiveMasternodeKeys(CTxIn &vin, Optional< CKey > &key, CBLSSecretKey &blsKey)
masternode_state_t GetState() const
void UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload) override
Notifies listeners when the block chain tip advances.
static bool IsValidNetAddr(const CService &addrIn)
void Reset(masternode_state_t _state, const CBlockIndex *pindexTip)
OperationResult SetOperatorKey(const std::string &strMNOperatorPrivKey)
~CActiveDeterministicMasternodeManager() override=default
const CBLSSecretKey * OperatorKey() const
const CActiveMasternodeInfo * GetInfo() const
void Init(const CBlockIndex *pindexTip)
OperationResult GetOperatorKey(CBLSSecretKey &key, CDeterministicMNCPtr &dmn) const
CActiveMasternode()=default
bool EnableHotColdMasterNode(CTxIn &vin, CService &addr)
Enable cold wallet mode (run a Masternode with no funds)
Optional< CTxIn > vin
void ManageStatus()
Manage status of main Masternode.
std::string GetStatusMessage() const
void GetKeys(CKey &privKeyMasternode, CPubKey &pubKeyMasternode) const
std::string notCapableReason
bool SendMasternodePing(std::string &errorMessage)
Ping Masternode.
The block chain is a tree shaped structure starting with the genesis block at the root,...
Definition: chain.h:139
An encapsulated private key.
Definition: key.h:30
An encapsulated public key.
Definition: pubkey.h:44
A combination of a network address (CNetAddr) and a (TCP) port.
Definition: netaddress.h:484
An input of a transaction.
Definition: transaction.h:94
Implement this to subscribe to events generated in validation.
256-bit opaque blob.
Definition: uint256.h:138
std::shared_ptr< const CDeterministicMN > CDeterministicMNCPtr
boost::optional< T > Optional
Substitute for C++17 std::optional.
Definition: optional.h:12
CBLSSecretKey keyOperator
CBLSPublicKey pubKeyOperator
const uint256 UINT256_ZERO
constant uint256 instances
Definition: uint256.h:175