28#include <unordered_set>
41 std::vector<CRecipient> recipients;
42 for (
size_t i = 0; i < outputs.size(); ++i) {
43 const auto& [destination, amount] = outputs.at(i);
45 recipients.push_back(recipient);
52 if (options.
exists(
"conf_target") || options.
exists(
"estimate_mode")) {
60 if (options.
exists(
"fee_rate")) {
65 options.
pushKV(
"fee_rate", fee_rate);
67 if (!options[
"conf_target"].isNull() && (options[
"estimate_mode"].isNull() || (options[
"estimate_mode"].get_str() ==
"unset"))) {
83 }
else if (
sffo.isNum()) {
84 pos =
sffo.getInt<
int>();
110 LOCK(pwallet->cs_wallet);
121 pwallet->FillPSBT(
psbtx, {.sign =
false, .bip32_derivs =
true}, complete);
122 const auto err{pwallet->FillPSBT(
psbtx, {.sign =
true, .bip32_derivs =
false}, complete)};
144 result.
pushKV(
"txid", tx->GetHash().GetHex());
146 pwallet->CommitTransaction(tx);
148 result.
pushKV(
"hex", hex);
151 result.
pushKV(
"complete", complete);
158 if (options.
exists(
"feeRate")) {
161 if (options.
exists(
"changeAddress")) {
164 if (options.
exists(
"changePosition")) {
167 if (options.
exists(
"lockUnspents")) {
170 if (options.
exists(
"subtractFeeFromOutputs")) {
183 throw JSONRPCError(
RPC_WALLET_ERROR,
"Error: sendtoaddress and sendmany are not supported for wallets with external signers; use send instead");
198 wallet.CommitTransaction(tx, std::nullopt, comment, comment_to);
201 entry.
pushKV(
"txid", tx->GetHash().GetHex());
202 entry.
pushKV(
"fee_reason", StringForFeeReason(
res->fee_reason));
205 return tx->GetHash().GetHex();
226 throw JSONRPCError(
RPC_INVALID_PARAMETER,
"Cannot specify both conf_target and fee_rate. Please provide either a confirmation target in blocks for automatic fee estimation, or an explicit fee rate.");
235 if (!
cc.m_signal_bip125_rbf)
cc.m_signal_bip125_rbf =
true;
250 "Send an amount to a given address." +
256 "This is not part of the transaction, just kept in your wallet."},
258 "to which you're sending the transaction. This is not part of the \n"
259 "transaction, just kept in your wallet."},
261 "The recipient will receive less bitcoins than you enter in the amount field."},
265 + FeeModesDetail(std::string(
"economical mode is used if the transaction is replaceable;\notherwise, conservative mode is used"))},
266 {
"avoid_reuse",
RPCArg::Type::BOOL,
RPCArg::Default{
true},
"(only available if avoid_reuse wallet flag is set) Avoid spending from dirty addresses; addresses are considered\n"
267 "dirty if they have previously been used in a transaction. If true, this also activates avoidpartialspends, grouping outputs by their addresses."},
272 RPCResult{
"if verbose is not set or set to false",
279 {
RPCResult::Type::STR,
"fee_reason",
"The reason the wallet selected this fee rate (\"" + FeeReasons(
"\", \"") +
"\")."}
286 "\nSend 0.1 BTC with a confirmation target of 6 blocks in economical fee estimate mode using positional arguments\n"
288 "\nSend 0.1 BTC with a fee rate of 1.1 " +
CURRENCY_ATOM +
"/vB, subtract fee from amount, BIP125-replaceable, using positional arguments\n"
290 "\nSend 0.2 BTC with a confirmation target of 6 blocks in economical fee estimate mode using named arguments\n"
292 "\nSend 0.5 BTC with a fee rate of 25 " +
CURRENCY_ATOM +
"/vB using named arguments\n"
294 +
HelpExampleCli(
"-named sendtoaddress",
"address=\"" +
EXAMPLE_ADDRESS[0] +
"\" amount=0.5 fee_rate=25 subtractfeefromamount=false replaceable=true avoid_reuse=true comment=\"2 pizzas\" comment_to=\"jeremy\" verbose=true")
303 pwallet->BlockUntilSyncedToCurrentChain();
305 LOCK(pwallet->cs_wallet);
308 std::optional<std::string> comment;
309 std::optional<std::string> comment_to;
310 if (!request.params[2].isNull() && !request.params[2].get_str().empty())
311 comment = request.params[2].get_str();
312 if (!request.params[3].isNull() && !request.params[3].get_str().empty())
313 comment_to = request.params[3].get_str();
316 if (!request.params[5].isNull()) {
329 const std::string address = request.params[0].get_str();
333 if (!request.params[4].isNull() && request.params[4].get_bool()) {
338 const bool verbose{request.params[10].isNull() ?
false : request.params[10].get_bool()};
348 "Send multiple times. Amounts are double-precision floating point numbers." +
365 "The fee will be equally deducted from the amount of each selected address.\n"
366 "Those recipients will receive less bitcoins than you enter in their corresponding amount field.\n"
367 "If no addresses are specified here, the sender pays the fee.",
375 + FeeModesDetail(std::string(
"economical mode is used if the transaction is replaceable;\notherwise, conservative mode is used"))},
380 RPCResult{
"if verbose is not set or set to false",
382 "the number of addresses."
388 "the number of addresses."},
389 {
RPCResult::Type::STR,
"fee_reason",
"The reason the wallet selected this fee rate (\"" + FeeReasons(
"\", \"") +
"\")."}
394 "\nSend two amounts to two different addresses:\n"
396 "\nSend two amounts to two different addresses setting the confirmation and comment:\n"
398 "\nSend two amounts to two different addresses, subtract fee from amount:\n"
400 "\nAs a JSON-RPC call\n"
410 pwallet->BlockUntilSyncedToCurrentChain();
412 LOCK(pwallet->cs_wallet);
414 if (!request.params[0].isNull() && !request.params[0].get_str().empty()) {
419 std::optional<std::string> comment;
420 if (!request.params[3].isNull() && !request.params[3].get_str().empty())
421 comment = request.params[3].
get_str();
424 if (!request.params[5].isNull()) {
434 const bool verbose{request.params[9].isNull() ?
false : request.params[9].get_bool()};
444 std::vector<RPCArg>
args = {
447 + FeeModesDetail(std::string(
"economical mode is used if the transaction is replaceable;\notherwise, conservative mode is used")),
RPCArgOptions{.
also_positional =
true}},
450 "Allows this transaction to be replaced by a transaction with higher fees"
455 "Used for fee estimation during coin selection.",
488 wallet.BlockUntilSyncedToCurrentChain();
525 if (options.
exists(
"add_inputs")) {
529 if (options.
exists(
"changeAddress") || options.
exists(
"change_address")) {
530 const std::string
change_address_str = (options.
exists(
"change_address") ? options[
"change_address"] : options[
"changeAddress"]).get_str();
540 if (options.
exists(
"changePosition") || options.
exists(
"change_position")) {
541 int pos = (options.
exists(
"change_position") ? options[
"change_position"] : options[
"changePosition"]).
getInt<int>();
542 if (pos < 0 || (
unsigned int)pos > recipients.size()) {
548 if (options.
exists(
"change_type")) {
549 if (options.
exists(
"changeAddress") || options.
exists(
"change_address")) {
559 if (options.
exists(
"lockUnspents") || options.
exists(
"lock_unspents")) {
560 lockUnspents = (options.
exists(
"lock_unspents") ? options[
"lock_unspents"] : options[
"lockUnspents"]).get_bool();
563 if (options.
exists(
"include_unsafe")) {
567 if (options.
exists(
"feeRate")) {
568 if (options.
exists(
"fee_rate")) {
571 if (options.
exists(
"conf_target")) {
572 throw JSONRPCError(
RPC_INVALID_PARAMETER,
"Cannot specify both conf_target and feeRate. Please provide either a confirmation target in blocks for automatic fee estimation, or an explicit fee rate.");
574 if (options.
exists(
"estimate_mode")) {
581 if (options.
exists(
"replaceable")) {
585 if (options.
exists(
"minconf")) {
593 if (options.
exists(
"maxconf")) {
603 if (options.
exists(
"solving_data")) {
637 for (
auto& desc :
descs) {
645 if (options.
exists(
"input_weights")) {
653 int vout =
vout_v.getInt<
int>();
666 throw JSONRPCError(
RPC_INVALID_PARAMETER,
"Invalid parameter, weight cannot be less than 165 (41 bytes (size of outpoint + sequence + empty scriptSig) * 4 (witness scaling factor)) + 1 (empty witness)");
676 if (options.
exists(
"max_tx_weight")) {
686 if (recipients.empty())
698 if (options.
exists(
"input_weights")) {
701 if (inputs.
size() == 0) {
706 if (input.exists(
"weight")) {
716 "fundrawtransaction",
717 "If the transaction has no inputs, they will be automatically selected to meet its out value.\n"
718 "It will add at most one change output to the outputs.\n"
719 "No existing outputs will be modified unless \"subtractFeeFromOutputs\" is specified.\n"
720 "Note that inputs which were signed may need to be resigned after completion since in/outputs have been added.\n"
721 "The inputs added will not be signed, use signrawtransactionwithkey\n"
722 "or signrawtransactionwithwallet for that.\n"
723 "All existing inputs must either have their previous output transaction be in the wallet\n"
724 "or be in the UTXO set. Solving data must be provided for non-wallet inputs.\n"
725 "Note that all inputs selected must be of standard form and P2SH scripts must be\n"
726 "in the wallet using importdescriptors (to calculate fees).\n"
727 "You can see whether this is the case by checking the \"solvable\" field in the listunspent output.\n"
728 "Note that if specifying an exact fee rate, the resulting transaction may have a higher fee rate\n"
729 "if the transaction has unconfirmed inputs. This is because the wallet will attempt to make the\n"
730 "entire package have the given fee rate, not the resulting transaction.\n",
737 {
"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"
738 "Warning: the resulting transaction may become invalid if one of the unsafe inputs disappears.\n"
739 "If that happens, you will need to fund the transaction with different inputs and republish it."},
750 "The fee will be equally deducted from the amount of each specified output.\n"
751 "Those recipients will receive less bitcoins than you enter in their corresponding amount field.\n"
752 "If no outputs are specified here, the sender pays the fee.",
764 "including the weight of the outpoint and sequence number. "
765 "Note that serialized signature sizes are not guaranteed to be consistent, "
766 "so the maximum DER signatures size of 73 bytes should be used when considering ECDSA signatures."
767 "Remember to convert serialized sizes to weight units when necessary."},
773 "Transaction building will fail if this can not be satisfied."},
780 "If iswitness is not present, heuristic tests will be used in decoding.\n"
781 "If true, only witness deserialization will be tried.\n"
782 "If false, only non-witness deserialization will be tried.\n"
783 "This boolean should reflect whether the transaction has inputs\n"
784 "(e.g. fully valid, or on-chain transactions), if known by the caller."
796 "\nCreate a transaction with no inputs\n"
797 +
HelpExampleCli(
"createrawtransaction",
"\"[]\" \"{\\\"myaddress\\\":0.01}\"") +
798 "\nAdd sufficient unsigned inputs to meet the output value\n"
800 "\nSign the transaction\n"
801 +
HelpExampleCli(
"signrawtransactionwithwallet",
"\"fundedtransactionhex\"") +
802 "\nSend the transaction\n"
803 +
HelpExampleCli(
"sendrawtransaction",
"\"signedtransactionhex\"")
812 bool try_witness = request.params[2].isNull() ?
true : request.params[2].get_bool();
813 bool try_no_witness = request.params[2].isNull() ?
true : !request.params[2].get_bool();
817 UniValue options = request.params[1];
818 std::vector<std::pair<CTxDestination, CAmount>>
destinations;
824 std::vector<std::string> dummy(
destinations.size(),
"dummy");
840 result.
pushKV(
"changepos",
txr.change_pos ? (
int)*
txr.change_pos : -1);
850 "signrawtransactionwithwallet",
851 "Sign inputs for raw transaction (serialized, hex-encoded).\n"
852 "The second optional argument (may be null) is an array of previous transaction outputs that\n"
853 "this transaction depends on but may not yet be in the block chain." +
876 " \"ALL|ANYONECANPAY\"\n"
877 " \"NONE|ANYONECANPAY\"\n"
878 " \"SINGLE|ANYONECANPAY\""},
917 LOCK(pwallet->cs_wallet);
921 std::map<COutPoint, Coin> coins;
925 pwallet->chain().findCoins(coins);
955 "the value (float or string) is the amount in " +
CURRENCY_UNIT +
""},
972 "Bumps the fee of a transaction T, replacing it with a new transaction B.\n"
973 + std::string(
want_psbt ?
"Returns a PSBT instead of creating and signing a new transaction.\n" :
"") +
974 "A transaction with the given txid must be in the wallet.\n"
975 "The command will pay the additional fee by reducing change outputs or adding inputs when necessary.\n"
976 "It may add a new change output if one does not already exist.\n"
977 "All inputs in the original transaction will be included in the replacement transaction.\n"
978 "The command will fail if the wallet or mempool contains a transaction that spends one of T's outputs.\n"
979 "By default, the new fee will be calculated automatically using the estimatesmartfee RPC.\n"
980 "The user can specify a confirmation target for estimatesmartfee.\n"
981 "Alternatively, the user can specify a fee rate in " +
CURRENCY_ATOM +
"/vB for the new transaction.\n"
982 "At a minimum, the new fee rate must be high enough to pay an additional new relay fee (incrementalfee\n"
983 "returned by getnetworkinfo) to enter the node's mempool.\n"
984 "* WARNING: before version 0.21, fee_rate was in " +
CURRENCY_UNIT +
"/kvB. As of 0.21, fee_rate is in " +
CURRENCY_ATOM +
"/vB. *\n",
992 "\nSpecify a fee rate in " +
CURRENCY_ATOM +
"/vB instead of relying on the built-in fee estimator.\n"
993 "Must be at least " +
incremental_fee +
" higher than the current transaction fee rate.\n"
994 "WARNING: before version 0.21, fee_rate was in " +
CURRENCY_UNIT +
"/kvB. As of 0.21, fee_rate is in " +
CURRENCY_ATOM +
"/vB.\n"},
996 "Whether the new transaction should be\n"
997 "marked bip-125 replaceable. If true, the sequence numbers in the transaction will\n"
998 "be set to 0xfffffffd. If false, any input sequence numbers in the\n"
999 "transaction will be set to 0xfffffffe\n"
1000 "so the new transaction will not be explicitly bip-125 replaceable (though it may\n"
1001 "still be replaceable in practice, for example if it has unconfirmed ancestors which\n"
1002 "are replaceable).\n"},
1004 + FeeModesDetail(std::string(
"economical mode is used if the transaction is replaceable;\notherwise, conservative mode is used"))},
1006 "Each key may only appear once, i.e. there can only be one 'data' output, and no address may be duplicated.\n"
1007 "At least one output of either type must be specified.\n"
1008 "Cannot be provided if 'original_change_index' is specified.",
1011 {
"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. "
1012 "The indicated output will be recycled into the new change output on the bumped transaction. "
1013 "The remainder after paying the recipients and fees will be sent to the output script of the "
1014 "original change output. The change output’s amount can increase if bumping the transaction "
1015 "adds new inputs, otherwise it will decrease. Cannot be used in combination with the 'outputs' option."},
1024 std::vector<RPCResult>{{
RPCResult::Type::STR,
"psbt",
"The base64-encoded unsigned PSBT of the new transaction."}} :
1036 "\nBump the fee, get the new transaction\'s " + std::string(
want_psbt ?
"psbt" :
"txid") +
"\n" +
1045 throw JSONRPCError(
RPC_WALLET_ERROR,
"bumpfee is not available with wallets that have private keys disabled. Use psbtbumpfee instead.");
1053 std::vector<CTxOut> outputs;
1059 if (!request.params[1].isNull()) {
1060 UniValue options = request.params[1];
1074 if (options.
exists(
"confTarget") && options.
exists(
"conf_target")) {
1078 auto conf_target = options.
exists(
"confTarget") ? options[
"confTarget"] : options[
"conf_target"];
1080 if (options.
exists(
"replaceable")) {
1086 if (!options[
"outputs"].isNull()) {
1087 if (options[
"outputs"].isArray() && options[
"outputs"].empty()) {
1095 if (options.
exists(
"original_change_index")) {
1099 if (options.
exists(
"psbt_version")) {
1109 pwallet->BlockUntilSyncedToCurrentChain();
1111 LOCK(pwallet->cs_wallet);
1116 std::vector<bilingual_str>
errors;
1159 bool complete =
false;
1160 const auto err{pwallet->FillPSBT(
psbtx, {.sign =
false, .bip32_derivs =
true}, complete)};
1188 "Send a transaction.\n",
1191 "Each key may only appear once, i.e. there can only be one 'data' output, and no address may be duplicated.\n"
1192 "At least one output of either type must be specified.\n"
1193 "For convenience, a dictionary, which holds the key-value pairs directly, is also accepted.",
1198 + FeeModesDetail(std::string(
"economical mode is used if the transaction is replaceable;\notherwise, conservative mode is used"))},
1203 {
"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"},
1204 {
"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"
1205 "Warning: the resulting transaction may become invalid if one of the unsafe inputs disappears.\n"
1206 "If that happens, you will need to fund the transaction with different inputs and republish it."},
1209 {
"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"},
1222 "including the weight of the outpoint and sequence number. "
1223 "Note that signature sizes are not guaranteed to be consistent, "
1224 "so the maximum DER signatures size of 73 bytes should be used when considering ECDSA signatures."
1225 "Remember to convert serialized sizes to weight units when necessary."},
1233 "The fee will be equally deducted from the amount of each specified output.\n"
1234 "Those recipients will receive less bitcoins than you enter in their corresponding amount field.\n"
1235 "If no outputs are specified here, the sender pays the fee.",
1241 "Transaction building will fail if this can not be satisfied."},
1251 {
RPCResult::Type::STR_HEX,
"txid",
true,
"The transaction id for the send. Only 1 transaction is created regardless of the number of addresses."},
1252 {
RPCResult::Type::STR_HEX,
"hex",
true,
"If add_to_wallet is false, the hex-encoded raw transaction with signature(s)"},
1253 {
RPCResult::Type::STR,
"psbt",
true,
"If more signatures are needed, or if add_to_wallet is false, the base64-encoded (partially) signed transaction"}
1257 "\nSend 0.1 BTC with a confirmation target of 6 blocks in economical fee estimate mode\n"
1259 "Send 0.2 BTC with a fee rate of 1.1 " +
CURRENCY_ATOM +
"/vB using positional arguments\n"
1261 "Send 0.2 BTC with a fee rate of 1 " +
CURRENCY_ATOM +
"/vB using the options argument\n"
1263 "Send 0.3 BTC with a fee rate of 25 " +
CURRENCY_ATOM +
"/vB using named arguments\n"
1265 "Create a transaction that should confirm the next block, with a specific input, and return result without adding to wallet or broadcasting to the network\n"
1266 +
HelpExampleCli(
"send",
"'{\"" +
EXAMPLE_ADDRESS[0] +
"\": 0.1}' 1 economical null '{\"add_to_wallet\": false, \"inputs\": [{\"txid\":\"a08e6907dbbd3d809776dbfc5d82e371b764ed838b5655e72f463568df1aadf0\", \"vout\":1}]}'")
1278 bool rbf{options.exists(
"replaceable") ? options[
"replaceable"].get_bool() : pwallet->m_signal_rbf};
1291 if (options.exists(
"max_tx_weight")) {
1292 coin_control.m_max_tx_weight = options[
"max_tx_weight"].getInt<
int>();
1310 "Spend the value of all (or specific) confirmed UTXOs and unconfirmed change in the wallet to one or more recipients.\n"
1311 "Unconfirmed inbound UTXOs and locked UTXOs will not be spent. Sendall will respect the avoid_reuse wallet flag.\n"
1312 "If your wallet contains many small inputs, either because it received tiny payments or as a result of accumulating change, consider using `send_max` to exclude inputs that are worth less than the fees needed to spend them.\n",
1315 "Optionally some recipients can be specified with an amount to perform payments, but at least one address must appear without a specified amount.\n",
1327 + FeeModesDetail(std::string(
"economical mode is used if the transaction is replaceable;\notherwise, conservative mode is used"))},
1350 {
"send_max",
RPCArg::Type::BOOL,
RPCArg::Default{
false},
"When true, only use UTXOs that can pay for their own fees to maximize the output amount. When 'false' (default), no UTXO is left behind. send_max is incompatible with providing specific inputs."},
1364 {
RPCResult::Type::STR_HEX,
"txid",
true,
"The transaction id for the send. Only 1 transaction is created regardless of the number of addresses."},
1365 {
RPCResult::Type::STR_HEX,
"hex",
true,
"If add_to_wallet is false, the hex-encoded raw transaction with signature(s)"},
1366 {
RPCResult::Type::STR,
"psbt",
true,
"If more signatures are needed, or if add_to_wallet is false, the base64-encoded (partially) signed transaction"}
1370 "\nSpend all UTXOs from the wallet with a fee rate of 1Â " +
CURRENCY_ATOM +
"/vB using named arguments\n"
1372 "Spend all UTXOs with a fee rate of 1.1 " +
CURRENCY_ATOM +
"/vB using positional arguments\n"
1374 "Spend all UTXOs split into equal amounts to two addresses with a fee rate of 1.5 " +
CURRENCY_ATOM +
"/vB using the options argument\n"
1376 "Leave dust UTXOs in wallet, spend only UTXOs with positive effective value with a fee rate of 10 " +
CURRENCY_ATOM +
"/vB using the options argument\n"
1378 "Spend all UTXOs with a fee rate of 1.3 " +
CURRENCY_ATOM +
"/vB using named arguments and sending a 0.25 " +
CURRENCY_UNIT +
" to another recipient\n"
1387 pwallet->BlockUntilSyncedToCurrentChain();
1396 const UniValue& recipients{request.params[0]};
1397 for (
unsigned int i = 0; i < recipients.size(); ++i) {
1398 const UniValue& recipient{recipients[i]};
1399 if (recipient.isStr()) {
1401 rkvp.pushKV(recipient.get_str(), 0);
1419 if (options.exists(
"minconf")) {
1425 coin_control.m_min_depth = options[
"minconf"].getInt<
int>();
1428 if (options.exists(
"maxconf")) {
1429 coin_control.m_max_depth = options[
"maxconf"].getInt<
int>();
1436 if (options.exists(
"version")) {
1446 const bool rbf{options.exists(
"replaceable") ? options[
"replaceable"].get_bool() : pwallet->m_signal_rbf};
1453 auto msg{
strprintf(
"Fee rate (%s) is lower than the minimum fee rate setting (%s).",
1457 msg +=
strprintf(
"\nConsider modifying -mintxfee (%s) or -minrelaytxfee (%s).",
1469 LOCK(pwallet->cs_wallet);
1472 bool send_max{options.exists(
"send_max") ? options[
"send_max"].get_bool() :
false};
1473 if (options.exists(
"inputs") && options.exists(
"send_max")) {
1475 }
else if (options.exists(
"inputs") && (options.exists(
"minconf") || options.exists(
"maxconf"))) {
1477 }
else if (options.exists(
"inputs")) {
1478 std::unordered_set<COutPoint, SaltedOutpointHasher>
seen_inputs;
1484 if (pwallet->IsSpent(input.prevout)) {
1487 const CWalletTx* tx{pwallet->GetWalletTx(input.prevout.hash)};
1488 if (!tx || input.prevout.n >= tx->GetTx()->vout.size() || !pwallet->IsMine(tx->GetTx()->vout[input.prevout.n])) {
1491 if (pwallet->GetTxDepthInMainChain(*tx) == 0) {
1504 if (
send_max && fee_rate.GetFee(output.input_bytes) > output.txout.nValue) {
1512 rawTx.vin.push_back(input);
1541 if (effective_value <= 0) {
1564 if (remainder < 0) {
1580 if (
IsDust(out, pwallet->chain().relayDustFee())) {
1585 if (
IsDust(out, pwallet->chain().relayDustFee())) {
1592 const bool lock_unspents{options.exists(
"lock_unspents") ? options[
"lock_unspents"].get_bool() :
false};
1595 pwallet->LockCoin(
txin.prevout,
false);
1607 "walletprocesspsbt",
1608 "Update a PSBT with input information from our wallet and then sign inputs\n"
1609 "that we can sign for." +
1614 {
"sighashtype",
RPCArg::Type::STR,
RPCArg::DefaultHint{
"DEFAULT for Taproot, ALL otherwise"},
"The signature hash type to sign with if not specified by the PSBT. Must be one of\n"
1619 " \"ALL|ANYONECANPAY\"\n"
1620 " \"NONE|ANYONECANPAY\"\n"
1621 " \"SINGLE|ANYONECANPAY\""},
1644 wallet.BlockUntilSyncedToCurrentChain();
1657 bool sign = request.params[1].isNull() ?
true : request.params[1].get_bool();
1658 bool bip32derivs = request.params[3].isNull() ?
true : request.params[3].get_bool();
1659 bool finalize = request.params[4].isNull() ?
true : request.params[4].get_bool();
1660 bool complete =
true;
1673 result.
pushKV(
"complete", complete);
1691 "walletcreatefundedpsbt",
1692 "Creates and funds a transaction in the Partially Signed Transaction format.\n"
1693 "Implements the Creator and Updater roles.\n"
1694 "All existing inputs must either have their previous output transaction be in the wallet\n"
1695 "or be in the UTXO set. Solving data must be provided for non-wallet inputs.\n",
1705 "including the weight of the outpoint and sequence number. "
1706 "Note that signature sizes are not guaranteed to be consistent, "
1707 "so the maximum DER signatures size of 73 bytes should be used when considering ECDSA signatures."
1708 "Remember to convert serialized sizes to weight units when necessary."},
1714 "Each key may only appear once, i.e. there can only be one 'data' output, and no address may be duplicated.\n"
1715 "At least one output of either type must be specified.\n"
1716 "For compatibility reasons, a dictionary, which holds the key-value pairs directly, is also\n"
1717 "accepted as second parameter.",
1724 {
"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"},
1725 {
"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"
1726 "Warning: the resulting transaction may become invalid if one of the unsafe inputs disappears.\n"
1727 "If that happens, you will need to fund the transaction with different inputs and republish it."},
1738 "The fee will be equally deducted from the amount of each specified output.\n"
1739 "Those recipients will receive less bitcoins than you enter in their corresponding amount field.\n"
1740 "If no outputs are specified here, the sender pays the fee.",
1746 "Transaction building will fail if this can not be satisfied."},
1763 "\nCreate a PSBT with automatically picked inputs that sends 0.5 BTC to an address and has a fee rate of 2 sat/vB:\n"
1764 +
HelpExampleCli(
"walletcreatefundedpsbt",
"\"[]\" \"[{\\\"" +
EXAMPLE_ADDRESS[0] +
"\\\":0.5}]\" 0 \"{\\\"add_inputs\\\":true,\\\"fee_rate\\\":2}\"")
1765 +
"\nCreate the same PSBT as the above one instead using named arguments:\n"
1776 wallet.BlockUntilSyncedToCurrentChain();
1803 if (!request.params[6].isNull()) {
1813 bool bip32derivs = request.params[4].isNull() ?
true : request.params[4].get_bool();
1814 bool complete =
true;
1827 result.
pushKV(
"changepos",
txr.change_pos ? (
int)*
txr.change_pos : -1);
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet)
Parse a scriptPubKey for the destination.
bool IsValidDestination(const CTxDestination &dest)
Check whether a CTxDestination corresponds to one with an address.
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
std::variant< CNoDestination, PubKeyDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, PayToAnchor, WitnessUnknown > CTxDestination
A txout script categorized into standard templates.
int64_t CAmount
Amount in satoshis (Can be negative)
static CAmount AmountFromValue(const UniValue &value)
#define CHECK_NONFATAL(condition)
Identity function.
#define NONFATAL_UNREACHABLE()
NONFATAL_UNREACHABLE() is a macro that is used to mark unreachable code.
Fee rate in satoshis per virtualbyte: CAmount / vB the feerate is represented internally as FeeFrac.
std::string ToString(FeeRateFormat fee_rate_format=FeeRateFormat::BTC_KVB) const
An outpoint - a combination of a transaction hash and an index n into its vout.
An encapsulated public key.
CKeyID GetID() const
Get the KeyID of this public key (hash of its serialization)
Serialized script, used inside transaction inputs and outputs.
A reference to a CScript: the Hash160 of its serialization.
The basic transaction that is broadcasted on the network and contained in blocks.
An input of a transaction.
static constexpr uint32_t MAX_SEQUENCE_NONFINAL
This is the maximum sequence number that enables both nLockTime and OP_CHECKLOCKTIMEVERIFY (BIP 65).
An output of a transaction.
Double ended buffer combining vector and stream-like interfaces.
A version of CTransaction with the PSBT format.
const std::string & get_str() const
const UniValue & find_value(std::string_view key) const
const UniValue & get_obj() const
const std::vector< UniValue > & getValues() const
const std::vector< std::string > & getKeys() const
const UniValue & get_array() const
bool exists(const std::string &key) const
void pushKV(std::string key, UniValue val)
std::string GetHex() const
static transaction_identifier FromUint256(const uint256 &id)
std::optional< bool > m_signal_bip125_rbf
Override the wallet's m_signal_rbf if set.
bool m_allow_other_inputs
If true, the selection process can add extra unselected inputs from the wallet while requires all sel...
uint32_t m_version
Version.
A CWallet maintains a set of transactions and balances, and provides the ability to create new transa...
A transaction with a bunch of additional info that only the owner cares about.
static UniValue Parse(std::string_view raw, ParamFormat format=ParamFormat::JSON)
Parse string to UniValue or throw runtime_error if string contains invalid JSON.
static int64_t GetTransactionInputWeight(const CTxIn &txin)
std::string EncodeHexTx(const CTransaction &tx)
bool DecodeHexTx(CMutableTransaction &tx, const std::string &hex_tx, bool try_no_witness, bool try_witness)
UniValue ValueFromAmount(const CAmount amount)
const std::string CURRENCY_ATOM
@ SAT_VB
Use sat/vB fee rate unit.
const std::string CURRENCY_UNIT
std::string HexStr(const std::span< const uint8_t > s)
Convert a span of bytes to a lower-case hexadecimal string.
@ SIGHASH_DEFAULT
Taproot only; implied when sighash byte is missing, and equivalent to SIGHASH_ALL.
CTxDestination DecodeDestination(const std::string &str, std::string &error_msg, std::vector< int > *error_locations)
std::string EncodeDestination(const CTxDestination &dest)
is a home for simple string functions returning descriptive messages that are used in RPC and GUI int...
static int sign(const secp256k1_context *ctx, struct signer_secrets *signer_secrets, struct signer *signer, const secp256k1_musig_keyagg_cache *cache, const unsigned char *msg32, unsigned char *sig64)
std::string FeeModesDetail(std::string default_info)
bilingual_str TransactionErrorString(const TransactionError err)
std::string FeeReasons(const std::string &delimiter)
bool FeeModeFromString(std::string_view mode_string, FeeEstimateMode &fee_estimate_mode)
std::string InvalidEstimateModeErrorMessage()
std::string StringForFeeReason(FeeReason reason)
bilingual_str ErrorString(const Result< T > &result)
Result CreateRateBumpTransaction(CWallet &wallet, const Txid &txid, const CCoinControl &coin_control, std::vector< bilingual_str > &errors, CAmount &old_fee, CAmount &new_fee, CMutableTransaction &mtx, bool require_mine, const std::vector< CTxOut > &outputs, std::optional< uint32_t > original_change_index)
Create bumpfee transaction based on feerate estimates.
bool SignTransaction(CWallet &wallet, CMutableTransaction &mtx)
Sign the new transaction,.
Result CommitTransaction(CWallet &wallet, const Txid &txid, CMutableTransaction &&mtx, std::vector< bilingual_str > &errors, Txid &bumped_txid)
Commit the bumpfee transaction.
CreatedTransactionResult FundTransaction(CWallet &wallet, const CMutableTransaction &tx, const std::vector< CRecipient > &recipients, const UniValue &options, CCoinControl &coinControl, bool override_min_fee)
std::shared_ptr< CWallet > GetWalletForJSONRPCRequest(const JSONRPCRequest &request)
Figures out what wallet, if any, to use for a JSONRPCRequest.
util::Result< CreatedTransactionResult > CreateTransaction(CWallet &wallet, const std::vector< CRecipient > &vecSend, std::optional< unsigned int > change_pos, const CCoinControl &coin_control, bool sign)
Create a new transaction paying the recipients with a set of coins selected by SelectCoins(); Also cr...
RPCMethod fundrawtransaction()
MinimumFeeRateResult GetMinimumFeeRate(const CWallet &wallet, const CCoinControl &coin_control)
Estimate the minimum fee rate considering user set parameters and the required fee.
static RPCMethod bumpfee_helper(std::string method_name)
void EnsureWalletIsUnlocked(const CWallet &wallet)
constexpr int DEFAULT_WALLET_TX_VERSION
RPCMethod walletcreatefundedpsbt()
const std::string HELP_REQUIRING_PASSPHRASE
static void SetFeeEstimateMode(const CWallet &wallet, CCoinControl &cc, const UniValue &conf_target, const UniValue &estimate_mode, const UniValue &fee_rate, bool override_min_fee)
Update coin control with fee estimation based on the given parameters.
bool IsDust(const CRecipient &recipient, const CFeeRate &dustRelayFee)
static void InterpretFeeEstimationInstructions(const UniValue &conf_target, const UniValue &estimate_mode, const UniValue &fee_rate, UniValue &options)
static void SetOptionsInputWeights(const UniValue &inputs, UniValue &options)
static void PreventOutdatedOptions(const UniValue &options)
std::vector< CRecipient > CreateRecipients(const std::vector< std::pair< CTxDestination, CAmount > > &outputs, const std::set< int > &subtract_fee_outputs)
RPCMethod signrawtransactionwithwallet()
RPCMethod walletprocesspsbt()
static std::vector< RPCArg > FundTxDoc(bool solving_data=true)
void DiscourageFeeSniping(CMutableTransaction &tx, FastRandomContext &rng_fast, interfaces::Chain &chain, const uint256 &block_hash, int block_height)
Set a height-based locktime for new transactions (uses the height of the current chain tip unless we ...
static std::vector< RPCArg > OutputsDoc()
bool GetAvoidReuseFlag(const CWallet &wallet, const UniValue ¶m)
static UniValue FinishTransaction(const std::shared_ptr< CWallet > pwallet, const UniValue &options, CMutableTransaction &rawTx)
RPCMethod sendtoaddress()
TxSize CalculateMaximumSignedTxSize(const CTransaction &tx, const CWallet *wallet, const std::vector< CTxOut > &txouts, const CCoinControl *coin_control)
Calculate the size of the transaction using CoinControl to determine whether to expect signature grin...
@ WALLET_FLAG_EXTERNAL_SIGNER
Indicates that the wallet needs an external signer.
@ WALLET_FLAG_DISABLE_PRIVATE_KEYS
UniValue SendMoney(CWallet &wallet, const CCoinControl &coin_control, std::vector< CRecipient > &recipients, std::optional< std::string > comment, std::optional< std::string > comment_to, bool verbose)
std::set< int > InterpretSubtractFeeFromOutputInstructions(const UniValue &sffo_instructions, const std::vector< std::string > &destinations)
CoinsResult AvailableCoins(const CWallet &wallet, const CCoinControl *coinControl, std::optional< CFeeRate > feerate, const CoinFilterParams ¶ms)
Populate the CoinsResult struct with vectors of available COutputs, organized by OutputType.
is a home for public enum and struct type definitions that are used internally by node code,...
std::optional< OutputType > ParseOutputType(std::string_view type)
std::string FormatAllOutputTypes()
constexpr unsigned int DEFAULT_INCREMENTAL_RELAY_FEE
Default for -incrementalrelayfee, which sets the minimum feerate increase for mempool limiting or rep...
constexpr int32_t MAX_STANDARD_TX_WEIGHT
The maximum weight for transactions we're willing to relay/mine.
constexpr TransactionSerParams TX_WITH_WITNESS
static CTransactionRef MakeTransactionRef(Tx &&txIn)
std::shared_ptr< const CTransaction > CTransactionRef
util::Result< PartiallySignedTransaction > DecodeBase64PSBT(const std::string &base64_tx)
Decode a base64ed PSBT into a PartiallySignedTransaction.
bool FinalizeAndExtractPSBT(PartiallySignedTransaction &psbtx, CMutableTransaction &result)
Finalizes a PSBT if possible, and extracts it to a CMutableTransaction if it could be finalized.
void SignTransactionResultToJSON(CMutableTransaction &mtx, bool complete, const std::map< COutPoint, Coin > &coins, const std::map< int, bilingual_str > &input_errors, UniValue &result)
void AddOutputs(CMutableTransaction &rawTx, const UniValue &outputs_in)
Normalize, parse, and add outputs to the transaction.
CMutableTransaction ConstructTransaction(const UniValue &inputs_in, const UniValue &outputs_in, const UniValue &locktime, std::optional< bool > rbf, const uint32_t version)
Create a transaction from univalue parameters.
std::vector< std::pair< CTxDestination, CAmount > > ParseOutputs(const UniValue &outputs)
Parse normalized outputs into destination, amount tuples.
UniValue NormalizeOutputs(const UniValue &outputs_in)
Normalize univalue-represented outputs.
void ParsePrevouts(const UniValue &prevTxsUnival, FlatSigningProvider *keystore, std::map< COutPoint, Coin > &coins)
Parse a prevtxs UniValue array and get the map of coins from it.
UniValue JSONRPCError(int code, const std::string &message)
@ RPC_MISC_ERROR
General application defined errors.
@ RPC_WALLET_INSUFFICIENT_FUNDS
Not enough funds in wallet or account.
@ RPC_INVALID_PARAMETER
Invalid, missing or duplicate parameter.
@ RPC_WALLET_ERROR
Wallet errors.
@ RPC_DESERIALIZATION_ERROR
Error parsing or validating structure in raw format.
@ RPC_INVALID_REQUEST
Standard JSON-RPC 2.0 errors.
@ RPC_INVALID_ADDRESS_OR_KEY
Invalid address or key.
std::string HelpExampleCli(const std::string &methodname, const std::string &args)
UniValue JSONRPCPSBTError(PSBTError err)
std::string HelpExampleRpc(const std::string &methodname, const std::string &args)
CPubKey HexToPubKey(const std::string &hex_in)
std::optional< int > ParseSighashString(const UniValue &sighash)
Returns a sighash value corresponding to the passed in argument.
const std::string EXAMPLE_ADDRESS[2]
Example bech32 addresses for the RPCExamples help documentation.
uint256 ParseHashO(const UniValue &o, std::string_view strKey)
unsigned int ParseConfirmTarget(const UniValue &value, unsigned int max_target)
Parse a confirm target option and raise an RPC error if it is invalid.
void RPCTypeCheckObj(const UniValue &o, const std::map< std::string, UniValueType > &typesExpected, bool fAllowNull, bool fStrict)
uint256 ParseHashV(const UniValue &v, std::string_view name)
Utilities: convert hex-encoded Values (throws error if not hex).
std::vector< Byte > ParseHex(std::string_view hex_str)
Like TryParseHex, but returns an empty vector on invalid input.
A mutable version of CTransaction.
std::vector< CTxOut > vout
@ OBJ_USER_KEYS
Special type where the user must set the keys e.g. to define multiple addresses; as opposed to e....
@ STR_HEX
Special type that is a STR with only hex chars.
@ AMOUNT
Special type representing a floating point amount (can be either NUM or STR)
@ OBJ_NAMED_PARAMS
Special type that behaves almost exactly like OBJ, defining an options object with a list of pre-defi...
std::string DefaultHint
Hint for default value.
@ OMITTED
Optional argument for which the default value is omitted from help text for one of two reasons:
UniValue Default
Default constant value.
std::string oneline_description
Should be empty unless it is supposed to override the auto-generated summary line.
bool also_positional
If set allows a named-parameter field in an OBJ_NAMED_PARAM options object to have the same name as a...
bool placeholder
If set, the argument is retained only for compatibility and should generally be omitted.
@ STR_HEX
Special string with only hex chars.
@ STR_AMOUNT
Special string to represent a floating point amount.
Wrapper for UniValue::VType, which includes typeAny: Used to denote don't care type.
A UTXO under consideration for use in funding a new transaction.
std::vector< COutput > All() const
Concatenate and return all COutputs as one vector.
constexpr int64_t TRUC_MAX_WEIGHT
constexpr decltype(CTransaction::version) TRUC_VERSION
constexpr int64_t TRUC_CHILD_MAX_WEIGHT
const char * uvTypeName(UniValue::VType t)
constexpr uint32_t MAX_BIP125_RBF_SEQUENCE
bool IsHex(std::string_view str)
std::string EncodeBase64(std::span< const unsigned char > input)
constexpr auto Ticks(Dur2 d)
Helper to count the seconds of a duration/time_point.
V Cat(V v1, V &&v2)
Concatenate two vectors, moving elements.