From ac20f8e79841071a599cc29ec1aa11880bf5dc89 Mon Sep 17 00:00:00 2001 From: Peter John Bushnell Date: Wed, 12 Jan 2022 06:56:26 +0000 Subject: [PATCH] Store attributes in masternode view (#1032) --- src/masternodes/govvariables/attributes.cpp | 2 +- src/masternodes/masternodes.cpp | 10 ++++++++++ src/masternodes/masternodes.h | 8 +++++++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/masternodes/govvariables/attributes.cpp b/src/masternodes/govvariables/attributes.cpp index 8d4e812e223..ddaae3a7f42 100644 --- a/src/masternodes/govvariables/attributes.cpp +++ b/src/masternodes/govvariables/attributes.cpp @@ -182,6 +182,6 @@ Res ATTRIBUTES::Validate(const CCustomCSView & view) const Res ATTRIBUTES::Apply(CCustomCSView & mnview, const uint32_t height) { - // On implemenation of features that rely on ATTRIBUTES store values in mnview where they are needed. + mnview.SetAttributes(attributes); return Res::Ok(); } diff --git a/src/masternodes/masternodes.cpp b/src/masternodes/masternodes.cpp index 86b528af9c0..8ffdcbb4e4e 100644 --- a/src/masternodes/masternodes.cpp +++ b/src/masternodes/masternodes.cpp @@ -544,6 +544,16 @@ 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 1df82591820..ab3109f61f8 100644 --- a/src/masternodes/masternodes.h +++ b/src/masternodes/masternodes.h @@ -222,6 +222,9 @@ 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'; } }; @@ -233,6 +236,9 @@ 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 @@ -357,7 +363,7 @@ class CCustomCSView void CheckPrefixes() { CheckPrefix< - CMasternodesView :: ID, Operator, Owner, Staker, SubNode, Timelock, + CMasternodesView :: ID, Operator, Owner, Staker, SubNode, Timelock, Attrs, CLastHeightView :: Height, CTeamView :: AuthTeam, ConfirmTeam, CurrentTeam, CFoundationsDebtView :: Debt,