diff --git a/src/masternodes/masternodes.cpp b/src/masternodes/masternodes.cpp index 5ff7b3e044..b801d0c8aa 100644 --- a/src/masternodes/masternodes.cpp +++ b/src/masternodes/masternodes.cpp @@ -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 && diff --git a/src/masternodes/masternodes.h b/src/masternodes/masternodes.h index 609c870899..7505c09e41 100644 --- a/src/masternodes/masternodes.h +++ b/src/masternodes/masternodes.h @@ -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; diff --git a/src/masternodes/rpc_customtx.cpp b/src/masternodes/rpc_customtx.cpp index 9df12709ef..7009629fe6 100644 --- a/src/masternodes/rpc_customtx.cpp +++ b/src/masternodes/rpc_customtx.cpp @@ -70,6 +70,7 @@ class CCustomTxRpcVisitor : public boost::static_visitor rpcInfo.pushKV("masternodeoperator", EncodeDestination(obj.operatorType == 1 ? CTxDestination(PKHash(obj.operatorAuthAddress)) : CTxDestination(WitnessV0KeyHash(obj.operatorAuthAddress)))); + rpcInfo.pushKV("timelock", CMasternode::GetTimelockToString(static_cast(obj.timelock))); } void operator()(const CResignMasterNodeMessage& obj) const { diff --git a/src/test/mn_timelock_tests.cpp b/src/test/mn_timelock_tests.cpp new file mode 100644 index 0000000000..bee39f15cf --- /dev/null +++ b/src/test/mn_timelock_tests.cpp @@ -0,0 +1,21 @@ +#include + +#include + +#include + +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(uint16_t {0})), "NONE"); + BOOST_CHECK_EQUAL(CMasternode::GetTimelockToString(static_cast(uint16_t {260})), "FIVEYEARTIMELOCK"); + BOOST_CHECK_EQUAL(CMasternode::GetTimelockToString(static_cast(uint16_t {520})), "TENYEARTIMELOCK"); +} + +BOOST_AUTO_TEST_SUITE_END()