From b10e7a8cda9375a4d397b4fb684fb1580f5303d4 Mon Sep 17 00:00:00 2001 From: surangap Date: Thu, 26 Aug 2021 06:36:44 +0800 Subject: [PATCH] Add masternode `timelock` to `CCustomTxRpcVisitor`, now can be retrieved 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 --- src/masternodes/masternodes.cpp | 9 +++++++++ src/masternodes/masternodes.h | 1 + src/masternodes/rpc_customtx.cpp | 1 + src/test/mn_timelock_tests.cpp | 21 +++++++++++++++++++++ 4 files changed, 32 insertions(+) create mode 100644 src/test/mn_timelock_tests.cpp diff --git a/src/masternodes/masternodes.cpp b/src/masternodes/masternodes.cpp index 5ff7b3e044f..b801d0c8aa4 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 609c8708999..7505c09e415 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 9df12709efb..7009629fe64 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 00000000000..bee39f15cfd --- /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()