Skip to content

Commit 4837a3f

Browse files
authored
Merge pull request #2013 from jamescowens/beaconreport_active_only_option
rpc: Add boolean option to report active beacons only in beaconreport
2 parents b88f766 + 1fbdc04 commit 4837a3f

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/rpc/blockchain.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -737,16 +737,28 @@ UniValue revokebeacon(const UniValue& params, bool fHelp)
737737

738738
UniValue beaconreport(const UniValue& params, bool fHelp)
739739
{
740-
if (fHelp || params.size() > 0)
740+
if (fHelp || params.size() > 1)
741741
throw runtime_error(
742-
"beaconreport\n"
742+
"beaconreport <active only>\n"
743+
"\n"
744+
"<active only> Boolean specifying whether only active beacons should be \n"
745+
" returned. Defaults to false which also includes expired beacons."
743746
"\n"
744747
"Displays list of valid beacons in the network\n");
745748

749+
bool active_only = false;
750+
751+
if (params.size() == 1)
752+
{
753+
active_only = params[0].getBool();
754+
}
755+
746756
UniValue results(UniValue::VARR);
747757

748758
std::vector<std::pair<GRC::Cpid, GRC::Beacon_ptr>> active_beacon_ptrs;
749759

760+
int64_t now = GetAdjustedTime();
761+
750762
// Minimize the lock on cs_main.
751763
{
752764
LOCK(cs_main);
@@ -761,6 +773,8 @@ UniValue beaconreport(const UniValue& params, bool fHelp)
761773
{
762774
UniValue entry(UniValue::VOBJ);
763775

776+
if (active_only && beacon_pair.second->Expired(now)) continue;
777+
764778
entry.pushKV("cpid", beacon_pair.first.ToString());
765779
entry.pushKV("address", beacon_pair.second->GetAddress().ToString());
766780
entry.pushKV("timestamp", beacon_pair.second->m_timestamp);

src/rpc/client.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ static const CRPCConvertParam vRPCConvertParams[] =
166166

167167
// Mining
168168
{ "advertisebeacon" , 0 },
169+
{ "beaconreport" , 0 },
169170
{ "superblocks" , 0 },
170171
{ "superblocks" , 1 },
171172

0 commit comments

Comments
 (0)