diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 5f3a54d2f..90b8e7201 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -856,6 +856,39 @@ UniValue gettxoutsetinfo(const UniValue& params, bool fHelp, const CPubKey& mypk return ret; } +UniValue getblockmerkletree(const UniValue& params, bool fHelp, const CPubKey& mypk) +{ + if (fHelp || params.size() != 1 ) + throw runtime_error( + "getblockmerkletree height\n" + "\nGet full merkletree for a given Hush or HSC block height.\n" + "\nArguments:\n" + "1. height (int, required) block height\n" + "\nResult:\n" + "\"hex\" (string) the merkle tree hex encoded\n" + + HelpExampleCli("getblockmerkletree", "290000") + + HelpExampleRpc("getblockmerkletree", "290000") + ); + + CBlockIndex* phushblockindex; + uint256 blockRoot; + SaplingMerkleTree tree; + + int nHeight = params[0].get_int(); + if ( (nHeight < 1) || (nHeight > chainActive.LastTip()->GetHeight()) ) { + throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid Hush or HSC block height parameter"); + } + + phushblockindex = chainActive[nHeight]; + blockRoot = phushblockindex->hashFinalSaplingRoot; + if( pcoinsTip->GetSaplingAnchorAt(blockRoot, tree) ) { + CDataStream ss(SER_NETWORK, PROTOCOL_VERSION); + ss << tree; + return HexStr(ss.begin(), ss.end()); + } else { + throw JSONRPCError(RPC_INVALID_PARAMETER, "Could not find merkletree"); + } +} UniValue kvsearch(const UniValue& params, bool fHelp, const CPubKey& mypk) { @@ -1877,6 +1910,7 @@ static const CRPCCommand commands[] = { "blockchain", "getblockcount", &getblockcount, true }, { "blockchain", "getblock", &getblock, true }, { "blockchain", "getblockhash", &getblockhash, true }, + { "blockchain", "getblockmerkletree", &getblockmerkletree, true }, { "blockchain", "getblockheader", &getblockheader, true }, { "blockchain", "getchaintips", &getchaintips, true }, { "blockchain", "getchaintxstats", &getchaintxstats, true }, diff --git a/src/rpc/client.cpp b/src/rpc/client.cpp index 916273043..e427ec3ff 100644 --- a/src/rpc/client.cpp +++ b/src/rpc/client.cpp @@ -63,6 +63,7 @@ static const CRPCConvertParam vRPCConvertParams[] = { "getbalance", 1 }, { "getbalance", 2 }, { "getblockhash", 0 }, + { "getblockmerkletree", 0 }, { "move", 2 }, { "move", 3 }, { "sendfrom", 2 },