MCPcopy Create free account
hub / github.com/ElementsProject/elements / decodescript

Function decodescript

src/rpc/rawtransaction.cpp:587–726  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

585}
586
587static RPCHelpMan decodescript()
588{
589 return RPCHelpMan{
590 "decodescript",
591 "\nDecode a hex-encoded script.\n",
592 {
593 {"hexstring", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "the hex-encoded script"},
594 },
595 RPCResult{
596 RPCResult::Type::OBJ, "", "",
597 {
598 {RPCResult::Type::STR, "asm", "Script public key"},
599 {RPCResult::Type::STR, "desc", "Inferred descriptor for the script"},
600 {RPCResult::Type::STR, "type", "The output type (e.g. " + GetAllOutputTypes() + ")"},
601 {RPCResult::Type::STR, "address", /*optional=*/true, "The Bitcoin address (only if a well-defined address exists)"},
602 {RPCResult::Type::STR, "p2sh", /*optional=*/true,
603 "address of P2SH script wrapping this redeem script (not returned for types that should not be wrapped)"},
604 {RPCResult::Type::OBJ, "segwit", /*optional=*/true,
605 "Result of a witness script public key wrapping this redeem script (not returned for types that should not be wrapped)",
606 {
607 {RPCResult::Type::STR, "asm", "String representation of the script public key"},
608 {RPCResult::Type::STR_HEX, "hex", "Hex string of the script public key"},
609 {RPCResult::Type::STR, "type", "The type of the script public key (e.g. witness_v0_keyhash or witness_v0_scripthash)"},
610 {RPCResult::Type::STR, "address", /*optional=*/true, "The Bitcoin address (only if a well-defined address exists)"},
611 {RPCResult::Type::STR, "desc", "Inferred descriptor for the script"},
612 {RPCResult::Type::STR, "p2sh-segwit", "address of the P2SH script wrapping this witness redeem script"},
613 }},
614 },
615 },
616 RPCExamples{
617 HelpExampleCli("decodescript", "\"hexstring\"")
618 + HelpExampleRpc("decodescript", "\"hexstring\"")
619 },
620 [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
621{
622 RPCTypeCheck(request.params, {UniValue::VSTR});
623
624 UniValue r(UniValue::VOBJ);
625 CScript script;
626 if (request.params[0].get_str().size() > 0){
627 std::vector<unsigned char> scriptData(ParseHexV(request.params[0], "argument"));
628 script = CScript(scriptData.begin(), scriptData.end());
629 } else {
630 // Empty scripts are valid
631 }
632 ScriptPubKeyToUniv(script, r, /* include_hex */ false);
633
634 std::vector<std::vector<unsigned char>> solutions_data;
635 const TxoutType which_type{Solver(script, solutions_data)};
636
637 const bool can_wrap{[&] {
638 switch (which_type) {
639 // ELEMENTS
640 case TxoutType::OP_TRUE:
641 case TxoutType::FEE:
642 return true;
643 case TxoutType::MULTISIG:
644 case TxoutType::NONSTANDARD:

Callers

nothing calls this directly

Calls 15

GetAllOutputTypesFunction · 0.85
HelpExampleCliFunction · 0.85
HelpExampleRpcFunction · 0.85
RPCTypeCheckFunction · 0.85
ParseHexVFunction · 0.85
ScriptPubKeyToUnivFunction · 0.85
SolverFunction · 0.85
IsOpSuccessFunction · 0.85
EncodeDestinationFunction · 0.85
ScriptHashClass · 0.85
GetScriptForDestinationFunction · 0.85
WitnessV0KeyHashClass · 0.85

Tested by

no test coverage detected