Skip to content

Commit

Permalink
Add masternode timelock to CCustomTxRpcVisitor, now can be retrie…
Browse files Browse the repository at this point in the history
…ved via relevant RPCs. (#679)

* Added masternode timelock to CCustomTxRpcVisitor, now can be retrived via decodecustomtx RPC.
* Updated NOTIMELOCK to NONE.

Co-authored-by: Prasanna Loganathar <[email protected]>
  • Loading branch information
surangap and prasannavl authored Aug 25, 2021
1 parent 949a5ef commit b10e7a8
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/masternodes/masternodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,15 @@ std::string CMasternode::GetHumanReadableState(State state)
}
}

std::string CMasternode::GetTimelockToString(TimeLock timelock)
{
switch (timelock) {
case FIVEYEAR : return "FIVEYEARTIMELOCK";
case TENYEAR : return "TENYEARTIMELOCK";
default : return "NONE";
}
}

bool operator==(CMasternode const & a, CMasternode const & b)
{
return (a.mintedBlocks == b.mintedBlocks &&
Expand Down
1 change: 1 addition & 0 deletions src/masternodes/masternodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ class CMasternode
bool IsActive(int height) const;

static std::string GetHumanReadableState(State state);
static std::string GetTimelockToString(TimeLock timelock);

ADD_SERIALIZE_METHODS;

Expand Down
1 change: 1 addition & 0 deletions src/masternodes/rpc_customtx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class CCustomTxRpcVisitor : public boost::static_visitor<void>
rpcInfo.pushKV("masternodeoperator", EncodeDestination(obj.operatorType == 1 ?
CTxDestination(PKHash(obj.operatorAuthAddress)) :
CTxDestination(WitnessV0KeyHash(obj.operatorAuthAddress))));
rpcInfo.pushKV("timelock", CMasternode::GetTimelockToString(static_cast<CMasternode::TimeLock>(obj.timelock)));
}

void operator()(const CResignMasterNodeMessage& obj) const {
Expand Down
21 changes: 21 additions & 0 deletions src/test/mn_timelock_tests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <test/setup_common.h>

#include <masternodes/masternodes.h>

#include <boost/test/unit_test.hpp>

BOOST_FIXTURE_TEST_SUITE(mn_timelock_tests, TestingSetup)

BOOST_AUTO_TEST_CASE(GetTimelockToString)
{
BOOST_CHECK_EQUAL(CMasternode::GetTimelockToString(CMasternode::ZEROYEAR), "NONE");
BOOST_CHECK_EQUAL(CMasternode::GetTimelockToString(CMasternode::FIVEYEAR), "FIVEYEARTIMELOCK");
BOOST_CHECK_EQUAL(CMasternode::GetTimelockToString(CMasternode::TENYEAR), "TENYEARTIMELOCK");

// from unit16_t
BOOST_CHECK_EQUAL(CMasternode::GetTimelockToString(static_cast<CMasternode::TimeLock>(uint16_t {0})), "NONE");
BOOST_CHECK_EQUAL(CMasternode::GetTimelockToString(static_cast<CMasternode::TimeLock>(uint16_t {260})), "FIVEYEARTIMELOCK");
BOOST_CHECK_EQUAL(CMasternode::GetTimelockToString(static_cast<CMasternode::TimeLock>(uint16_t {520})), "TENYEARTIMELOCK");
}

BOOST_AUTO_TEST_SUITE_END()

0 comments on commit b10e7a8

Please sign in to comment.