Skip to content

Commit 594eabb

Browse files
authored
Merge pull request #1668 from cyrossignol/lifetime-rpc-cpid
Add support for CPID input to "lifetime" RPC function
2 parents dc2eda1 + 1d872eb commit 594eabb

File tree

1 file changed

+21
-30
lines changed

1 file changed

+21
-30
lines changed

src/rpcblockchain.cpp

+21-30
Original file line numberDiff line numberDiff line change
@@ -898,49 +898,40 @@ UniValue explainmagnitude(const UniValue& params, bool fHelp)
898898

899899
UniValue lifetime(const UniValue& params, bool fHelp)
900900
{
901-
if (fHelp || params.size() != 0)
901+
if (fHelp || params.size() > 1)
902902
throw runtime_error(
903-
"lifetime\n"
903+
"lifetime [cpid]\n"
904904
"\n"
905-
"Displays information for the lifetime of your cpid in the network\n");
905+
"Displays research rewards for the lifetime of a CPID.\n");
906906

907-
UniValue results(UniValue::VARR);
908-
UniValue c(UniValue::VOBJ);
909-
UniValue res(UniValue::VOBJ);
907+
const NN::MiningId mining_id = params.size() > 0
908+
? NN::MiningId::Parse(params[0].get_str())
909+
: NN::Researcher::Get()->Id();
910910

911-
const NN::CpidOption cpid = NN::Researcher::Get()->Id().TryCpid();
912-
std::string Narr = ToString(GetAdjustedTime());
911+
if (!mining_id.Valid()) {
912+
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid CPID.");
913+
}
913914

914-
c.pushKV("Lifetime Payments Report", Narr);
915-
results.push_back(c);
915+
const NN::CpidOption cpid = mining_id.TryCpid();
916916

917917
if (!cpid) {
918-
return results;
918+
throw JSONRPCError(RPC_INVALID_PARAMETER, "No data for investor.");
919919
}
920920

921-
LOCK(cs_main);
921+
UniValue results(UniValue::VOBJ);
922922

923-
CBlockIndex* pindex = pindexGenesisBlock;
923+
LOCK(cs_main);
924924

925-
while (pindex->nHeight < pindexBest->nHeight)
925+
for (const CBlockIndex* pindex = pindexGenesisBlock;
926+
pindex;
927+
pindex = pindex->pnext)
926928
{
927-
pindex = pindex->pnext;
928-
929-
if (pindex==NULL || !pindex->IsInMainChain())
930-
continue;
931-
932-
if (pindex == pindexBest)
933-
break;
934-
935-
if (pindex->GetMiningId() == *cpid && (pindex->nResearchSubsidy > 0))
936-
res.pushKV(ToString(pindex->nHeight), ValueFromAmount(pindex->nResearchSubsidy));
929+
if (pindex->nResearchSubsidy > 0 && pindex->GetMiningId() == *cpid) {
930+
results.pushKV(
931+
std::to_string(pindex->nHeight),
932+
ValueFromAmount(pindex->nResearchSubsidy));
933+
}
937934
}
938-
//8-14-2015
939-
const NN::ResearchAccount account = NN::Tally::GetAccount(*cpid);
940-
941-
res.pushKV("RA Magnitude Sum", (int)account.m_total_magnitude);
942-
res.pushKV("RA Accuracy", (int)account.m_accuracy);
943-
results.push_back(res);
944935

945936
return results;
946937
}

0 commit comments

Comments
 (0)