Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add masternode timelock to CCustomTxRpcVisitor, now can be retrieved via relevant RPCs. #679

Merged
merged 5 commits into from
Aug 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()