Merge #15616: rpc: Clarify decodescript RPCResult doc

fa926ec24f rpc: Mention all output types in decodescript doc (MarcoFalke)
fa3caa1666 rpc: decodescript use IsValidNumArgs over hardcoded check (MarcoFalke)
faad33ff15 rpc: Clarify decodescript RPCResult doc (MarcoFalke)

Pull request description:

  * Remove `"hex"` from the decodescript RPCResult doc
  * Add `"segwit`" to the doc

  Follow up to a6099ef319 and 4f933b3d23

ACKs for commit fa926e:
  ryanofsky:
    utACK fa926ec24f. Only change since last review is listing possible output types in the help string using a new `GetAllOutputTypes` function

Tree-SHA512: e6ecc563d04769942567118d50188467bf64ceb276ba6268928d469e8f06621f2ca1ae1e555d3daa6ec22a615ee259bb31c4141c19818d0f53fb6c529b18381b
This commit is contained in:
MarcoFalke 2019-03-28 10:56:20 -04:00
commit 9e7dc682e0
No known key found for this signature in database
GPG key ID: D2EA4850E7528B25

View file

@ -615,33 +615,54 @@ static UniValue decoderawtransaction(const JSONRPCRequest& request)
return result;
}
static std::string GetAllOutputTypes()
{
std::string ret;
for (int i = TX_NONSTANDARD; i <= TX_WITNESS_UNKNOWN; ++i) {
if (i != TX_NONSTANDARD) ret += ", ";
ret += GetTxnOutputType(static_cast<txnouttype>(i));
}
return ret;
}
static UniValue decodescript(const JSONRPCRequest& request)
{
if (request.fHelp || request.params.size() != 1)
throw std::runtime_error(
RPCHelpMan{"decodescript",
const RPCHelpMan help{"decodescript",
"\nDecode a hex-encoded script.\n",
{
{"hexstring", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "the hex-encoded script"},
},
RPCResult{
"{\n"
" \"asm\":\"asm\", (string) Script public key\n"
" \"hex\":\"hex\", (string) hex-encoded public key\n"
" \"type\":\"type\", (string) The output type\n"
" \"reqSigs\": n, (numeric) The required signatures\n"
" \"addresses\": [ (json array of string)\n"
" \"address\" (string) bitcoin address\n"
" \"asm\":\"asm\", (string) Script public key\n"
" \"type\":\"type\", (string) The output type (e.g. "+GetAllOutputTypes()+")\n"
" \"reqSigs\": n, (numeric) The required signatures\n"
" \"addresses\": [ (json array of string)\n"
" \"address\" (string) bitcoin address\n"
" ,...\n"
" ],\n"
" \"p2sh\",\"address\" (string) address of P2SH script wrapping this redeem script (not returned if the script is already a P2SH).\n"
" \"p2sh\":\"str\" (string) address of P2SH script wrapping this redeem script (not returned if the script is already a P2SH).\n"
" \"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"
" \"asm\":\"str\", (string) String representation of the script public key\n"
" \"hex\":\"hexstr\", (string) Hex string of the script public key\n"
" \"type\":\"str\", (string) The type of the script public key (e.g. witness_v0_keyhash or witness_v0_scripthash)\n"
" \"reqSigs\": n, (numeric) The required signatures (always 1)\n"
" \"addresses\": [ (json array of string) (always length 1)\n"
" \"address\" (string) segwit address\n"
" ,...\n"
" ],\n"
" \"p2sh-segwit\":\"str\" (string) address of the P2SH script wrapping this witness redeem script.\n"
"}\n"
},
RPCExamples{
HelpExampleCli("decodescript", "\"hexstring\"")
+ HelpExampleRpc("decodescript", "\"hexstring\"")
},
}.ToString());
};
if (request.fHelp || !help.IsValidNumArgs(request.params.size())) {
throw std::runtime_error(help.ToString());
}
RPCTypeCheck(request.params, {UniValue::VSTR});
@ -653,7 +674,7 @@ static UniValue decodescript(const JSONRPCRequest& request)
} else {
// Empty scripts are valid
}
ScriptPubKeyToUniv(script, r, false);
ScriptPubKeyToUniv(script, r, /* fIncludeHex */ false);
UniValue type;
type = find_value(r, "type");
@ -687,7 +708,7 @@ static UniValue decodescript(const JSONRPCRequest& request)
// Newer segwit program versions should be considered when then become available.
segwitScr = GetScriptForDestination(WitnessV0ScriptHash(script));
}
ScriptPubKeyToUniv(segwitScr, sr, true);
ScriptPubKeyToUniv(segwitScr, sr, /* fIncludeHex */ true);
sr.pushKV("p2sh-segwit", EncodeDestination(CScriptID(segwitScr)));
r.pushKV("segwit", sr);
}