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.
751" \"ALL|ANYONECANPAY\"\n"752" \"NONE|ANYONECANPAY\"\n"753" \"SINGLE|ANYONECANPAY\"\n"754},755},756RPCResult{757RPCResult::Type::OBJ, "", "",758{759{RPCResult::Type::STR_HEX, "hex", "The hex-encoded raw transaction with signature(s)"},760{RPCResult::Type::BOOL, "complete", "If the transaction has a complete set of signatures"},761{RPCResult::Type::ARR, "errors", /*optional=*/true, "Script verification errors (if there are any)",762{763{RPCResult::Type::OBJ, "", "",764{765{RPCResult::Type::STR_HEX, "txid", "The hash of the referenced, previous transaction"},766{RPCResult::Type::NUM, "vout", "The index of the output to spent and used as input"},767{RPCResult::Type::ARR, "witness", "",768{769{RPCResult::Type::STR_HEX, "witness", ""},770}},771{RPCResult::Type::STR_HEX, "scriptSig", "The hex-encoded signature script"},772{RPCResult::Type::NUM, "sequence", "Script sequence number"},773{RPCResult::Type::STR, "error", "Verification or signing error related to the input"},774}},775}},776}777},778RPCExamples{779HelpExampleCli("signrawtransactionwithkey", "\"myhex\" \"[\\\"key1\\\",\\\"key2\\\"]\"")780+ HelpExampleRpc("signrawtransactionwithkey", "\"myhex\", \"[\\\"key1\\\",\\\"key2\\\"]\"")781},782[](const RPCMethod& self, const JSONRPCRequest& request) -> UniValue783{784CMutableTransaction mtx;785if (!DecodeHexTx(mtx, request.params[0].get_str())) {786throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed. Make sure the tx has at least one input.");787}789FlatSigningProvider keystore;790const UniValue& keys = request.params[1].get_array();791for (unsigned int idx = 0; idx < keys.size(); ++idx) {792UniValue k = keys[idx];793CKey key = DecodeSecret(k.get_str());794if (!key.IsValid()) {795throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid private key");796}798CPubKey pubkey = key.GetPubKey();799CKeyID key_id = pubkey.GetID();800keystore.pubkeys.emplace(key_id, pubkey);801keystore.keys.emplace(key_id, key);802}804// Fetch previous transactions (inputs):805std::map<COutPoint, Coin> coins;806for (const CTxIn& txin : mtx.vin) {807coins[txin.prevout]; // Create empty map entry keyed by prevout.808}809NodeContext& node = EnsureAnyNodeContext(request.context);810FindCoins(node, coins);812// Parse the prevtxs array813ParsePrevouts(request.params[2], &keystore, coins);815UniValue result(UniValue::VOBJ);816SignTransaction(mtx, &keystore, coins, request.params[3], result);817return result;818},819};820}822const RPCResult& DecodePSBTInputs()823{824static const RPCResult decodepsbt_inputs{825RPCResult::Type::ARR, "inputs", "",826{827{RPCResult::Type::OBJ, "", "",828{829{RPCResult::Type::OBJ, "non_witness_utxo", /*optional=*/true, "Decoded network transaction for non-witness UTXOs",830TxDoc({.elision_mode = ElisionMode::WithSummary, .elision_summary = "The layout is the same as the output of decoderawtransaction."})831},832{RPCResult::Type::OBJ, "witness_utxo", /*optional=*/true, "Transaction output for witness UTXOs",833{834{RPCResult::Type::NUM, "amount", "The value in " + CURRENCY_UNIT},835{RPCResult::Type::OBJ, "scriptPubKey", "",836{837{RPCResult::Type::STR, "asm", "Disassembly of the output script"},838{RPCResult::Type::STR, "desc", "Inferred descriptor for the output"},839{RPCResult::Type::STR_HEX, "hex", "The raw output script bytes, hex-encoded"},840{RPCResult::Type::STR, "type", "The type, eg 'pubkeyhash'"},841{RPCResult::Type::STR, "address", /*optional=*/true, "The Bitcoin address (only if a well-defined address exists)"},842}},843}},844{RPCResult::Type::OBJ_DYN, "partial_signatures", /*optional=*/true, "",845{846{RPCResult::Type::STR, "pubkey", "The public key and signature that corresponds to it."},847}},848{RPCResult::Type::STR, "sighash", /*optional=*/true, "The sighash type to be used"},849{RPCResult::Type::OBJ, "redeem_script", /*optional=*/true, "",850{851{RPCResult::Type::STR, "asm", "Disassembly of the redeem script"},852{RPCResult::Type::STR_HEX, "hex", "The raw redeem script bytes, hex-encoded"},853{RPCResult::Type::STR, "type", "The type, eg 'pubkeyhash'"},854}},855{RPCResult::Type::OBJ, "witness_script", /*optional=*/true, "",856{857{RPCResult::Type::STR, "asm", "Disassembly of the witness script"},858{RPCResult::Type::STR_HEX, "hex", "The raw witness script bytes, hex-encoded"},859{RPCResult::Type::STR, "type", "The type, eg 'pubkeyhash'"},860}},861{RPCResult::Type::ARR, "bip32_derivs", /*optional=*/true, "",862{863{RPCResult::Type::OBJ, "", "",864{865{RPCResult::Type::STR, "pubkey", "The public key with the derivation path as the value."},866{RPCResult::Type::STR, "master_fingerprint", "The fingerprint of the master key"},867{RPCResult::Type::STR, "path", "The path"},868}},869}},870{RPCResult::Type::OBJ, "final_scriptSig", /*optional=*/true, "",871{872{RPCResult::Type::STR, "asm", "Disassembly of the final signature script"},873{RPCResult::Type::STR_HEX, "hex", "The raw final signature script bytes, hex-encoded"},874}},875{RPCResult::Type::ARR, "final_scriptwitness", /*optional=*/true, "",876{877{RPCResult::Type::STR_HEX, "", "hex-encoded witness data (if any)"},878}},879{RPCResult::Type::OBJ_DYN, "ripemd160_preimages", /*optional=*/ true, "",880{881{RPCResult::Type::STR, "hash", "The hash and preimage that corresponds to it."},882}},883{RPCResult::Type::OBJ_DYN, "sha256_preimages", /*optional=*/ true, "",884{885{RPCResult::Type::STR, "hash", "The hash and preimage that corresponds to it."},886}},887{RPCResult::Type::OBJ_DYN, "hash160_preimages", /*optional=*/ true, "",888{889{RPCResult::Type::STR, "hash", "The hash and preimage that corresponds to it."},890}},891{RPCResult::Type::OBJ_DYN, "hash256_preimages", /*optional=*/ true, "",892{893{RPCResult::Type::STR, "hash", "The hash and preimage that corresponds to it."},894}},895{RPCResult::Type::STR_HEX, "previous_txid", /*optional=*/true, "TXID of the transaction containing the output being spent by this input"},896{RPCResult::Type::NUM, "previous_vout", /*optional=*/true, "Index of the output being spent"},897{RPCResult::Type::NUM, "sequence", /*optional=*/true, "Sequence number for this input"},898{RPCResult::Type::NUM, "time_locktime", /*optional=*/true, "Time-based locktime required for this input"},899{RPCResult::Type::NUM, "height_locktime", /*optional=*/true, "Height-based locktime required for this input"},900{RPCResult::Type::STR_HEX, "taproot_key_path_sig", /*optional=*/ true, "hex-encoded signature for the Taproot key path spend"},901{RPCResult::Type::ARR, "taproot_script_path_sigs", /*optional=*/ true, "",902{903{RPCResult::Type::OBJ, "signature", /*optional=*/ true, "The signature for the pubkey and leaf hash combination",904{905{RPCResult::Type::STR, "pubkey", "The x-only pubkey for this signature"},906{RPCResult::Type::STR, "leaf_hash", "The leaf hash for this signature"},907{RPCResult::Type::STR, "sig", "The signature itself"},908}},909}},910{RPCResult::Type::ARR, "taproot_scripts", /*optional=*/ true, "",911{912{RPCResult::Type::OBJ, "", "",913{914{RPCResult::Type::STR_HEX, "script", "A leaf script"},915{RPCResult::Type::NUM, "leaf_ver", "The version number for the leaf script"},916{RPCResult::Type::ARR, "control_blocks", "The control blocks for this script",917{918{RPCResult::Type::STR_HEX, "control_block", "A hex-encoded control block for this script"},919}},920}},921}},922{RPCResult::Type::ARR, "taproot_bip32_derivs", /*optional=*/ true, "",923{924{RPCResult::Type::OBJ, "", "",925{926{RPCResult::Type::STR, "pubkey", "The x-only public key this path corresponds to"},927{RPCResult::Type::STR, "master_fingerprint", "The fingerprint of the master key"},928{RPCResult::Type::STR, "path", "The path"},929{RPCResult::Type::ARR, "leaf_hashes", "The hashes of the leaves this pubkey appears in",930{931{RPCResult::Type::STR_HEX, "hash", "The hash of a leaf this pubkey appears in"},932}},933}},934}},935{RPCResult::Type::STR_HEX, "taproot_internal_key", /*optional=*/ true, "The hex-encoded Taproot x-only internal key"},936{RPCResult::Type::STR_HEX, "taproot_merkle_root", /*optional=*/ true, "The hex-encoded Taproot merkle root"},937{RPCResult::Type::ARR, "musig2_participant_pubkeys", /*optional=*/true, "",938{939{RPCResult::Type::OBJ, "", "",940{941{RPCResult::Type::STR_HEX, "aggregate_pubkey", "The compressed aggregate public key for which the participants create."},942{RPCResult::Type::ARR, "participant_pubkeys", "",943{944{RPCResult::Type::STR_HEX, "pubkey", "The compressed public keys that are aggregated for aggregate_pubkey."},945}},946}},947}},948{RPCResult::Type::ARR, "musig2_pubnonces", /*optional=*/true, "",949{950{RPCResult::Type::OBJ, "", "",951{952{RPCResult::Type::STR_HEX, "participant_pubkey", "The compressed public key of the participant that created this pubnonce."},953{RPCResult::Type::STR_HEX, "aggregate_pubkey", "The compressed aggregate public key for which this pubnonce is for."},954{RPCResult::Type::STR_HEX, "leaf_hash", /*optional=*/true, "The hash of the leaf script that contains the aggregate pubkey being signed for. Omitted when signing for the internal key."},955{RPCResult::Type::STR_HEX, "pubnonce", "The public nonce itself."},956}},957}},958{RPCResult::Type::ARR, "musig2_partial_sigs", /*optional=*/true, "",959{960{RPCResult::Type::OBJ, "", "",961{962{RPCResult::Type::STR_HEX, "participant_pubkey", "The compressed public key of the participant that created this partial signature."},963{RPCResult::Type::STR_HEX, "aggregate_pubkey", "The compressed aggregate public key for which this partial signature is for."},964{RPCResult::Type::STR_HEX, "leaf_hash", /*optional=*/true, "The hash of the leaf script that contains the aggregate pubkey being signed for. Omitted when signing for the internal key."},965{RPCResult::Type::STR_HEX, "partial_sig", "The partial signature itself."},966}},967}},968{RPCResult::Type::OBJ_DYN, "unknown", /*optional=*/ true, "The unknown input fields",969{970{RPCResult::Type::STR_HEX, "key", "(key-value pair) An unknown key-value pair"},971}},972{RPCResult::Type::ARR, "proprietary", /*optional=*/true, "The input proprietary map",973{974{RPCResult::Type::OBJ, "", "",975{976{RPCResult::Type::STR_HEX, "identifier", "The hex string for the proprietary identifier"},977{RPCResult::Type::NUM, "subtype", "The number for the subtype"},978{RPCResult::Type::STR_HEX, "key", "The hex for the key"},979{RPCResult::Type::STR_HEX, "value", "The hex for the value"},980}},981}},982}},983}984};985return decodepsbt_inputs;986}988const RPCResult& DecodePSBTOutputs()989{990static const RPCResult decodepsbt_outputs{991RPCResult::Type::ARR, "outputs", "",992{993{RPCResult::Type::OBJ, "", "",994{995{RPCResult::Type::OBJ, "redeem_script", /*optional=*/true, "",996{997{RPCResult::Type::STR, "asm", "Disassembly of the redeem script"},998{RPCResult::Type::STR_HEX, "hex", "The raw redeem script bytes, hex-encoded"},999{RPCResult::Type::STR, "type", "The type, eg 'pubkeyhash'"},1000}},