rpc: expand getaddressinfo embedded with explicit fields

Replace the ELISION entry inside getaddressinfo's embedded object
with explicit fields using ElideGroup().

Factor the embedded field list into a helper so the nested layout
can be reused without duplicating the full structure inline.
This commit is contained in:
Renato Britto
2026-03-17 00:44:57 -03:00
committed by satsfy (Renato Britto)
parent a9f9e7d17e
commit 88e2a6ae89

View File

@@ -365,6 +365,52 @@ static UniValue DescribeWalletAddress(const CWallet& wallet, const CTxDestinatio
return ret;
}
// NOLINTNEXTLINE(misc-no-recursion)
static std::vector<RPCResult> GetAddressInfoEmbeddedFields(bool include_nested)
{
auto fields = std::vector<RPCResult>{
{RPCResult::Type::STR, "address", /*optional=*/true, "The bitcoin address of the embedded script."},
{RPCResult::Type::STR_HEX, "scriptPubKey", /*optional=*/true, "The hex-encoded output script generated by the address."},
{RPCResult::Type::BOOL, "isscript", /*optional=*/true, "If the key is a script."},
{RPCResult::Type::BOOL, "iswitness", /*optional=*/true, "If the address is a witness address."},
{RPCResult::Type::NUM, "witness_version", /*optional=*/true, "The version number of the witness program."},
{RPCResult::Type::STR_HEX, "witness_program", /*optional=*/true, "The hex value of the witness program."},
{RPCResult::Type::STR, "script", /*optional=*/true,
"The output script type. Only if isscript is true and the redeemscript is known. Possible\n"
"types: nonstandard, pubkey, pubkeyhash, scripthash, multisig, nulldata, witness_v0_keyhash,\n"
"witness_v0_scripthash, witness_unknown."},
{RPCResult::Type::STR_HEX, "hex", /*optional=*/true, "The redeemscript for the p2sh address."},
{RPCResult::Type::ARR, "pubkeys", /*optional=*/true,
"Array of pubkeys associated with the known redeemscript (only if script is multisig).",
{
{RPCResult::Type::STR, "pubkey", ""},
}},
{RPCResult::Type::NUM, "sigsrequired", /*optional=*/true,
"The number of signatures required to spend multisig output (only if script is multisig)."},
{RPCResult::Type::STR_HEX, "pubkey", /*optional=*/true,
"The hex value of the raw public key for single-key addresses (possibly embedded in P2SH or P2WSH)."},
};
if (include_nested) {
fields.emplace_back(
RPCResult::Type::OBJ,
"embedded",
/*optional=*/true,
"Information about the address embedded in P2SH or P2WSH, if relevant and known.",
GetAddressInfoEmbeddedFields(/*include_nested=*/false)
);
}
fields.emplace_back(
RPCResult::Type::BOOL,
"iscompressed",
/*optional=*/true,
"If the pubkey is compressed."
);
return fields;
}
RPCMethod getaddressinfo()
{
return RPCMethod{
@@ -399,11 +445,13 @@ RPCMethod getaddressinfo()
}},
{RPCResult::Type::NUM, "sigsrequired", /*optional=*/true, "The number of signatures required to spend multisig output (only if script is multisig)."},
{RPCResult::Type::STR_HEX, "pubkey", /*optional=*/true, "The hex value of the raw public key for single-key addresses (possibly embedded in P2SH or P2WSH)."},
{RPCResult::Type::OBJ, "embedded", /*optional=*/true, "Information about the address embedded in P2SH or P2WSH, if relevant and known.",
{
{RPCResult::Type::ELISION, "", "Includes all getaddressinfo output fields for the embedded address, excluding metadata (timestamp, hdkeypath, hdseedid)\n"
"and relation to the wallet (ismine)."},
}},
{RPCResult::Type::OBJ, "embedded", /*optional=*/true,
"Information about the address embedded in P2SH or P2WSH, if relevant and known.",
ElideGroup(
GetAddressInfoEmbeddedFields(/*include_nested=*/true),
"Includes all getaddressinfo output fields for the embedded address, excluding metadata (timestamp, hdkeypath, hdseedid)\n"
"and relation to the wallet (ismine)."
)},
{RPCResult::Type::BOOL, "iscompressed", /*optional=*/true, "If the pubkey is compressed."},
{RPCResult::Type::NUM_TIME, "timestamp", /*optional=*/true, "The creation time of the key, if available, expressed in " + UNIX_EPOCH_TIME + "."},
{RPCResult::Type::STR, "hdkeypath", /*optional=*/true, "The HD keypath, if the key is HD and available."},