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

Gettotalsupply #1502

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
98 changes: 97 additions & 1 deletion src/rpc/misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1759,6 +1759,60 @@ UniValue getspentinfo(const JSONRPCRequest& request)
return obj;
}

CAmount 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 nTotalAmount;
}

CAmount getCVE17144amount()
{
// as the attack happened at block 293526,
// get the block
CBlockIndex *mintBlock = chainActive[293526];
levonpetrosyan93 marked this conversation as resolved.
Show resolved Hide resolved
CBlock block;
if (!ReadBlockFromDisk(block, mintBlock, ::Params().GetConsensus())) {
throw std::runtime_error(std::string("can't read block from disk, "));
}
CAmount amount = 0;
for (CTransactionRef tx : block.vtx) {
std::set<COutPoint> vInOutPoints;
if (!tx->IsCoinBase() && !tx->HasNoRegularInputs()) {
std::set<COutPoint> vInOutPoints;
for (const auto& txin : tx->vin)
{
if (!vInOutPoints.insert(txin.prevout).second) {
CTransactionRef tx;
uint256 hashBlock;
if (!GetTransaction(txin.prevout.hash, tx, Params().GetConsensus(), hashBlock, true)) {
continue;
}
amount += tx->vout[txin.prevout.n].nValue;
}
}
}
}
return amount;
}

UniValue gettotalsupply(const JSONRPCRequest& request)
{
if (request.fHelp || request.params.size() != 0)
Expand All @@ -1780,12 +1834,53 @@ 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 -= getzerocoinpoolbalance(); //498,397.00000000 The actual amount of coins forged during the Zerocoin attacks (the negative balance after the pool closed),
total += getCVE17144amount(); //320,841.99803185 The cmount of forged coins during CVE-2018-17144 attacks,
total -= 16810168037465;// burnt Coins sent to unrecoverable address https://explorer.firo.org/tx/0b53178c1b22bae4c04ef943ee6d6d30f2483327fe9beb54952951592e8ce368
levonpetrosyan93 marked this conversation as resolved.
Show resolved Hide resolved
UniValue result(UniValue::VOBJ);
result.push_back(Pair("total", total));

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", "")
);

return getzerocoinpoolbalance();
}
levonpetrosyan93 marked this conversation as resolved.
Show resolved Hide resolved

UniValue getCVE17144amount(const JSONRPCRequest& request)
{
if (request.fHelp || request.params.size() != 0)
throw std::runtime_error(
"getCVE17144amount\n"
"\nReturns the total amount of forged coins during CVE-2018-17144 attacks.\n"
"\nArguments: none\n"
"\nResult:\n"
"{\n"
" \"total\" (string) The total balance\n"
"}\n"
"\nExamples:\n"
+ HelpExampleCli("getCVE17144amount", "")
+ HelpExampleRpc("getCVE17144amount", "")
);

return getCVE17144amount();
}

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

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