diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index e67fbd103f..6ad6049e12 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -1759,6 +1759,60 @@ UniValue getspentinfo(const JSONRPCRequest& request) return obj; } +CAmount getzerocoinpoolbalance() +{ + CAmount nTotalAmount = 0; + + // Iterate over all mints + std::vector > addressIndex; + if (GetAddressIndex(uint160(), AddressType::zerocoinMint, addressIndex)) { + for (std::vector >::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]; + 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 vInOutPoints; + if (!tx->IsCoinBase() && !tx->HasNoRegularInputs()) { + std::set 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) @@ -1780,9 +1834,9 @@ 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), 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 - + 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 UniValue result(UniValue::VOBJ); result.push_back(Pair("total", total)); @@ -1805,26 +1859,7 @@ UniValue getzerocoinpoolbalance(const JSONRPCRequest& request) + HelpExampleRpc("getzerocoinpoolbalance", "") ); - CAmount nTotalAmount = 0; - - // Iterate over all mints - std::vector > addressIndex; - if (GetAddressIndex(uint160(), AddressType::zerocoinMint, addressIndex)) { - for (std::vector >::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); + return getzerocoinpoolbalance(); } UniValue getCVE17144amount(const JSONRPCRequest& request) @@ -1842,32 +1877,8 @@ UniValue getCVE17144amount(const JSONRPCRequest& request) + HelpExampleCli("getCVE17144amount", "") + HelpExampleRpc("getCVE17144amount", "") ); - // as the attack happened at block 293526, - // get the block - CBlockIndex *mintBlock = chainActive[293526]; - 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 vInOutPoints; - if (!tx->IsCoinBase() && !tx->HasNoRegularInputs()) { - std::set 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; + + return getCVE17144amount(); } UniValue getinfoex(const JSONRPCRequest& request)