MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / decoderawtransaction

Function decoderawtransaction

src/rpc/rawtransaction.cpp:399–438  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

397}
398
399static RPCMethod decoderawtransaction()
400{
401 return RPCMethod{"decoderawtransaction",
402 "Return a JSON object representing the serialized, hex-encoded transaction.",
403 {
404 {"hexstring", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The transaction hex string"},
405 {"iswitness", RPCArg::Type::BOOL, RPCArg::DefaultHint{"depends on heuristic tests"}, "Whether the transaction hex is a serialized witness transaction.\n"
406 "If iswitness is not present, heuristic tests will be used in decoding.\n"
407 "If true, only witness deserialization will be tried.\n"
408 "If false, only non-witness deserialization will be tried.\n"
409 "This boolean should reflect whether the transaction has inputs\n"
410 "(e.g. fully valid, or on-chain transactions), if known by the caller."
411 },
412 },
413 RPCResult{
414 RPCResult::Type::OBJ, "", "",
415 TxDoc(),
416 },
417 RPCExamples{
418 HelpExampleCli("decoderawtransaction", "\"hexstring\"")
419 + HelpExampleRpc("decoderawtransaction", "\"hexstring\"")
420 },
421 [](const RPCMethod& self, const JSONRPCRequest& request) -> UniValue
422{
423 CMutableTransaction mtx;
424
425 bool try_witness = request.params[1].isNull() ? true : request.params[1].get_bool();
426 bool try_no_witness = request.params[1].isNull() ? true : !request.params[1].get_bool();
427
428 if (!DecodeHexTx(mtx, request.params[0].get_str(), try_no_witness, try_witness)) {
429 throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed");
430 }
431
432 UniValue result(UniValue::VOBJ);
433 TxToUniv(CTransaction(std::move(mtx)), /*block_hash=*/uint256(), /*entry=*/result, /*include_hex=*/false);
434
435 return result;
436},
437 };
438}
439
440static RPCMethod decodescript()
441{

Callers

nothing calls this directly

Calls 10

TxDocFunction · 0.85
HelpExampleCliFunction · 0.85
HelpExampleRpcFunction · 0.85
DecodeHexTxFunction · 0.85
JSONRPCErrorFunction · 0.85
TxToUnivFunction · 0.85
isNullMethod · 0.80
get_boolMethod · 0.80
CTransactionClass · 0.50
uint256Class · 0.50

Tested by

no test coverage detected