Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
751tfm::format(std::cout, "%s\n", jsonOutput);752}754static void OutputTxHash(const CTransaction& tx)755{756std::string strHexHash = tx.GetHash().GetHex(); // the hex-encoded transaction hash (aka the transaction id)758tfm::format(std::cout, "%s\n", strHexHash);759}761static void OutputTxHex(const CTransaction& tx)762{763std::string strHex = EncodeHexTx(tx);765tfm::format(std::cout, "%s\n", strHex);766}768static void OutputTx(const CTransaction& tx)769{770if (gArgs.GetBoolArg("-json", false))771OutputTxJSON(tx);772else if (gArgs.GetBoolArg("-txid", false))773OutputTxHash(tx);774else775OutputTxHex(tx);776}778static std::string readStdin()779{780char buf[4096];781std::string ret;783while (!feof(stdin)) {784size_t bread = fread(buf, 1, sizeof(buf), stdin);785ret.append(buf, bread);786if (bread < sizeof(buf))787break;788}790if (ferror(stdin))791throw std::runtime_error("error reading stdin");793return TrimString(ret);794}796static int CommandLineRawTx(int argc, char* argv[])797{798std::string strPrint;799int nRet = 0;800try {801// Skip switches; Permit common stdin convention "-"802while (argc > 1 && IsSwitchChar(argv[1][0]) &&803(argv[1][1] != 0)) {804argc--;805argv++;806}808CMutableTransaction tx;809int startArg;811if (!fCreateBlank) {812// require at least one param813if (argc < 2)814throw std::runtime_error("too few parameters");816// param: hex-encoded bitcoin transaction817std::string strHexTx(argv[1]);818if (strHexTx == "-") // "-" implies standard input819strHexTx = readStdin();821if (!DecodeHexTx(tx, strHexTx, true))822throw std::runtime_error("invalid transaction encoding");824startArg = 2;825} else826startArg = 1;828for (int i = startArg; i < argc; i++) {829std::string arg = argv[i];830std::string key, value;831size_t eqpos = arg.find('=');832if (eqpos == std::string::npos)833key = arg;834else {835key = arg.substr(0, eqpos);836value = arg.substr(eqpos + 1);837}839MutateTx(tx, key, value);840}842OutputTx(CTransaction(tx));843}844catch (const std::exception& e) {845strPrint = std::string("error: ") + e.what();846nRet = EXIT_FAILURE;847}848catch (...) {849PrintExceptionContinue(nullptr, "CommandLineRawTx()");850throw;851}853if (strPrint != "") {854tfm::format(nRet == 0 ? std::cout : std::cerr, "%s\n", strPrint);855}856return nRet;857}859MAIN_FUNCTION860{861SetupEnvironment();862SHA256AutoDetect();864try {865int ret = AppInitRawTx(argc, argv);866if (ret != CONTINUE_EXECUTION)867return ret;868}869catch (const std::exception& e) {870PrintExceptionContinue(&e, "AppInitRawTx()");871return EXIT_FAILURE;872} catch (...) {873PrintExceptionContinue(nullptr, "AppInitRawTx()");874return EXIT_FAILURE;875}877int ret = EXIT_FAILURE;878try {879ret = CommandLineRawTx(argc, argv);880}881catch (const std::exception& e) {882PrintExceptionContinue(&e, "CommandLineRawTx()");883} catch (...) {884PrintExceptionContinue(nullptr, "CommandLineRawTx()");885}886return ret;887}
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.