Skip to content

Commit

Permalink
Add getzerocoinpoolbalance rpc
Browse files Browse the repository at this point in the history
  • Loading branch information
levonpetrosyan93 committed Jun 16, 2024
1 parent c8dd7c4 commit eb5231b
Showing 1 changed file with 40 additions and 3 deletions.
43 changes: 40 additions & 3 deletions src/rpc/misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1582,8 +1582,7 @@ UniValue gettotalsupply(const JSONRPCRequest& request)
if(!pblocktree->ReadTotalSupply(total))
throw JSONRPCError(RPC_DATABASE_ERROR, "Cannot read the total supply from the database. This functionality requires -addressindex to be enabled. Enabling -addressindex requires reindexing.");

total += 49839700000000; // The actual amount of coins forged during the Zerocoin attacks (the negative balance after the pool closed)
total += 23750000000000; // The estimated amount of coins forged during the Lelantus attacks.
total += 49839700000000; // The actual amount of coins forged during the Zerocoin attacks (the negative balance after the pool closed), you can verify the number by calling getzerocoinpoolbalance rpc
total += 3131972000000; // The remaining amount of forged coins during CVE-2018-17144 attacks, after subtracting locked coins and burnt Coins sent to unrecoverable address https://explorer.firo.org/tx/0b53178c1b22bae4c04ef943ee6d6d30f2483327fe9beb54952951592e8ce368

UniValue result(UniValue::VOBJ);
Expand All @@ -1592,6 +1591,44 @@ UniValue gettotalsupply(const JSONRPCRequest& request)
return result;
}

UniValue getzerocoinpoolbalance(const JSONRPCRequest& request)
{
if (request.fHelp || request.params.size() != 0)
throw std::runtime_error(
"getzerocoinpoolbalance\n"
"\nReturns the total coin amount, which remains after zerocoin pool closed.\n"
"\nArguments: none\n"
"\nResult:\n"
"{\n"
" \"total\" (string) The total balance\n"
"}\n"
"\nExamples:\n"
+ HelpExampleCli("getzerocoinpoolbalance", "")
+ HelpExampleRpc("getzerocoinpoolbalance", "")
);

CAmount nTotalAmount = 0;

// Iterate over all mints
std::vector<std::pair<CAddressIndexKey, CAmount> > addressIndex;
if (GetAddressIndex(uint160(), AddressType::zerocoinMint, addressIndex)) {
for (std::vector<std::pair<CAddressIndexKey, CAmount> >::const_iterator it=addressIndex.begin(); it!=addressIndex.end(); it++) {
nTotalAmount += it->second;
}
}
addressIndex.clear();

// Iterate over all spends
if (GetAddressIndex(uint160(), AddressType::zerocoinSpend, addressIndex)) {
for (std::vector < std::pair < CAddressIndexKey, CAmount > > ::const_iterator it = addressIndex.begin();
it != addressIndex.end(); it++) {
nTotalAmount += it->second;
}
}

return UniValue(nTotalAmount);
}

UniValue getinfoex(const JSONRPCRequest& request)
{
if (request.fHelp || request.params.size() != 0)
Expand Down Expand Up @@ -1717,7 +1754,7 @@ static const CRPCCommand commands[] =
/* Not shown in help */
{ "hidden", "getinfoex", &getinfoex, false },
{ "addressindex", "gettotalsupply", &gettotalsupply, false },

{ "addressindex", "getzerocoinpoolbalance", &getzerocoinpoolbalance, false },
/* Mobile related */
{ "mobile", "getanonymityset", &getanonymityset, false },
{ "mobile", "getmintmetadata", &getmintmetadata, true },
Expand Down

0 comments on commit eb5231b

Please sign in to comment.