Add Orchard support to the z_gettreestate RPC

This commit is contained in:
Steven Smith 2022-02-17 06:14:21 -08:00
parent d0d6d47aa7
commit 59c6b028f7
1 changed files with 32 additions and 0 deletions

View File

@ -1247,6 +1247,13 @@ UniValue z_gettreestate(const UniValue& params, bool fHelp)
" \"finalRoot\": \"hex\", (string)\n" " \"finalRoot\": \"hex\", (string)\n"
" \"finalState\": \"hex\" (string)\n" " \"finalState\": \"hex\" (string)\n"
" }\n" " }\n"
" },\n"
" \"orchard\": {\n"
" \"skipHash\": \"hash\", (string) hash of most recent block with more information\n"
" \"commitments\": {\n"
" \"finalRoot\": \"hex\", (string)\n"
" \"finalState\": \"hex\" (string)\n"
" }\n"
" }\n" " }\n"
"}\n" "}\n"
"\nExamples:\n" "\nExamples:\n"
@ -1327,6 +1334,31 @@ UniValue z_gettreestate(const UniValue& params, bool fHelp)
res.pushKV("sapling", sapling_result); res.pushKV("sapling", sapling_result);
} }
// orchard
{
UniValue orchard_result(UniValue::VOBJ);
UniValue orchard_commitments(UniValue::VOBJ);
orchard_commitments.pushKV("finalRoot", pindex->hashFinalOrchardRoot.GetHex());
bool need_skiphash = false;
OrchardMerkleFrontier tree;
if (pcoinsTip->GetOrchardAnchorAt(pindex->hashFinalOrchardRoot, tree)) {
CDataStream s(SER_NETWORK, PROTOCOL_VERSION);
s << tree;
orchard_commitments.pushKV("finalState", HexStr(s.begin(), s.end()));
} else {
// Set skipHash to the most recent block that has a finalState.
const CBlockIndex* pindex_skip = pindex->pprev;
while (pindex_skip && !pcoinsTip->GetOrchardAnchorAt(pindex_skip->hashFinalOrchardRoot, tree)) {
pindex_skip = pindex_skip->pprev;
}
if (pindex_skip) {
orchard_result.pushKV("skipHash", pindex_skip->GetBlockHash().GetHex());
}
}
orchard_result.pushKV("commitments", orchard_commitments);
res.pushKV("orchard", orchard_result);
}
return res; return res;
} }