Skip to content

Commit 9e7dc68

Browse files
author
MarcoFalke
committed
Merge #15616: rpc: Clarify decodescript RPCResult doc
fa926ec rpc: Mention all output types in decodescript doc (MarcoFalke) fa3caa1 rpc: decodescript use IsValidNumArgs over hardcoded check (MarcoFalke) faad33f rpc: Clarify decodescript RPCResult doc (MarcoFalke) Pull request description: * Remove `"hex"` from the decodescript RPCResult doc * Add `"segwit`" to the doc Follow up to a6099ef and 4f933b3 ACKs for commit fa926e: ryanofsky: utACK fa926ec. Only change since last review is listing possible output types in the help string using a new `GetAllOutputTypes` function Tree-SHA512: e6ecc563d04769942567118d50188467bf64ceb276ba6268928d469e8f06621f2ca1ae1e555d3daa6ec22a615ee259bb31c4141c19818d0f53fb6c529b18381b
2 parents 32e0428 + fa926ec commit 9e7dc68

File tree

1 file changed

+34
-13
lines changed

1 file changed

+34
-13
lines changed

src/rpc/rawtransaction.cpp

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -615,33 +615,54 @@ static UniValue decoderawtransaction(const JSONRPCRequest& request)
615615
return result;
616616
}
617617

618+
static std::string GetAllOutputTypes()
619+
{
620+
std::string ret;
621+
for (int i = TX_NONSTANDARD; i <= TX_WITNESS_UNKNOWN; ++i) {
622+
if (i != TX_NONSTANDARD) ret += ", ";
623+
ret += GetTxnOutputType(static_cast<txnouttype>(i));
624+
}
625+
return ret;
626+
}
627+
618628
static UniValue decodescript(const JSONRPCRequest& request)
619629
{
620-
if (request.fHelp || request.params.size() != 1)
621-
throw std::runtime_error(
622-
RPCHelpMan{"decodescript",
630+
const RPCHelpMan help{"decodescript",
623631
"\nDecode a hex-encoded script.\n",
624632
{
625633
{"hexstring", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "the hex-encoded script"},
626634
},
627635
RPCResult{
628636
"{\n"
629-
" \"asm\":\"asm\", (string) Script public key\n"
630-
" \"hex\":\"hex\", (string) hex-encoded public key\n"
631-
" \"type\":\"type\", (string) The output type\n"
632-
" \"reqSigs\": n, (numeric) The required signatures\n"
633-
" \"addresses\": [ (json array of string)\n"
634-
" \"address\" (string) bitcoin address\n"
637+
" \"asm\":\"asm\", (string) Script public key\n"
638+
" \"type\":\"type\", (string) The output type (e.g. "+GetAllOutputTypes()+")\n"
639+
" \"reqSigs\": n, (numeric) The required signatures\n"
640+
" \"addresses\": [ (json array of string)\n"
641+
" \"address\" (string) bitcoin address\n"
635642
" ,...\n"
636643
" ],\n"
637-
" \"p2sh\",\"address\" (string) address of P2SH script wrapping this redeem script (not returned if the script is already a P2SH).\n"
644+
" \"p2sh\":\"str\" (string) address of P2SH script wrapping this redeem script (not returned if the script is already a P2SH).\n"
645+
" \"segwit\": { (json object) Result of a witness script public key wrapping this redeem script (not returned if the script is a P2SH or witness).\n"
646+
" \"asm\":\"str\", (string) String representation of the script public key\n"
647+
" \"hex\":\"hexstr\", (string) Hex string of the script public key\n"
648+
" \"type\":\"str\", (string) The type of the script public key (e.g. witness_v0_keyhash or witness_v0_scripthash)\n"
649+
" \"reqSigs\": n, (numeric) The required signatures (always 1)\n"
650+
" \"addresses\": [ (json array of string) (always length 1)\n"
651+
" \"address\" (string) segwit address\n"
652+
" ,...\n"
653+
" ],\n"
654+
" \"p2sh-segwit\":\"str\" (string) address of the P2SH script wrapping this witness redeem script.\n"
638655
"}\n"
639656
},
640657
RPCExamples{
641658
HelpExampleCli("decodescript", "\"hexstring\"")
642659
+ HelpExampleRpc("decodescript", "\"hexstring\"")
643660
},
644-
}.ToString());
661+
};
662+
663+
if (request.fHelp || !help.IsValidNumArgs(request.params.size())) {
664+
throw std::runtime_error(help.ToString());
665+
}
645666

646667
RPCTypeCheck(request.params, {UniValue::VSTR});
647668

@@ -653,7 +674,7 @@ static UniValue decodescript(const JSONRPCRequest& request)
653674
} else {
654675
// Empty scripts are valid
655676
}
656-
ScriptPubKeyToUniv(script, r, false);
677+
ScriptPubKeyToUniv(script, r, /* fIncludeHex */ false);
657678

658679
UniValue type;
659680
type = find_value(r, "type");
@@ -687,7 +708,7 @@ static UniValue decodescript(const JSONRPCRequest& request)
687708
// Newer segwit program versions should be considered when then become available.
688709
segwitScr = GetScriptForDestination(WitnessV0ScriptHash(script));
689710
}
690-
ScriptPubKeyToUniv(segwitScr, sr, true);
711+
ScriptPubKeyToUniv(segwitScr, sr, /* fIncludeHex */ true);
691712
sr.pushKV("p2sh-segwit", EncodeDestination(CScriptID(segwitScr)));
692713
r.pushKV("segwit", sr);
693714
}

0 commit comments

Comments
 (0)