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.
1751+ "\nCreate the same PSBT as the above one instead using named arguments:\n"1752+ HelpExampleCli("-named walletcreatefundedpsbt", "outputs=\"[{\\\"" + EXAMPLE_ADDRESS[0] + "\\\":0.5}]\" add_inputs=true fee_rate=2")1753},1754[](const RPCMethod& self, const JSONRPCRequest& request) -> UniValue1755{1756std::shared_ptr<CWallet> const pwallet = GetWalletForJSONRPCRequest(request);1757if (!pwallet) return UniValue::VNULL;1759CWallet& wallet{*pwallet};1760// Make sure the results are valid at least up to the most recent block1761// the user could have gotten from another RPC command prior to now1762wallet.BlockUntilSyncedToCurrentChain();1764UniValue options{request.params[3].isNull() ? UniValue::VOBJ : request.params[3]};1766CCoinControl coin_control;1767coin_control.m_version = self.Arg<uint32_t>("version");1769const UniValue &replaceable_arg = options["replaceable"];1770const bool rbf{replaceable_arg.isNull() ? wallet.m_signal_rbf : replaceable_arg.get_bool()};1771CMutableTransaction rawTx = ConstructTransaction(request.params[0], request.params[1], request.params[2], rbf, coin_control.m_version);1772UniValue outputs(UniValue::VOBJ);1773outputs = NormalizeOutputs(request.params[1]);1774std::vector<CRecipient> recipients = CreateRecipients(1775ParseOutputs(outputs),1776InterpretSubtractFeeFromOutputInstructions(options["subtractFeeFromOutputs"], outputs.getKeys())1777);1778// Automatically select coins, unless at least one is manually selected. Can1779// be overridden by options.add_inputs.1780coin_control.m_allow_other_inputs = rawTx.vin.size() == 0;1781SetOptionsInputWeights(request.params[0], options);1782// Clear tx.vout since it is not meant to be used now that we are passing outputs directly.1783// This sets us up for a future PR to completely remove tx from the function signature in favor of passing inputs directly1784rawTx.vout.clear();1785auto txr = FundTransaction(wallet, rawTx, recipients, options, coin_control, /*override_min_fee=*/true);1787// Make a blank psbt1788uint32_t psbt_version = 2;1789if (!request.params[6].isNull()) {1790psbt_version = request.params[6].getInt<int>();1791}1792if (psbt_version != 2 && psbt_version != 0) {1793throw JSONRPCError(RPC_INVALID_PARAMETER, "The PSBT version can only be 2 or 0");1794}1796PartiallySignedTransaction psbtx(CMutableTransaction(*txr.tx), psbt_version);1798// Fill transaction with out data but don't sign1799bool bip32derivs = request.params[4].isNull() ? true : request.params[4].get_bool();1800bool complete = true;1801const auto err{wallet.FillPSBT(psbtx, {.sign = false, .bip32_derivs = bip32derivs}, complete)};1802if (err) {1803throw JSONRPCPSBTError(*err);1804}1806// Serialize the PSBT1807DataStream ssTx{};1808ssTx << psbtx;1810UniValue result(UniValue::VOBJ);1811result.pushKV("psbt", EncodeBase64(ssTx.str()));1812result.pushKV("fee", ValueFromAmount(txr.fee));1813result.pushKV("changepos", txr.change_pos ? (int)*txr.change_pos : -1);1814return result;1815},1816};1817}1818} // namespace wallet