From 1a9c7af775bc615ad7ec15cfe808c59d6b8cfc05 Mon Sep 17 00:00:00 2001 From: Peter Bushnell Date: Wed, 12 Jan 2022 07:24:58 +0000 Subject: [PATCH] Get attrs direct from Gov view --- src/masternodes/govvariables/attributes.cpp | 1 - src/masternodes/gv.cpp | 9 +++++++++ src/masternodes/gv.h | 2 ++ src/masternodes/masternodes.cpp | 10 ---------- src/masternodes/masternodes.h | 8 +------- 5 files changed, 12 insertions(+), 18 deletions(-) diff --git a/src/masternodes/govvariables/attributes.cpp b/src/masternodes/govvariables/attributes.cpp index ddaae3a7f42..4456d5010de 100644 --- a/src/masternodes/govvariables/attributes.cpp +++ b/src/masternodes/govvariables/attributes.cpp @@ -182,6 +182,5 @@ Res ATTRIBUTES::Validate(const CCustomCSView & view) const Res ATTRIBUTES::Apply(CCustomCSView & mnview, const uint32_t height) { - mnview.SetAttributes(attributes); return Res::Ok(); } diff --git a/src/masternodes/gv.cpp b/src/masternodes/gv.cpp index a9198af926a..4f4b907741b 100644 --- a/src/masternodes/gv.cpp +++ b/src/masternodes/gv.cpp @@ -81,3 +81,12 @@ void CGovView::EraseStoredVariables(const uint32_t height) EraseBy(GovVarKey{height, var->GetName()}); } } + +std::map CGovView::GetAttributes() const { + if (const auto var = GetVariable("ATTRIBUTES")) { + if (const auto attrs = dynamic_cast(var.get())) { + return attrs->attributes; + } + } + return {}; +} diff --git a/src/masternodes/gv.h b/src/masternodes/gv.h index bc3717bf48f..8994722b477 100644 --- a/src/masternodes/gv.h +++ b/src/masternodes/gv.h @@ -46,6 +46,8 @@ class CGovView : public virtual CStorageView std::map>> GetAllStoredVariables(); void EraseStoredVariables(const uint32_t height); + std::map GetAttributes() const; + struct ByHeightVars { static constexpr uint8_t prefix() { return 'G'; } }; struct ByName { static constexpr uint8_t prefix() { return 'g'; } }; }; diff --git a/src/masternodes/masternodes.cpp b/src/masternodes/masternodes.cpp index cf6cacf7e3a..811d811f939 100644 --- a/src/masternodes/masternodes.cpp +++ b/src/masternodes/masternodes.cpp @@ -544,16 +544,6 @@ uint16_t CMasternodesView::GetTimelock(const uint256& nodeId, const CMasternode& return 0; } -std::map CMasternodesView::GetAttributes() const { - std::map attributes; - Read(Attrs::prefix(), attributes); - return attributes; -} - -void CMasternodesView::SetAttributes(const std::map& attributes) { - Write(Attrs::prefix(), attributes); -} - std::vector CMasternodesView::GetBlockTimes(const CKeyID& keyID, const uint32_t blockHeight, const int32_t creationHeight, const uint16_t timelock) { // Get last block time for non-subnode staking diff --git a/src/masternodes/masternodes.h b/src/masternodes/masternodes.h index f2cccd09eff..50623bc3f0b 100644 --- a/src/masternodes/masternodes.h +++ b/src/masternodes/masternodes.h @@ -222,9 +222,6 @@ class CMasternodesView : public virtual CStorageView uint16_t GetTimelock(const uint256& nodeId, const CMasternode& node, const uint64_t height) const; - std::map GetAttributes() const; - void SetAttributes(const std::map& attributes); - // tags struct ID { static constexpr uint8_t prefix() { return 'M'; } }; struct Operator { static constexpr uint8_t prefix() { return 'o'; } }; @@ -236,9 +233,6 @@ class CMasternodesView : public virtual CStorageView // Store long term time lock struct Timelock { static constexpr uint8_t prefix() { return 'K'; } }; - - // Store attributes map - struct Attrs { static constexpr uint8_t prefix() { return 's'; } }; }; class CLastHeightView : public virtual CStorageView @@ -363,7 +357,7 @@ class CCustomCSView void CheckPrefixes() { CheckPrefix< - CMasternodesView :: ID, Operator, Owner, Staker, SubNode, Timelock, Attrs, + CMasternodesView :: ID, Operator, Owner, Staker, SubNode, Timelock, CLastHeightView :: Height, CTeamView :: AuthTeam, ConfirmTeam, CurrentTeam, CFoundationsDebtView :: Debt,