Auto merge of #4790 - therealyingtong:add-addresses-getblocksubsidy, r=daira

Add funding stream addresses to getblocksubsidy RPC output

Closes #4728.
This commit is contained in:
Homu 2020-10-20 08:18:01 +00:00
commit 0dc05a7722
3 changed files with 47 additions and 9 deletions

View File

@ -193,7 +193,6 @@ UniValue blockToDeltasJSON(const CBlock& block, const CBlockIndex* blockindex)
if (IsValidDestination(dest)) {
delta.pushKV("address", keyIO.EncodeDestination(dest));
}
delta.pushKV("address", keyIO.EncodeDestination(dest));
delta.pushKV("satoshis", out.nValue);
delta.pushKV("index", (int)k);

View File

@ -13,6 +13,7 @@
#include "crypto/equihash.h"
#endif
#include "init.h"
#include "key_io.h"
#include "main.h"
#include "metrics.h"
#include "miner.h"
@ -882,15 +883,17 @@ UniValue getblocksubsidy(const UniValue& params, bool fHelp)
" \"founders\" : x.xxx, (numeric) The founders' reward amount in " + CURRENCY_UNIT + ".\n"
" \"fundingstreams\" : [ (array) An array of funding stream descriptions (present only when Canopy has activated).\n"
" {\n"
" \"recipient\" : \"...\", (string) A description of the funding stream recipient.\n"
" \"specification\" : \"url\", (string) A URL for the specification of this funding stream.\n"
" \"value\" : x.xxx (numeric) The funding stream amount in " + CURRENCY_UNIT + ".\n"
" \"recipient\" : \"...\", (string) A description of the funding stream recipient.\n"
" \"specification\" : \"url\", (string) A URL for the specification of this funding stream.\n"
" \"value\" : x.xxx (numeric) The funding stream amount in " + CURRENCY_UNIT + ".\n"
" \"valueZat\" : xxxx (numeric) The funding stream amount in " + MINOR_CURRENCY_UNIT + ".\n"
" \"address\" : (string) The transparent or Sapling address of the funding stream recipient.\n"
" }, ...\n"
" ]\n"
"}\n"
"\nExamples:\n"
+ HelpExampleCli("getblocksubsidy", "1000")
+ HelpExampleRpc("getblockubsidy", "1000")
+ HelpExampleRpc("getblocksubsidy", "1000")
);
LOCK(cs_main);
@ -906,9 +909,11 @@ UniValue getblocksubsidy(const UniValue& params, bool fHelp)
UniValue result(UniValue::VOBJ);
if (canopyActive) {
KeyIO keyIO(Params());
UniValue fundingstreams(UniValue::VARR);
auto fsinfos = Consensus::GetActiveFundingStreams(nHeight, consensus);
for (auto fsinfo : fsinfos) {
for (int idx = 0; idx < fsinfos.size(); idx++) {
const auto& fsinfo = fsinfos[idx];
CAmount nStreamAmount = fsinfo.Value(nBlockSubsidy);
nMinerReward -= nStreamAmount;
@ -916,6 +921,29 @@ UniValue getblocksubsidy(const UniValue& params, bool fHelp)
fsobj.pushKV("recipient", fsinfo.recipient);
fsobj.pushKV("specification", fsinfo.specification);
fsobj.pushKV("value", ValueFromAmount(nStreamAmount));
fsobj.pushKV("valueZat", nStreamAmount);
auto fs = consensus.vFundingStreams[idx];
auto address = fs.get().RecipientAddress(consensus, nHeight);
CScript* outpoint = boost::get<CScript>(&address);
std::string addressStr;
if (outpoint != nullptr) {
// For transparent funding stream addresses
UniValue pubkey(UniValue::VOBJ);
ScriptPubKeyToUniv(*outpoint, pubkey, true);
addressStr = find_value(pubkey, "addresses").get_array()[0].get_str();
} else {
libzcash::SaplingPaymentAddress* zaddr = boost::get<libzcash::SaplingPaymentAddress>(&address);
if (zaddr != nullptr) {
// For shielded funding stream addresses
addressStr = keyIO.EncodePaymentAddress(*zaddr);
}
}
fsobj.pushKV("address", addressStr);
fundingstreams.push_back(fsobj);
}
result.pushKV("fundingstreams", fundingstreams);

View File

@ -316,7 +316,7 @@ BOOST_AUTO_TEST_CASE(rpc_wallet)
BOOST_CHECK_EQUAL(find_value(obj, "founders").get_real(), 1.25);
BOOST_CHECK(!obj.exists("fundingstreams"));
auto check_funding_streams = [](UniValue obj, std::vector<std::string> recipients, std::vector<double> amounts) {
auto check_funding_streams = [](UniValue obj, std::vector<std::string> recipients, std::vector<double> amounts, std::vector<std::string> addresses) {
size_t n = recipients.size();
BOOST_REQUIRE_EQUAL(amounts.size(), n);
UniValue fundingstreams = find_value(obj, "fundingstreams");
@ -328,6 +328,7 @@ BOOST_AUTO_TEST_CASE(rpc_wallet)
BOOST_CHECK_EQUAL(find_value(fsobj, "recipient").get_str(), recipients[i]);
BOOST_CHECK_EQUAL(find_value(fsobj, "specification").get_str(), "https://zips.z.cash/zip-0214");
BOOST_CHECK_EQUAL(find_value(fsobj, "value").get_real(), amounts[i]);
BOOST_CHECK_EQUAL(find_value(fsobj, "address").get_str(), addresses[i]);
}
};
@ -341,7 +342,12 @@ BOOST_AUTO_TEST_CASE(rpc_wallet)
BOOST_CHECK_EQUAL(find_value(obj, "founders").get_real(), 0.0);
if (canopyEnabled) {
check_funding_streams(obj, {"Electric Coin Company", "Zcash Foundation", "Major Grants" },
{ 0.21875, 0.15625, 0.25 });
{ 0.21875, 0.15625, 0.25 },
{
"t3LmX1cxWPPPqL4TZHx42HU3U5ghbFjRiif",
"t3dvVE3SQEi7kqNzwrfNePxZ1d4hUyztBA1",
"t3XyYW8yBFRuMnfvm5KLGFbEVz25kckZXym"
});
}
BOOST_CHECK_NO_THROW(retValue = CallRPC("getblocksubsidy 2726399"));
@ -350,7 +356,12 @@ BOOST_AUTO_TEST_CASE(rpc_wallet)
BOOST_CHECK_EQUAL(find_value(obj, "founders").get_real(), 0.0);
if (canopyEnabled) {
check_funding_streams(obj, {"Electric Coin Company", "Zcash Foundation", "Major Grants" },
{ 0.21875, 0.15625, 0.25 });
{ 0.21875, 0.15625, 0.25 },
{
"t3XHAGxRP2FNfhAjxGjxbrQPYtQQjc3RCQD",
"t3dvVE3SQEi7kqNzwrfNePxZ1d4hUyztBA1",
"t3XyYW8yBFRuMnfvm5KLGFbEVz25kckZXym"
});
}
BOOST_CHECK_NO_THROW(retValue = CallRPC("getblocksubsidy 2726400"));