Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/rawtransaction.cpp
Show First 20 Lines • Show All 593 Lines • ▼ Show 20 Lines | static UniValue decoderawtransaction(const Config &config, | ||||
} | } | ||||
UniValue result(UniValue::VOBJ); | UniValue result(UniValue::VOBJ); | ||||
TxToUniv(CTransaction(std::move(mtx)), uint256(), result, false); | TxToUniv(CTransaction(std::move(mtx)), uint256(), result, false); | ||||
return result; | return result; | ||||
} | } | ||||
static std::string GetAllOutputTypes() { | |||||
std::string ret; | |||||
for (int i = TX_NONSTANDARD; i <= TX_NULL_DATA; ++i) { | |||||
if (i != TX_NONSTANDARD) { | |||||
ret += ", "; | |||||
} | |||||
ret += GetTxnOutputType(static_cast<txnouttype>(i)); | |||||
} | |||||
return ret; | |||||
} | |||||
static UniValue decodescript(const Config &config, | static UniValue decodescript(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
RPCHelpMan{ | RPCHelpMan{ | ||||
"decodescript", | "decodescript", | ||||
"Decode a hex-encoded script.\n", | "Decode a hex-encoded script.\n", | ||||
{ | { | ||||
{"hexstring", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, | {"hexstring", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, | ||||
"the hex-encoded script"}, | "the hex-encoded script"}, | ||||
}, | }, | ||||
RPCResult{"{\n" | RPCResult{ | ||||
"{\n" | |||||
" \"asm\":\"asm\", (string) Script public key\n" | " \"asm\":\"asm\", (string) Script public key\n" | ||||
" \"hex\":\"hex\", (string) hex-encoded public key\n" | " \"type\":\"type\", (string) The output type (e.g. " + | ||||
" \"type\":\"type\", (string) The output type\n" | GetAllOutputTypes() + | ||||
")\n" | |||||
" \"reqSigs\": n, (numeric) The required signatures\n" | " \"reqSigs\": n, (numeric) The required signatures\n" | ||||
" \"addresses\": [ (json array of string)\n" | " \"addresses\": [ (json array of string)\n" | ||||
" \"address\" (string) bitcoin address\n" | " \"address\" (string) bitcoin address\n" | ||||
" ,...\n" | " ,...\n" | ||||
" ],\n" | " ],\n" | ||||
" \"p2sh\",\"address\" (string) address of P2SH script " | " \"p2sh\":\"str\" (string) address of P2SH script" | ||||
"wrapping this redeem script (not returned if the script is " | " wrapping this redeem script (not returned if the script" | ||||
"already a P2SH).\n" | " is already a P2SH).\n" | ||||
"}\n"}, | "}\n"}, | ||||
RPCExamples{HelpExampleCli("decodescript", "\"hexstring\"") + | RPCExamples{HelpExampleCli("decodescript", "\"hexstring\"") + | ||||
HelpExampleRpc("decodescript", "\"hexstring\"")}, | HelpExampleRpc("decodescript", "\"hexstring\"")}, | ||||
} | } | ||||
.Check(request); | .Check(request); | ||||
RPCTypeCheck(request.params, {UniValue::VSTR}); | RPCTypeCheck(request.params, {UniValue::VSTR}); | ||||
UniValue r(UniValue::VOBJ); | UniValue r(UniValue::VOBJ); | ||||
CScript script; | CScript script; | ||||
if (request.params[0].get_str().size() > 0) { | if (request.params[0].get_str().size() > 0) { | ||||
std::vector<uint8_t> scriptData( | std::vector<uint8_t> scriptData( | ||||
ParseHexV(request.params[0], "argument")); | ParseHexV(request.params[0], "argument")); | ||||
script = CScript(scriptData.begin(), scriptData.end()); | script = CScript(scriptData.begin(), scriptData.end()); | ||||
} else { | } else { | ||||
// Empty scripts are valid. | // Empty scripts are valid. | ||||
} | } | ||||
ScriptPubKeyToUniv(script, r, false); | ScriptPubKeyToUniv(script, r, /* fIncludeHex */ false); | ||||
UniValue type; | UniValue type; | ||||
type = find_value(r, "type"); | type = find_value(r, "type"); | ||||
if (type.isStr() && type.get_str() != "scripthash") { | if (type.isStr() && type.get_str() != "scripthash") { | ||||
// P2SH cannot be wrapped in a P2SH. If this script is already a P2SH, | // P2SH cannot be wrapped in a P2SH. If this script is already a P2SH, | ||||
// don't return the address for a P2SH of the P2SH. | // don't return the address for a P2SH of the P2SH. | ||||
r.pushKV("p2sh", EncodeDestination(ScriptHash(script), config)); | r.pushKV("p2sh", EncodeDestination(ScriptHash(script), config)); | ||||
▲ Show 20 Lines • Show All 1,383 Lines • Show Last 20 Lines |