Skip to content

Commit

Permalink
Handle shielded address case
Browse files Browse the repository at this point in the history
  • Loading branch information
therealyingtong committed Oct 16, 2020
1 parent 6c41d1d commit 719c117
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
20 changes: 15 additions & 5 deletions src/rpc/mining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,7 @@ UniValue getblocksubsidy(const UniValue& params, bool fHelp)
" \"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\" : x.xxx (numeric) The funding stream amount in " + MINOR_CURRENCY_UNIT + ".\n"
" \"scriptPubKey\" : (string) scriptPubKey of the funding stream recipient.\n"
" \"pubKey\" : (json object) CScript or Sapling address of the funding stream recipient.\n"
" }, ...\n"
" ]\n"
"}\n"
Expand Down Expand Up @@ -927,10 +927,20 @@ UniValue getblocksubsidy(const UniValue& params, bool fHelp)

auto fs = consensus.vFundingStreams[idx];
auto address = fs.get().RecipientAddress(consensus, nHeight);
CScript outpoint = boost::get<CScript>(address);
UniValue outobj(UniValue::VOBJ);
ScriptPubKeyToJSON(outpoint, outobj, true);
fsobj.pushKV("scriptPubKey", outobj);

CScript* outpoint = boost::get<CScript>(&address);
libzcash::SaplingPaymentAddress* zaddr = boost::get<libzcash::SaplingPaymentAddress>(&address);
UniValue pubkey(UniValue::VOBJ);

if (outpoint != nullptr) {
// For transparent funding stream addresses
ScriptPubKeyToJSON(*outpoint, pubkey, true);
} else if (zaddr != nullptr) {
// For shielded funding stream addresses
pubkey.pushKV("address", keyIO.EncodePaymentAddress(*zaddr));
}

fsobj.pushKV("pubkey", pubkey);
fundingstreams.push_back(fsobj);
}
result.pushKV("fundingstreams", fundingstreams);
Expand Down
4 changes: 2 additions & 2 deletions src/wallet/test/rpc_wallet_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,8 @@ 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]);
auto outobj = find_value(fsobj, "outpoint").get_obj();
auto address = find_value(outobj, "addresses").get_array()[0].get_str();
auto pubkey = find_value(fsobj, "pubkey").get_obj();
auto address = find_value(pubkey, "addresses").get_array()[0].get_str();
BOOST_CHECK_EQUAL(address, addresses[i]);
}
};
Expand Down

0 comments on commit 719c117

Please sign in to comment.