Skip to content

Commit

Permalink
Add listmandatorysidestakes rpc
Browse files Browse the repository at this point in the history
  • Loading branch information
jamescowens committed Mar 29, 2024
1 parent e33e41d commit d84f87e
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/gridcoin/sidestake.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,33 @@ std::string SideStake::GetDescription() const
return std::string {};
}

int64_t SideStake::GetTimeStamp() const
{
if (m_type == Type::MANDATORY && m_mandatory_sidestake_ptr != nullptr) {
return m_mandatory_sidestake_ptr->m_timestamp;
}

return int64_t {0};
}

uint256 SideStake::GetHash() const
{
if (m_type == Type::MANDATORY && m_mandatory_sidestake_ptr != nullptr) {
return m_mandatory_sidestake_ptr->m_hash;
}

return uint256 {};
}

uint256 SideStake::GetPreviousHash() const
{
if (m_type == Type::MANDATORY && m_mandatory_sidestake_ptr != nullptr) {
return m_mandatory_sidestake_ptr->m_previous_hash;
}

return uint256 {};
}

SideStake::Status SideStake::GetStatus() const
{
// For trivial initializer case
Expand Down
15 changes: 15 additions & 0 deletions src/gridcoin/sidestake.h
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,21 @@ class SideStake
//!
std::string GetDescription() const;
//!
//! \brief Gets the timestamp of the transaction that contains the mandatory sidestake contract (now entry)
//! \return
//!
int64_t GetTimeStamp() const;
//!
//! \brief Gets the hash of the transaction that contains the mandatory sidestake contract (now entry)
//! \return uint256 hash
//!
uint256 GetHash() const;
//!
//! \brief Gets the hash of the transaction that contains the previous mandatory sidestake contract for the same key (address)
//! \return uint256 hash
//!
uint256 GetPreviousHash() const;
//!
//! \brief Gets a variant containing either the mandatory sidestake status or local sidestake status, whichever
//! is applicable.
//! \return std::variant of the applicable sidestake status
Expand Down
35 changes: 35 additions & 0 deletions src/rpc/blockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2700,6 +2700,41 @@ UniValue listprotocolentries(const UniValue& params, bool fHelp)
return res;
}

UniValue listmandatorysidestakes(const UniValue& params, bool fHelp)
{
if (fHelp || params.size() != 0)
throw runtime_error(
"listprotocolentries\n"
"\n"
"Displays the mandatory sidestakes on the network.\n");

UniValue res(UniValue::VOBJ);
UniValue scraper_entries(UniValue::VARR);

for (const auto& sidestake : GRC::GetSideStakeRegistry().ActiveSideStakeEntries(GRC::SideStake::FilterFlag::MANDATORY, false)) {
UniValue entry(UniValue::VOBJ);

entry.pushKV("mandatory_sidestake_entry_address", CBitcoinAddress(sidestake->GetDestination()).ToString());
entry.pushKV("mandatory_sidestake_entry_allocation", sidestake->GetAllocation().ToPercent());
entry.pushKV("mandatory_sidestake_entry_tx_hash", sidestake->GetHash().ToString());
if (sidestake->GetPreviousHash().IsNull()) {
entry.pushKV("previous_mandatory_sidestake_entry_tx_hash", "null");
} else {
entry.pushKV("previous_mandatory_sidestake_entry_tx_hash", sidestake->GetPreviousHash().ToString());
}

entry.pushKV("mandatory_sidestake_entry_timestamp", sidestake->GetTimeStamp());
entry.pushKV("mandatory_sidestake_entry_time", DateTimeStrFormat(sidestake->GetTimeStamp()));
entry.pushKV("mandatory_sidestake_entry_status", sidestake->StatusToString());

scraper_entries.push_back(entry);
}

res.pushKV("current_mandatory_sidestake_entries", scraper_entries);

return res;
}

UniValue network(const UniValue& params, bool fHelp)
{
if (fHelp || params.size() != 0)
Expand Down
1 change: 1 addition & 0 deletions src/rpc/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ static const CRPCCommand vRPCCommands[] =
{ "listprotocolentries", &listprotocolentries, cat_developer },
{ "listresearcheraccounts", &listresearcheraccounts, cat_developer },
{ "listscrapers", &listscrapers, cat_developer },
{ "listmandatorysidestakes", &listmandatorysidestakes, cat_developer },
{ "listsettings", &listsettings, cat_developer },
{ "logging", &logging, cat_developer },
{ "network", &network, cat_developer },
Expand Down
1 change: 1 addition & 0 deletions src/rpc/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ extern UniValue listprojects(const UniValue& params, bool fHelp);
extern UniValue listprotocolentries(const UniValue& params, bool fHelp);
extern UniValue listresearcheraccounts(const UniValue& params, bool fHelp);
extern UniValue listscrapers(const UniValue& params, bool fHelp);
extern UniValue listmandatorysidestakes(const UniValue& params, bool fHelp);
extern UniValue listsettings(const UniValue& params, bool fHelp);
extern UniValue logging(const UniValue& params, bool fHelp);
extern UniValue network(const UniValue& params, bool fHelp);
Expand Down

0 comments on commit d84f87e

Please sign in to comment.