diff --git a/src/masternodes/masternodes.h b/src/masternodes/masternodes.h index a9db52b6e02..26041cd2169 100644 --- a/src/masternodes/masternodes.h +++ b/src/masternodes/masternodes.h @@ -241,13 +241,15 @@ class CMasternodesView : public virtual CStorageView void SetMasternodeLastBlockTime(const CKeyID & minter, const uint32_t &blockHeight, const int64_t &time); std::optional GetMasternodeLastBlockTime(const CKeyID & minter, const uint32_t height); void EraseMasternodeLastBlockTime(const uint256 &minter, const uint32_t& blockHeight); - void ForEachMinterNode(std::function)> callback, MNBlockTimeKey const & start = {}); + void ForEachMinterNode(std::function)> callback, + MNBlockTimeKey const & start = {uint256{}, std::numeric_limits::max()}); // Subnode block times void SetSubNodesBlockTime(const CKeyID & minter, const uint32_t &blockHeight, const uint8_t id, const int64_t& time); std::vector GetSubNodesBlockTime(const CKeyID & minter, const uint32_t height); void EraseSubNodesLastBlockTime(const uint256& nodeId, const uint32_t& blockHeight); - void ForEachSubNode(std::function)> callback, SubNodeBlockTimeKey const & start = {}); + void ForEachSubNode(std::function)> callback, + SubNodeBlockTimeKey const & start = {uint256{}, uint8_t{}, std::numeric_limits::max()}); uint16_t GetTimelock(const uint256& nodeId, const CMasternode& node, const uint64_t height) const; diff --git a/src/masternodes/rpc_masternodes.cpp b/src/masternodes/rpc_masternodes.cpp index 50b555e51bc..86ad9bd18cd 100644 --- a/src/masternodes/rpc_masternodes.cpp +++ b/src/masternodes/rpc_masternodes.cpp @@ -585,7 +585,7 @@ UniValue getmasternodeblocks(const JSONRPCRequest& request) { UniValue identifier = request.params[0].get_obj(); int idCount{0}; - uint256 mn_id; + uint256 mn_id{}; if (!identifier["id"].isNull()) { mn_id = ParseHashV(identifier["id"], "id"); @@ -652,7 +652,8 @@ UniValue getmasternodeblocks(const JSONRPCRequest& request) { if (!request.params[1].isNull()) { depth = request.params[1].get_int(); } - UniValue ret(UniValue::VOBJ); + + std::map> mintedBlocks; auto currentHeight = ::ChainActive().Height(); depth = std::min(depth, currentHeight); auto startBlock = currentHeight - depth; @@ -671,7 +672,7 @@ UniValue getmasternodeblocks(const JSONRPCRequest& request) { auto tip = ::ChainActive()[blockHeight]; if (tip && depth > 0) { lastHeight = tip->nHeight; - ret.pushKV(std::to_string(lastHeight), tip->GetBlockHash().ToString()); + mintedBlocks.emplace(lastHeight, tip->GetBlockHash()); depth--; } @@ -691,10 +692,15 @@ UniValue getmasternodeblocks(const JSONRPCRequest& request) { for (; tip && tip->nHeight > creationHeight && depth > 0 && tip->nHeight > startBlock; tip = tip->pprev, --depth) { auto id = pcustomcsview->GetMasternodeIdByOperator(tip->minterKey()); if (id && *id == mn_id) { - ret.pushKV(std::to_string(tip->nHeight), tip->GetBlockHash().ToString()); + mintedBlocks.emplace(tip->nHeight, tip->GetBlockHash()); } } + UniValue ret(UniValue::VOBJ); + for (const auto& [height, hash] : mintedBlocks) { + ret.pushKV(std::to_string(height), hash.ToString()); + } + return GetRPCResultCache().Set(request, ret); }