Skip to content

Commit

Permalink
[RPC] Add totalsupply/moneysupply to getsupplyinfo/getinfo
Browse files Browse the repository at this point in the history
  • Loading branch information
random-zebra committed Nov 23, 2020
1 parent cea10c7 commit ab9c8d0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/rpc/blockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,7 @@ UniValue getsupplyinfo(const JSONRPCRequest& request)
" \"updateheight\" : n, (numeric) The chain height when the transparent supply was updated\n"
" \"transparentsupply\" : n (numeric) The sum of all spendable transaction outputs at height updateheight\n"
" \"shieldedsupply\": n (numeric) Chain tip shielded pool value\n"
" \"totalsupply\": n (numeric) The sum of transparentsupply and shieldedsupply\n"
"}\n"

"\nExamples:\n" +
Expand All @@ -665,10 +666,13 @@ UniValue getsupplyinfo(const JSONRPCRequest& request)
}

UniValue ret(UniValue::VOBJ);
const CAmount tSupply = MoneySupply.Get();
ret.pushKV("updateheight", MoneySupply.GetCacheHeight());
ret.pushKV("transparentsupply", ValueFromAmount(MoneySupply.Get()));
ret.pushKV("transparentsupply", ValueFromAmount(tSupply));
Optional<CAmount> shieldedPoolValue = WITH_LOCK(cs_main, return (chainActive.Tip() ? chainActive.Tip()->nChainSaplingValue : nullopt); );
ret.pushKV("shieldedsupply", ValuePoolDesc(shieldedPoolValue, nullopt)["chainValue"]);
const CAmount totalSupply = tSupply + (shieldedPoolValue ? *shieldedPoolValue : 0);
ret.pushKV("totalsupply", ValueFromAmount(totalSupply));

return ret;
}
Expand Down
2 changes: 2 additions & 0 deletions src/rpc/misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ UniValue getinfo(const JSONRPCRequest& request)
" \"proxy\": \"host:port\", (string, optional) the proxy used by the server\n"
" \"difficulty\": xxxxxx, (numeric) the current difficulty\n"
" \"testnet\": true|false, (boolean) if the server is using testnet or not\n"
" \"moneysupply\": n (numeric) The sum of transparentsupply and shieldedsupply\n"
" \"transparentsupply\" : n (numeric) The sum of the value of all unspent outputs when the chainstate was\n"
" last flushed to disk (use getsupplyinfo to know the update-height, or\n"
" to trigger the money supply update/recalculation)"
Expand Down Expand Up @@ -130,6 +131,7 @@ UniValue getinfo(const JSONRPCRequest& request)

// Add (cached) money supply via getsupplyinfo RPC
UniValue supply_info = getsupplyinfo(JSONRPCRequest());
obj.pushKV("moneysupply", supply_info["totalsupply"]);
obj.pushKV("transparentsupply", supply_info["transparentsupply"]);
obj.pushKV("shieldedsupply", supply_info["shieldedsupply"]);

Expand Down

0 comments on commit ab9c8d0

Please sign in to comment.