Skip to content

Commit

Permalink
[MN] Active MN manager: return key and dmn after validation
Browse files Browse the repository at this point in the history
  • Loading branch information
random-zebra committed May 23, 2021
1 parent 5df5067 commit 6fcd53d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/activemasternode.cpp
Expand Up @@ -7,7 +7,6 @@

#include "addrman.h"
#include "evo/providertx.h"
#include "evo/deterministicmns.h"
#include "masternode-sync.h"
#include "masternode.h"
#include "masternodeconfig.h"
Expand Down Expand Up @@ -67,6 +66,24 @@ OperationResult CActiveDeterministicMasternodeManager::SetOperatorKey(const std:
return OperationResult(true);
}

OperationResult CActiveDeterministicMasternodeManager::GetOperatorKey(CKey& key, CKeyID& keyID, CDeterministicMNCPtr& dmn) const
{
if (!IsReady()) {
return errorOut("Active masternode not ready");
}
dmn = deterministicMNManager->GetListAtChainTip().GetValidMN(info.proTxHash);
if (!dmn) {
return errorOut(strprintf("Active masternode %s not registered or PoSe banned", info.proTxHash.ToString()));
}
if (info.keyIDOperator != dmn->pdmnState->keyIDOperator) {
return errorOut("Active masternode operator key changed or revoked");
}
// return keys
key = info.keyOperator;
keyID = info.keyIDOperator;
return OperationResult(true);
}

void CActiveDeterministicMasternodeManager::Init()
{
// set masternode arg if called from RPC
Expand Down Expand Up @@ -119,6 +136,8 @@ void CActiveDeterministicMasternodeManager::Init()

LogPrintf("%s: proTxHash=%s, proTx=%s\n", __func__, dmn->proTxHash.ToString(), dmn->ToString());

info.proTxHash = dmn->proTxHash;

if (info.service != dmn->pdmnState->addr) {
state = MASTERNODE_ERROR;
strError = strprintf("Local address %s does not match the address from ProTx (%s)",
Expand All @@ -142,7 +161,6 @@ void CActiveDeterministicMasternodeManager::Init()
}
}

info.proTxHash = dmn->proTxHash;
state = MASTERNODE_READY;
}

Expand Down
4 changes: 4 additions & 0 deletions src/activemasternode.h
Expand Up @@ -8,6 +8,7 @@

#include "init.h"
#include "key.h"
#include "evo/deterministicmns.h"
#include "masternode.h"
#include "net.h"
#include "operationresult.h"
Expand Down Expand Up @@ -60,6 +61,9 @@ class CActiveDeterministicMasternodeManager : public CValidationInterface
void Reset(masternode_state_t _state);
// Sets the Deterministic Masternode Operator's private/public key
OperationResult SetOperatorKey(const std::string& strMNOperatorPrivKey);
// If the active masternode is ready, and the keyID matches with the registered one,
// return private key, keyID, and pointer to dmn.
OperationResult GetOperatorKey(CKey& key, CKeyID& keyID, CDeterministicMNCPtr& dmn) const;
void SetNullProTx() { info.proTxHash = UINT256_ZERO; }

const CActiveMasternodeInfo* GetInfo() const { return &info; }
Expand Down

0 comments on commit 6fcd53d

Please sign in to comment.