Skip to content

Commit

Permalink
Store attributes in masternode view (#1032)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bushstar authored and bvbfan committed Jan 18, 2022
1 parent 8401b96 commit ac20f8e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/masternodes/govvariables/attributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
10 changes: 10 additions & 0 deletions src/masternodes/masternodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,16 @@ uint16_t CMasternodesView::GetTimelock(const uint256& nodeId, const CMasternode&
return 0;
}

std::map<std::string, std::string> CMasternodesView::GetAttributes() const {
std::map<std::string, std::string> attributes;
Read(Attrs::prefix(), attributes);
return attributes;
}

void CMasternodesView::SetAttributes(const std::map<std::string, std::string>& attributes) {
Write(Attrs::prefix(), attributes);
}

std::vector<int64_t> 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
Expand Down
8 changes: 7 additions & 1 deletion src/masternodes/masternodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string, std::string> GetAttributes() const;
void SetAttributes(const std::map<std::string, std::string>& attributes);

// tags
struct ID { static constexpr uint8_t prefix() { return 'M'; } };
struct Operator { static constexpr uint8_t prefix() { return 'o'; } };
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit ac20f8e

Please sign in to comment.