-
-
Notifications
You must be signed in to change notification settings - Fork 355
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 #1447
Gettotalsupply #1447
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1582,12 +1582,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 += 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); | ||
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", "") | ||
); | ||
|
||
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); | ||
} | ||
Comment on lines
+1594
to
+1630
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tip Codebase Verification The Consider adding error handling for
Analysis chainReview the implementation of This function calculates the remaining balance of the Zerocoin pool. It's important to ensure that the address index data used for calculations is accurate and up-to-date. Additionally, consider adding error handling for cases where Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Description: Verify that GetAddressIndex is retrieving accurate data.
# Test: Check if GetAddressIndex returns expected results. Expect: Valid and accurate data.
rg --type cpp "GetAddressIndex" src/
Length of output: 972 Script: #!/bin/bash
# Retrieve the implementation of GetAddressIndex from src/validation.cpp and src/validation.h
ast-grep --lang cpp --pattern 'bool GetAddressIndex($_, $_, $_)'
Length of output: 66 Script: #!/bin/bash
# Use rg to find the exact location of GetAddressIndex in src/validation.cpp
rg --type cpp "GetAddressIndex" src/validation.cpp
# Display the implementation of GetAddressIndex from src/validation.cpp
rg --type cpp -A 20 "bool GetAddressIndex" src/validation.cpp
Length of output: 966 |
||
|
||
UniValue getinfoex(const JSONRPCRequest& request) | ||
{ | ||
if (request.fHelp || request.params.size() != 0) | ||
|
@@ -1713,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 }, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clarify the hardcoded values in the
gettotalsupply
function.The function now includes hardcoded values to adjust for historical discrepancies due to attacks. It's crucial to document the source and calculation method of these values for future reference and auditability.