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.
1001{"outputs", RPCArg::Type::ARR, RPCArg::Default{UniValue::VARR}, "The outputs specified as key-value pairs.\n"1002"Each key may only appear once, i.e. there can only be one 'data' output, and no address may be duplicated.\n"1003"At least one output of either type must be specified.\n"1004"Cannot be provided if 'original_change_index' is specified.",1005OutputsDoc(),1006RPCArgOptions{.skip_type_check = true}},1007{"original_change_index", RPCArg::Type::NUM, RPCArg::DefaultHint{"not set, detect change automatically"}, "The 0-based index of the change output on the original transaction. "1008"The indicated output will be recycled into the new change output on the bumped transaction. "1009"The remainder after paying the recipients and fees will be sent to the output script of the "1010"original change output. The change output’s amount can increase if bumping the transaction "1011"adds new inputs, otherwise it will decrease. Cannot be used in combination with the 'outputs' option."},1012},1013want_psbt ? std::vector<RPCArg>{{"psbt_version", RPCArg::Type::NUM, RPCArg::Default(2), "The PSBT version number to use."}} : std::vector<RPCArg>()1014),1015RPCArgOptions{.oneline_description="options"}},1016},1017RPCResult{1018RPCResult::Type::OBJ, "", "", Cat(1019want_psbt ?1020std::vector<RPCResult>{{RPCResult::Type::STR, "psbt", "The base64-encoded unsigned PSBT of the new transaction."}} :1021std::vector<RPCResult>{{RPCResult::Type::STR_HEX, "txid", "The id of the new transaction."}},1022{1023{RPCResult::Type::STR_AMOUNT, "origfee", "The fee of the replaced transaction."},1024{RPCResult::Type::STR_AMOUNT, "fee", "The fee of the new transaction."},1025{RPCResult::Type::ARR, "errors", "Errors encountered during processing (may be empty).",1026{1027{RPCResult::Type::STR, "", ""},1028}},1029})1030},1031RPCExamples{1032"\nBump the fee, get the new transaction\'s " + std::string(want_psbt ? "psbt" : "txid") + "\n" +1033HelpExampleCli(method_name, "<txid>")1034},1035[want_psbt](const RPCMethod& self, const JSONRPCRequest& request) -> UniValue1036{1037std::shared_ptr<CWallet> const pwallet = GetWalletForJSONRPCRequest(request);1038if (!pwallet) return UniValue::VNULL;1040if (pwallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS) && !pwallet->IsWalletFlagSet(WALLET_FLAG_EXTERNAL_SIGNER) && !want_psbt) {1041throw JSONRPCError(RPC_WALLET_ERROR, "bumpfee is not available with wallets that have private keys disabled. Use psbtbumpfee instead.");1042}1044Txid hash{Txid::FromUint256(ParseHashV(request.params[0], "txid"))};1046CCoinControl coin_control;1047// optional parameters1048coin_control.m_signal_bip125_rbf = true;1049std::vector<CTxOut> outputs;1051std::optional<uint32_t> original_change_index;1053uint32_t psbt_version = 2;1055if (!request.params[1].isNull()) {1056UniValue options = request.params[1];1057RPCTypeCheckObj(options,1058{1059{"confTarget", UniValueType(UniValue::VNUM)},1060{"conf_target", UniValueType(UniValue::VNUM)},1061{"fee_rate", UniValueType()}, // will be checked by AmountFromValue() in SetFeeEstimateMode()1062{"replaceable", UniValueType(UniValue::VBOOL)},1063{"estimate_mode", UniValueType(UniValue::VSTR)},1064{"outputs", UniValueType()}, // will be checked by AddOutputs()1065{"original_change_index", UniValueType(UniValue::VNUM)},1066{"psbt_version", UniValueType(UniValue::VNUM)},1067},1068true, true);1070if (options.exists("confTarget") && options.exists("conf_target")) {1071throw JSONRPCError(RPC_INVALID_PARAMETER, "confTarget and conf_target options should not both be set. Use conf_target (confTarget is deprecated).");1072}1074auto conf_target = options.exists("confTarget") ? options["confTarget"] : options["conf_target"];1076if (options.exists("replaceable")) {1077coin_control.m_signal_bip125_rbf = options["replaceable"].get_bool();1078}1079SetFeeEstimateMode(*pwallet, coin_control, conf_target, options["estimate_mode"], options["fee_rate"], /*override_min_fee=*/false);1081// Prepare new outputs by creating a temporary tx and calling AddOutputs().1082if (!options["outputs"].isNull()) {1083if (options["outputs"].isArray() && options["outputs"].empty()) {1084throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, output argument cannot be an empty array");1085}1086CMutableTransaction tempTx;1087AddOutputs(tempTx, options["outputs"]);1088outputs = tempTx.vout;1089}1091if (options.exists("original_change_index")) {1092original_change_index = options["original_change_index"].getInt<uint32_t>();1093}1095if (options.exists("psbt_version")) {1096psbt_version = options["psbt_version"].getInt<uint32_t>();1097}1098if (psbt_version != 2 && psbt_version != 0) {1099throw JSONRPCError(RPC_INVALID_PARAMETER, "The PSBT version can only be 2 or 0");1100}1101}1103// Make sure the results are valid at least up to the most recent block1104// the user could have gotten from another RPC command prior to now1105pwallet->BlockUntilSyncedToCurrentChain();1107LOCK(pwallet->cs_wallet);1109EnsureWalletIsUnlocked(*pwallet);1112std::vector<bilingual_str> errors;1113CAmount old_fee;1114CAmount new_fee;1115CMutableTransaction mtx;1116// Targeting feerate bump.1117[&](){1118switch (feebumper::CreateRateBumpTransaction(*pwallet, hash, coin_control, errors, old_fee, new_fee, mtx, /*require_mine=*/ !want_psbt, outputs, original_change_index)) {1119case feebumper::Result::OK:1120return;1121case feebumper::Result::INVALID_ADDRESS_OR_KEY:1122throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, errors[0].original);1123case feebumper::Result::INVALID_REQUEST:1124throw JSONRPCError(RPC_INVALID_REQUEST, errors[0].original);1125case feebumper::Result::INVALID_PARAMETER:1126throw JSONRPCError(RPC_INVALID_PARAMETER, errors[0].original);1127case feebumper::Result::WALLET_ERROR:1128throw JSONRPCError(RPC_WALLET_ERROR, errors[0].original);1129case feebumper::Result::MISC_ERROR:1130throw JSONRPCError(RPC_MISC_ERROR, errors[0].original);1131} // no default case, so the compiler can warn about missing cases1132NONFATAL_UNREACHABLE();1133}();1135UniValue result(UniValue::VOBJ);1137// For bumpfee, return the new transaction id.1138// For psbtbumpfee, return the base64-encoded unsigned PSBT of the new transaction.1139if (!want_psbt) {1140if (!feebumper::SignTransaction(*pwallet, mtx)) {1141if (pwallet->IsWalletFlagSet(WALLET_FLAG_EXTERNAL_SIGNER)) {1142throw JSONRPCError(RPC_WALLET_ERROR, "Transaction incomplete. Try psbtbumpfee instead.");1143}1144throw JSONRPCError(RPC_WALLET_ERROR, "Can't sign transaction.");1145}1147Txid txid;1148if (feebumper::CommitTransaction(*pwallet, hash, std::move(mtx), errors, txid) != feebumper::Result::OK) {1149throw JSONRPCError(RPC_WALLET_ERROR, errors[0].original);1150}1152result.pushKV("txid", txid.GetHex());1153} else {1154PartiallySignedTransaction psbtx(mtx, psbt_version);1155bool complete = false;1156const auto err{pwallet->FillPSBT(psbtx, {.sign = false, .bip32_derivs = true}, complete)};1157CHECK_NONFATAL(!err);1158CHECK_NONFATAL(!complete);1159DataStream ssTx{};1160ssTx << psbtx;1161result.pushKV("psbt", EncodeBase64(ssTx.str()));1162}1164result.pushKV("origfee", ValueFromAmount(old_fee));1165result.pushKV("fee", ValueFromAmount(new_fee));1166UniValue result_errors(UniValue::VARR);1167for (const bilingual_str& error : errors) {1168result_errors.push_back(error.original);1169}1170result.pushKV("errors", std::move(result_errors));1172return result;1173},1174};1175}1177RPCMethod bumpfee() { return bumpfee_helper("bumpfee"); }1178RPCMethod psbtbumpfee() { return bumpfee_helper("psbtbumpfee"); }1180RPCMethod send()1181{1182return RPCMethod{1183"send",1184"Send a transaction.\n",1185{1186{"outputs", RPCArg::Type::ARR, RPCArg::Optional::NO, "The outputs specified as key-value pairs.\n"1187"Each key may only appear once, i.e. there can only be one 'data' output, and no address may be duplicated.\n"1188"At least one output of either type must be specified.\n"1189"For convenience, a dictionary, which holds the key-value pairs directly, is also accepted.",1190OutputsDoc(),1191RPCArgOptions{.skip_type_check = true}},1192{"conf_target", RPCArg::Type::NUM, RPCArg::DefaultHint{"wallet -txconfirmtarget"}, "Confirmation target in blocks"},1193{"estimate_mode", RPCArg::Type::STR, RPCArg::Default{"unset"}, "The fee estimate mode, must be one of (case insensitive):\n"1194+ FeeModesDetail(std::string("economical mode is used if the transaction is replaceable;\notherwise, conservative mode is used"))},1195{"fee_rate", RPCArg::Type::AMOUNT, RPCArg::DefaultHint{"not set, fall back to wallet fee estimation"}, "Specify a fee rate in " + CURRENCY_ATOM + "/vB."},1196{"options", RPCArg::Type::OBJ_NAMED_PARAMS, RPCArg::Optional::OMITTED, "",1197Cat<std::vector<RPCArg>>(1198{1199{"add_inputs", RPCArg::Type::BOOL, RPCArg::DefaultHint{"false when \"inputs\" are specified, true otherwise"},"Automatically include coins from the wallet to cover the target amount.\n"},1200{"include_unsafe", RPCArg::Type::BOOL, RPCArg::Default{false}, "Include inputs that are not safe to spend (unconfirmed transactions from outside keys and unconfirmed replacement transactions).\n"1201"Warning: the resulting transaction may become invalid if one of the unsafe inputs disappears.\n"1202"If that happens, you will need to fund the transaction with different inputs and republish it."},1203{"minconf", RPCArg::Type::NUM, RPCArg::Default{0}, "If add_inputs is specified, require inputs with at least this many confirmations."},1204{"maxconf", RPCArg::Type::NUM, RPCArg::Optional::OMITTED, "If add_inputs is specified, require inputs with at most this many confirmations."},1205{"add_to_wallet", RPCArg::Type::BOOL, RPCArg::Default{true}, "When false, returns a serialized transaction which will not be added to the wallet or broadcast"},1206{"change_address", RPCArg::Type::STR, RPCArg::DefaultHint{"automatic"}, "The bitcoin address to receive the change"},1207{"change_position", RPCArg::Type::NUM, RPCArg::DefaultHint{"random"}, "The index of the change output"},1208{"change_type", RPCArg::Type::STR, RPCArg::DefaultHint{"set by -changetype"}, "The output type to use. Only valid if change_address is not specified. Options are " + FormatAllOutputTypes() + "."},1209{"fee_rate", RPCArg::Type::AMOUNT, RPCArg::DefaultHint{"not set, fall back to wallet fee estimation"}, "Specify a fee rate in " + CURRENCY_ATOM + "/vB.", RPCArgOptions{.also_positional = true}},1210{"include_watching", RPCArg::Type::BOOL, RPCArg::Default{false}, "(DEPRECATED) No longer used"},1211{"inputs", RPCArg::Type::ARR, RPCArg::Default{UniValue::VARR}, "Specify inputs instead of adding them automatically.",1212{1213{"", RPCArg::Type::OBJ, RPCArg::Optional::OMITTED, "", {1214{"txid", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The transaction id"},1215{"vout", RPCArg::Type::NUM, RPCArg::Optional::NO, "The output number"},1216{"sequence", RPCArg::Type::NUM, RPCArg::DefaultHint{"depends on the value of the 'replaceable' and 'locktime' arguments"}, "The sequence number"},1217{"weight", RPCArg::Type::NUM, RPCArg::DefaultHint{"Calculated from wallet and solving data"}, "The maximum weight for this input, "1218"including the weight of the outpoint and sequence number. "1219"Note that signature sizes are not guaranteed to be consistent, "1220"so the maximum DER signatures size of 73 bytes should be used when considering ECDSA signatures."1221"Remember to convert serialized sizes to weight units when necessary."},1222}},1223},1224},1225{"locktime", RPCArg::Type::NUM, RPCArg::DefaultHint{"locktime close to block height to prevent fee sniping"}, "Raw locktime. Non-0 value also locktime-activates inputs"},1226{"lock_unspents", RPCArg::Type::BOOL, RPCArg::Default{false}, "Lock selected unspent outputs"},1227{"psbt", RPCArg::Type::BOOL, RPCArg::DefaultHint{"automatic"}, "Always return a PSBT, implies add_to_wallet=false."},1228{"subtract_fee_from_outputs", RPCArg::Type::ARR, RPCArg::Default{UniValue::VARR}, "Outputs to subtract the fee from, specified as integer indices.\n"1229"The fee will be equally deducted from the amount of each specified output.\n"1230"Those recipients will receive less bitcoins than you enter in their corresponding amount field.\n"1231"If no outputs are specified here, the sender pays the fee.",1232{1233{"vout_index", RPCArg::Type::NUM, RPCArg::Optional::OMITTED, "The zero-based output index, before a change output is added."},1234},1235},1236{"max_tx_weight", RPCArg::Type::NUM, RPCArg::Default{MAX_STANDARD_TX_WEIGHT}, "The maximum acceptable transaction weight.\n"1237"Transaction building will fail if this can not be satisfied."},1238},1239FundTxDoc()),1240RPCArgOptions{.oneline_description="options"}},1241{"version", RPCArg::Type::NUM, RPCArg::Default{DEFAULT_WALLET_TX_VERSION}, "Transaction version"},1242},1243RPCResult{1244RPCResult::Type::OBJ, "", "",1245{1246{RPCResult::Type::BOOL, "complete", "If the transaction has a complete set of signatures"},1247{RPCResult::Type::STR_HEX, "txid", /*optional=*/true, "The transaction id for the send. Only 1 transaction is created regardless of the number of addresses."},1248{RPCResult::Type::STR_HEX, "hex", /*optional=*/true, "If add_to_wallet is false, the hex-encoded raw transaction with signature(s)"},1249{RPCResult::Type::STR, "psbt", /*optional=*/true, "If more signatures are needed, or if add_to_wallet is false, the base64-encoded (partially) signed transaction"}1250}