Skip to content

Commit

Permalink
Merge bitcoin#15616: rpc: Clarify decodescript RPCResult doc
Browse files Browse the repository at this point in the history
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
  • Loading branch information
MarcoFalke committed Mar 28, 2019
2 parents 32e0428 + fa926ec commit 9e7dc68
Showing 1 changed file with 34 additions and 13 deletions.
47 changes: 34 additions & 13 deletions src/rpc/rawtransaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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});

Expand All @@ -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");
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 9e7dc68

Please sign in to comment.