Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get attrs direct from Gov view #1033

Merged
merged 1 commit into from
Jan 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/masternodes/govvariables/attributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
9 changes: 9 additions & 0 deletions src/masternodes/gv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,12 @@ void CGovView::EraseStoredVariables(const uint32_t height)
EraseBy<ByHeightVars>(GovVarKey{height, var->GetName()});
}
}

std::map<std::string, std::string> CGovView::GetAttributes() const {
if (const auto var = GetVariable("ATTRIBUTES")) {
if (const auto attrs = dynamic_cast<ATTRIBUTES*>(var.get())) {
return attrs->attributes;
}
}
return {};
}
2 changes: 2 additions & 0 deletions src/masternodes/gv.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ class CGovView : public virtual CStorageView
std::map<std::string, std::map<uint64_t, std::shared_ptr<GovVariable>>> GetAllStoredVariables();
void EraseStoredVariables(const uint32_t height);

std::map<std::string, std::string> GetAttributes() const;

struct ByHeightVars { static constexpr uint8_t prefix() { return 'G'; } };
struct ByName { static constexpr uint8_t prefix() { return 'g'; } };
};
Expand Down
10 changes: 0 additions & 10 deletions src/masternodes/masternodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -544,16 +544,6 @@ 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: 1 addition & 7 deletions src/masternodes/masternodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<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 @@ -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
Expand Down Expand Up @@ -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,
Expand Down