 |
Bitcoin Core
22.99.0
P2P Digital Currency
|
Go to the documentation of this file.
25 std::set<CTxDestination> destinations;
27 for (
const std::string& address: address_amounts.
getKeys()) {
33 if (destinations.count(dest)) {
36 destinations.insert(dest);
41 bool subtract_fee =
false;
42 for (
unsigned int idx = 0; idx < subtract_fee_outputs.
size(); idx++) {
43 const UniValue& addr = subtract_fee_outputs[idx];
44 if (addr.
get_str() == address) {
49 CRecipient recipient = {script_pub_key, amount, subtract_fee};
69 int nChangePosRet = -1;
77 wallet.CommitTransaction(tx, std::move(map_value), {} );
80 entry.
pushKV(
"txid", tx->GetHash().GetHex());
84 return tx->GetHash().GetHex();
104 if (!conf_target.
isNull()) {
105 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.");
107 if (!estimate_mode.
isNull() && estimate_mode.
get_str() !=
"unset") {
120 if (!conf_target.
isNull()) {
128 "\nSend an amount to a given address." +
134 "This is not part of the transaction, just kept in your wallet."},
136 "to which you're sending the transaction. This is not part of the \n"
137 "transaction, just kept in your wallet."},
139 "The recipient will receive less bitcoins than you enter in the amount field."},
144 {
"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"
145 "dirty if they have previously been used in a transaction. If true, this also activates avoidpartialspends, grouping outputs by their addresses."},
150 RPCResult{
"if verbose is not set or set to false",
164 "\nSend 0.1 BTC with a confirmation target of 6 blocks in economical fee estimate mode using positional arguments\n"
166 "\nSend 0.1 BTC with a fee rate of 1.1 " +
CURRENCY_ATOM +
"/vB, subtract fee from amount, BIP125-replaceable, using positional arguments\n"
168 "\nSend 0.2 BTC with a confirmation target of 6 blocks in economical fee estimate mode using named arguments\n"
170 "\nSend 0.5 BTC with a fee rate of 25 " +
CURRENCY_ATOM +
"/vB using named arguments\n"
172 +
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")
181 pwallet->BlockUntilSyncedToCurrentChain();
183 LOCK(pwallet->cs_wallet);
187 if (!request.params[2].isNull() && !request.params[2].get_str().empty())
188 mapValue[
"comment"] = request.params[2].get_str();
189 if (!request.params[3].isNull() && !request.params[3].get_str().empty())
190 mapValue[
"to"] = request.params[3].get_str();
192 bool fSubtractFeeFromAmount =
false;
193 if (!request.params[4].isNull()) {
194 fSubtractFeeFromAmount = request.params[4].get_bool();
198 if (!request.params[5].isNull()) {
206 SetFeeEstimateMode(*pwallet, coin_control, request.params[6], request.params[7], request.params[9],
false);
211 const std::string address = request.params[0].get_str();
212 address_amounts.
pushKV(address, request.params[1]);
214 if (fSubtractFeeFromAmount) {
215 subtractFeeFromAmount.
push_back(address);
218 std::vector<CRecipient> recipients;
220 const bool verbose{request.params[10].isNull() ? false : request.params[10].get_bool()};
222 return SendMoney(*pwallet, coin_control, recipients, mapValue, verbose);
230 "\nSend multiple times. Amounts are double-precision floating point numbers." +
242 "The fee will be equally deducted from the amount of each selected address.\n"
243 "Those recipients will receive less bitcoins than you enter in their corresponding amount field.\n"
244 "If no addresses are specified here, the sender pays the fee.",
257 RPCResult{
"if verbose is not set or set to false",
259 "the number of addresses."
265 "the number of addresses."},
271 "\nSend two amounts to two different addresses:\n"
273 "\nSend two amounts to two different addresses setting the confirmation and comment:\n"
275 "\nSend two amounts to two different addresses, subtract fee from amount:\n"
277 "\nAs a JSON-RPC call\n"
287 pwallet->BlockUntilSyncedToCurrentChain();
289 LOCK(pwallet->cs_wallet);
291 if (!request.params[0].isNull() && !request.params[0].get_str().empty()) {
297 if (!request.params[3].isNull() && !request.params[3].get_str().empty())
298 mapValue[
"comment"] = request.params[3].
get_str();
301 if (!request.params[4].isNull())
302 subtractFeeFromAmount = request.params[4].
get_array();
305 if (!request.params[5].isNull()) {
309 SetFeeEstimateMode(*pwallet, coin_control, request.params[6], request.params[7], request.params[8],
false);
311 std::vector<CRecipient> recipients;
313 const bool verbose{request.params[9].isNull() ? false : request.params[9].get_bool()};
315 return SendMoney(*pwallet, coin_control, recipients, std::move(mapValue), verbose);
323 "\nSet the transaction fee rate in " +
CURRENCY_UNIT +
"/kvB for this wallet. Overrides the global -paytxfee command line parameter.\n"
324 "Can be deactivated by passing 0 as the fee. In that case automatic fee selection will be used by default.\n",
340 LOCK(pwallet->cs_wallet);
343 CFeeRate tx_fee_rate(nAmount, 1000);
344 CFeeRate max_tx_fee_rate(pwallet->m_default_max_tx_fee, 1000);
347 }
else if (tx_fee_rate < pwallet->chain().relayMinFee()) {
349 }
else if (tx_fee_rate < pwallet->m_min_fee) {
351 }
else if (tx_fee_rate > max_tx_fee_rate) {
355 pwallet->m_pay_tx_fee = tx_fee_rate;
370 "Allows this transaction to be replaced by a transaction with higher fees"},
372 "Used for fee estimation during coin selection.",
394 wallet.BlockUntilSyncedToCurrentChain();
396 change_position = -1;
397 bool lockUnspents =
false;
399 std::set<int> setSubtractFeeFromOutputs;
437 if (options.
exists(
"add_inputs") ) {
441 if (options.
exists(
"changeAddress") || options.
exists(
"change_address")) {
442 const std::string change_address_str = (options.
exists(
"change_address") ? options[
"change_address"] : options[
"changeAddress"]).get_str();
452 if (options.
exists(
"changePosition") || options.
exists(
"change_position")) {
453 change_position = (options.
exists(
"change_position") ? options[
"change_position"] : options[
"changePosition"]).get_int();
456 if (options.
exists(
"change_type")) {
457 if (options.
exists(
"changeAddress") || options.
exists(
"change_address")) {
460 if (std::optional<OutputType> parsed =
ParseOutputType(options[
"change_type"].get_str())) {
467 const UniValue include_watching_option = options.
exists(
"include_watching") ? options[
"include_watching"] : options[
"includeWatching"];
470 if (options.
exists(
"lockUnspents") || options.
exists(
"lock_unspents")) {
471 lockUnspents = (options.
exists(
"lock_unspents") ? options[
"lock_unspents"] : options[
"lockUnspents"]).get_bool();
474 if (options.
exists(
"include_unsafe")) {
478 if (options.
exists(
"feeRate")) {
479 if (options.
exists(
"fee_rate")) {
482 if (options.
exists(
"conf_target")) {
483 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.");
485 if (options.
exists(
"estimate_mode")) {
492 if (options.
exists(
"subtractFeeFromOutputs") || options.
exists(
"subtract_fee_from_outputs") )
493 subtractFeeFromOutputs = (options.
exists(
"subtract_fee_from_outputs") ? options[
"subtract_fee_from_outputs"] : options[
"subtractFeeFromOutputs"]).get_array();
495 if (options.
exists(
"replaceable")) {
498 SetFeeEstimateMode(
wallet, coinControl, options[
"conf_target"], options[
"estimate_mode"], options[
"fee_rate"], override_min_fee);
505 if (options.
exists(
"solving_data")) {
507 if (solving_data.
exists(
"pubkeys")) {
508 for (
const UniValue& pk_univ : solving_data[
"pubkeys"].get_array().getValues()) {
509 const std::string& pk_str = pk_univ.
get_str();
510 if (!
IsHex(pk_str)) {
513 const std::vector<unsigned char> data(
ParseHex(pk_str));
514 const CPubKey pubkey(data.begin(), data.end());
525 if (solving_data.
exists(
"scripts")) {
526 for (
const UniValue& script_univ : solving_data[
"scripts"].get_array().getValues()) {
527 const std::string& script_str = script_univ.get_str();
528 if (!
IsHex(script_str)) {
531 std::vector<unsigned char> script_data(
ParseHex(script_str));
532 const CScript script(script_data.begin(), script_data.end());
537 if (solving_data.
exists(
"descriptors")) {
538 for (
const UniValue& desc_univ : solving_data[
"descriptors"].get_array().getValues()) {
539 const std::string& desc_str = desc_univ.get_str();
542 std::vector<CScript> scripts_temp;
543 std::unique_ptr<Descriptor> desc =
Parse(desc_str, desc_out,
error,
true);
547 desc->Expand(0, desc_out, scripts_temp, desc_out);
553 if (options.
exists(
"input_weights")) {
554 for (
const UniValue& input : options[
"input_weights"].get_array().getValues()) {
558 if (!vout_v.
isNum()) {
567 if (!weight_v.
isNum()) {
573 if (weight < min_input_weight) {
574 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)");
584 if (tx.
vout.size() == 0)
587 if (change_position != -1 && (change_position < 0 || (
unsigned int)change_position > tx.
vout.size()))
590 for (
unsigned int idx = 0; idx < subtractFeeFromOutputs.
size(); idx++) {
591 int pos = subtractFeeFromOutputs[idx].
get_int();
592 if (setSubtractFeeFromOutputs.count(pos))
596 if (pos >=
int(tx.
vout.size()))
598 setSubtractFeeFromOutputs.insert(pos);
603 std::map<COutPoint, Coin> coins;
607 wallet.chain().findCoins(coins);
608 for (
const auto& coin : coins) {
609 if (!coin.second.out.IsNull()) {
623 if (options.
exists(
"input_weights")) {
626 if (inputs.
size() == 0) {
631 if (input.exists(
"weight")) {
635 options.
pushKV(
"input_weights", weights);
641 "\nIf the transaction has no inputs, they will be automatically selected to meet its out value.\n"
642 "It will add at most one change output to the outputs.\n"
643 "No existing outputs will be modified unless \"subtractFeeFromOutputs\" is specified.\n"
644 "Note that inputs which were signed may need to be resigned after completion since in/outputs have been added.\n"
645 "The inputs added will not be signed, use signrawtransactionwithkey\n"
646 "or signrawtransactionwithwallet for that.\n"
647 "All existing inputs must either have their previous output transaction be in the wallet\n"
648 "or be in the UTXO set. Solving data must be provided for non-wallet inputs.\n"
649 "Note that all inputs selected must be of standard form and P2SH scripts must be\n"
650 "in the wallet using importaddress or addmultisigaddress (to calculate fees).\n"
651 "You can see whether this is the case by checking the \"solvable\" field in the listunspent output.\n"
652 "Only pay-to-pubkey, multisig, and P2SH versions thereof are currently supported for watch-only\n",
656 Cat<std::vector<RPCArg>>(
659 {
"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"
660 "Warning: the resulting transaction may become invalid if one of the unsafe inputs disappears.\n"
661 "If that happens, you will need to fund the transaction with different inputs and republish it."},
664 {
"change_type",
RPCArg::Type::STR,
RPCArg::DefaultHint{
"set by -changetype"},
"The output type to use. Only valid if changeAddress is not specified. Options are \"legacy\", \"p2sh-segwit\", and \"bech32\"."},
666 "Only solvable inputs can be used. Watch-only destinations are solvable if the public key and/or output script was imported,\n"
667 "e.g. with 'importpubkey' or 'importmulti' with the 'pubkeys' or 'desc' field."},
672 "The fee will be equally deducted from the amount of each specified output.\n"
673 "Those recipients will receive less bitcoins than you enter in their corresponding amount field.\n"
674 "If no outputs are specified here, the sender pays the fee.",
684 "including the weight of the outpoint and sequence number. "
685 "Note that serialized signature sizes are not guaranteed to be consistent, "
686 "so the maximum DER signatures size of 73 bytes should be used when considering ECDSA signatures."
687 "Remember to convert serialized sizes to weight units when necessary."},
694 "If iswitness is not present, heuristic tests will be used in decoding.\n"
695 "If true, only witness deserialization will be tried.\n"
696 "If false, only non-witness deserialization will be tried.\n"
697 "This boolean should reflect whether the transaction has inputs\n"
698 "(e.g. fully valid, or on-chain transactions), if known by the caller."
710 "\nCreate a transaction with no inputs\n"
711 +
HelpExampleCli(
"createrawtransaction",
"\"[]\" \"{\\\"myaddress\\\":0.01}\"") +
712 "\nAdd sufficient unsigned inputs to meet the output value\n"
714 "\nSign the transaction\n"
715 +
HelpExampleCli(
"signrawtransactionwithwallet",
"\"fundedtransactionhex\"") +
716 "\nSend the transaction\n"
717 +
HelpExampleCli(
"sendrawtransaction",
"\"signedtransactionhex\"")
724 RPCTypeCheck(request.params, {UniValue::VSTR, UniValueType(), UniValue::VBOOL});
728 bool try_witness = request.params[2].isNull() ? true : request.params[2].get_bool();
729 bool try_no_witness = request.params[2].isNull() ? true : !request.params[2].get_bool();
730 if (!
DecodeHexTx(tx, request.params[0].get_str(), try_no_witness, try_witness)) {
739 FundTransaction(*pwallet, tx, fee, change_position, request.params[1], coin_control,
true);
744 result.
pushKV(
"changepos", change_position);
753 return RPCHelpMan{
"signrawtransactionwithwallet",
754 "\nSign inputs for raw transaction (serialized, hex-encoded).\n"
755 "The second optional argument (may be null) is an array of previous transaction outputs that\n"
756 "this transaction depends on but may not yet be in the block chain." +
779 " \"ALL|ANYONECANPAY\"\n"
780 " \"NONE|ANYONECANPAY\"\n"
781 " \"SINGLE|ANYONECANPAY\""},
814 RPCTypeCheck(request.params, {UniValue::VSTR, UniValue::VARR, UniValue::VSTR},
true);
817 if (!
DecodeHexTx(mtx, request.params[0].get_str())) {
822 LOCK(pwallet->cs_wallet);
826 std::map<COutPoint, Coin> coins;
830 pwallet->chain().findCoins(coins);
838 std::map<int, bilingual_str> input_errors;
840 bool complete = pwallet->SignTransaction(mtx, coins, nHashType, input_errors);
850 const bool want_psbt = method_name ==
"psbtbumpfee";
854 "\nBumps the fee of an opt-in-RBF transaction T, replacing it with a new transaction B.\n"
855 + std::string(want_psbt ?
"Returns a PSBT instead of creating and signing a new transaction.\n" :
"") +
856 "An opt-in RBF transaction with the given txid must be in the wallet.\n"
857 "The command will pay the additional fee by reducing change outputs or adding inputs when necessary.\n"
858 "It may add a new change output if one does not already exist.\n"
859 "All inputs in the original transaction will be included in the replacement transaction.\n"
860 "The command will fail if the wallet or mempool contains a transaction that spends one of T's outputs.\n"
861 "By default, the new fee will be calculated automatically using the estimatesmartfee RPC.\n"
862 "The user can specify a confirmation target for estimatesmartfee.\n"
863 "Alternatively, the user can specify a fee rate in " +
CURRENCY_ATOM +
"/vB for the new transaction.\n"
864 "At a minimum, the new fee rate must be high enough to pay an additional new relay fee (incrementalfee\n"
865 "returned by getnetworkinfo) to enter the node's mempool.\n"
866 "* WARNING: before version 0.21, fee_rate was in " +
CURRENCY_UNIT +
"/kvB. As of 0.21, fee_rate is in " +
CURRENCY_ATOM +
"/vB. *\n",
873 "\nSpecify a fee rate in " +
CURRENCY_ATOM +
"/vB instead of relying on the built-in fee estimator.\n"
874 "Must be at least " + incremental_fee +
" higher than the current transaction fee rate.\n"
875 "WARNING: before version 0.21, fee_rate was in " +
CURRENCY_UNIT +
"/kvB. As of 0.21, fee_rate is in " +
CURRENCY_ATOM +
"/vB.\n"},
877 "marked bip-125 replaceable. If true, the sequence numbers in the transaction will\n"
878 "be left unchanged from the original. If false, any input sequence numbers in the\n"
879 "original transaction that were less than 0xfffffffe will be increased to 0xfffffffe\n"
880 "so the new transaction will not be explicitly bip-125 replaceable (though it may\n"
881 "still be replaceable in practice, for example if it has unconfirmed ancestors which\n"
882 "are replaceable).\n"},
891 std::vector<RPCResult>{{
RPCResult::Type::STR,
"psbt",
"The base64-encoded unsigned PSBT of the new transaction."}} :
903 "\nBump the fee, get the new transaction\'s " + std::string(want_psbt ?
"psbt" :
"txid") +
"\n" +
912 throw JSONRPCError(
RPC_WALLET_ERROR,
"bumpfee is not available with wallets that have private keys disabled. Use psbtbumpfee instead.");
915 RPCTypeCheck(request.params, {UniValue::VSTR, UniValue::VOBJ});
923 if (!request.params[1].isNull()) {
924 UniValue options = request.params[1];
935 if (options.
exists(
"confTarget") && options.
exists(
"conf_target")) {
939 auto conf_target = options.
exists(
"confTarget") ? options[
"confTarget"] : options[
"conf_target"];
941 if (options.
exists(
"replaceable")) {
944 SetFeeEstimateMode(*pwallet, coin_control, conf_target, options[
"estimate_mode"], options[
"fee_rate"],
false);
949 pwallet->BlockUntilSyncedToCurrentChain();
951 LOCK(pwallet->cs_wallet);
956 std::vector<bilingual_str> errors;
1000 bool complete =
false;
1015 result.
pushKV(
"errors", result_errors);
1028 "\nEXPERIMENTAL warning: this call may be changed in future releases.\n"
1029 "\nSend a transaction.\n",
1032 "That is, each address can only appear once and there can only be one 'data' object.\n"
1033 "For convenience, a dictionary, which holds the key-value pairs directly, is also accepted.",
1049 " \"" +
FeeModes(
"\"\n\"") +
"\""},
1052 Cat<std::vector<RPCArg>>(
1055 {
"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"
1056 "Warning: the resulting transaction may become invalid if one of the unsafe inputs disappears.\n"
1057 "If that happens, you will need to fund the transaction with different inputs and republish it."},
1058 {
"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"},
1061 {
"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 \"legacy\", \"p2sh-segwit\", and \"bech32\"."},
1064 "Only solvable inputs can be used. Watch-only destinations are solvable if the public key and/or output script was imported,\n"
1065 "e.g. with 'importpubkey' or 'importmulti' with the 'pubkeys' or 'desc' field."},
1072 "including the weight of the outpoint and sequence number. "
1073 "Note that signature sizes are not guaranteed to be consistent, "
1074 "so the maximum DER signatures size of 73 bytes should be used when considering ECDSA signatures."
1075 "Remember to convert serialized sizes to weight units when necessary."},
1082 "The fee will be equally deducted from the amount of each specified output.\n"
1083 "Those recipients will receive less bitcoins than you enter in their corresponding amount field.\n"
1084 "If no outputs are specified here, the sender pays the fee.",
1097 {
RPCResult::Type::STR_HEX,
"txid",
true,
"The transaction id for the send. Only 1 transaction is created regardless of the number of addresses."},
1098 {
RPCResult::Type::STR_HEX,
"hex",
true,
"If add_to_wallet is false, the hex-encoded raw transaction with signature(s)"},
1099 {
RPCResult::Type::STR,
"psbt",
true,
"If more signatures are needed, or if add_to_wallet is false, the base64-encoded (partially) signed transaction"}
1103 "\nSend 0.1 BTC with a confirmation target of 6 blocks in economical fee estimate mode\n"
1105 "Send 0.2 BTC with a fee rate of 1.1 " +
CURRENCY_ATOM +
"/vB using positional arguments\n"
1107 "Send 0.2 BTC with a fee rate of 1 " +
CURRENCY_ATOM +
"/vB using the options argument\n"
1109 "Send 0.3 BTC with a fee rate of 25 " +
CURRENCY_ATOM +
"/vB using named arguments\n"
1111 "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"
1112 +
HelpExampleCli(
"send",
"'{\"" +
EXAMPLE_ADDRESS[0] +
"\": 0.1}' 1 economical '{\"add_to_wallet\": false, \"inputs\": [{\"txid\":\"a08e6907dbbd3d809776dbfc5d82e371b764ed838b5655e72f463568df1aadf0\", \"vout\":1}]}'")
1129 if (options.exists(
"conf_target") || options.exists(
"estimate_mode")) {
1130 if (!request.params[1].isNull() || !request.params[2].isNull()) {
1134 options.pushKV(
"conf_target", request.params[1]);
1135 options.pushKV(
"estimate_mode", request.params[2]);
1137 if (options.exists(
"fee_rate")) {
1138 if (!request.params[3].isNull()) {
1142 options.pushKV(
"fee_rate", request.params[3]);
1144 if (!options[
"conf_target"].isNull() && (options[
"estimate_mode"].isNull() || (options[
"estimate_mode"].get_str() ==
"unset"))) {
1147 if (options.exists(
"feeRate")) {
1150 if (options.exists(
"changeAddress")) {
1153 if (options.exists(
"changePosition")) {
1156 if (options.exists(
"includeWatching")) {
1159 if (options.exists(
"lockUnspents")) {
1162 if (options.exists(
"subtractFeeFromOutputs")) {
1166 const bool psbt_opt_in = options.exists(
"psbt") && options[
"psbt"].get_bool();
1169 int change_position;
1170 bool rbf = pwallet->m_signal_rbf;
1171 if (options.exists(
"replaceable")) {
1172 rbf = options[
"replaceable"].get_bool();
1180 FundTransaction(*pwallet, rawTx, fee, change_position, options, coin_control,
false);
1182 bool add_to_wallet =
true;
1183 if (options.exists(
"add_to_wallet")) {
1184 add_to_wallet = options[
"add_to_wallet"].get_bool();
1204 if (psbt_opt_in || !complete || !add_to_wallet) {
1212 std::string err_string;
1215 result.
pushKV(
"txid", tx->GetHash().GetHex());
1216 if (add_to_wallet && !psbt_opt_in) {
1217 pwallet->CommitTransaction(tx, {}, {} );
1219 result.
pushKV(
"hex", hex);
1222 result.
pushKV(
"complete", complete);
1232 "\nUpdate a PSBT with input information from our wallet and then sign inputs\n"
1233 "that we can sign for." +
1238 {
"sighashtype",
RPCArg::Type::STR,
RPCArg::Default{
"DEFAULT for Taproot, ALL otherwise"},
"The signature hash type to sign with if not specified by the PSBT. Must be one of\n"
1243 " \"ALL|ANYONECANPAY\"\n"
1244 " \"NONE|ANYONECANPAY\"\n"
1245 " \"SINGLE|ANYONECANPAY\""},
1267 wallet.BlockUntilSyncedToCurrentChain();
1282 bool sign = request.params[1].isNull() ? true : request.params[1].get_bool();
1283 bool bip32derivs = request.params[3].isNull() ? true : request.params[3].get_bool();
1284 bool finalize = request.params[4].isNull() ? true : request.params[4].get_bool();
1285 bool complete =
true;
1289 const TransactionError err{
wallet.FillPSBT(psbtx, complete, nHashType, sign, bip32derivs,
nullptr, finalize)};
1298 result.
pushKV(
"complete", complete);
1308 "\nCreates and funds a transaction in the Partially Signed Transaction format.\n"
1309 "Implements the Creator and Updater roles.\n"
1310 "All existing inputs must either have their previous output transaction be in the wallet\n"
1311 "or be in the UTXO set. Solving data must be provided for non-wallet inputs.\n",
1321 "including the weight of the outpoint and sequence number. "
1322 "Note that signature sizes are not guaranteed to be consistent, "
1323 "so the maximum DER signatures size of 73 bytes should be used when considering ECDSA signatures."
1324 "Remember to convert serialized sizes to weight units when necessary."},
1330 "That is, each address can only appear once and there can only be one 'data' object.\n"
1331 "For compatibility reasons, a dictionary, which holds the key-value pairs directly, is also\n"
1332 "accepted as second parameter.",
1348 Cat<std::vector<RPCArg>>(
1351 {
"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"
1352 "Warning: the resulting transaction may become invalid if one of the unsafe inputs disappears.\n"
1353 "If that happens, you will need to fund the transaction with different inputs and republish it."},
1356 {
"change_type",
RPCArg::Type::STR,
RPCArg::DefaultHint{
"set by -changetype"},
"The output type to use. Only valid if changeAddress is not specified. Options are \"legacy\", \"p2sh-segwit\", and \"bech32\"."},
1362 "The fee will be equally deducted from the amount of each specified output.\n"
1363 "Those recipients will receive less bitcoins than you enter in their corresponding amount field.\n"
1364 "If no outputs are specified here, the sender pays the fee.",
1383 "\nCreate a transaction with no inputs\n"
1384 +
HelpExampleCli(
"walletcreatefundedpsbt",
"\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]\" \"[{\\\"data\\\":\\\"00010203\\\"}]\"")
1394 wallet.BlockUntilSyncedToCurrentChain();
1405 UniValue options = request.params[3];
1408 int change_position;
1409 bool rbf{
wallet.m_signal_rbf};
1410 const UniValue &replaceable_arg = options[
"replaceable"];
1411 if (!replaceable_arg.
isNull()) {
1413 rbf = replaceable_arg.
isTrue();
1427 bool bip32derivs = request.params[4].isNull() ? true : request.params[4].get_bool();
1428 bool complete =
true;
1441 result.
pushKV(
"changepos", change_position);
@ RPC_INVALID_REQUEST
Standard JSON-RPC 2.0 errors.
An input of a transaction.
@ RPC_MISC_ERROR
General application defined errors.
RPCHelpMan walletcreatefundedpsbt()
std::unique_ptr< Descriptor > Parse(const std::string &descriptor, FlatSigningProvider &out, std::string &error, bool require_checksum)
Parse a descriptor string.
bool FeeModeFromString(const std::string &mode_string, FeeEstimateMode &fee_estimate_mode)
std::string HelpExampleCli(const std::string &methodname, const std::string &args)
std::vector< unsigned char > ParseHex(const char *psz)
unsigned int ParseConfirmTarget(const UniValue &value, unsigned int max_target)
Parse a confirm target option and raise an RPC error if it is invalid.
#define CHECK_NONFATAL(condition)
Throw a NonFatalCheckError when the condition evaluates to false.
UniValue SendMoney(CWallet &wallet, const CCoinControl &coin_control, std::vector< CRecipient > &recipients, mapValue_t map_value, bool verbose)
V Cat(V v1, V &&v2)
Concatenate two vectors, moving elements.
const UniValue NullUniValue
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
RPCHelpMan fundrawtransaction()
@ RPC_INVALID_PARAMETER
Invalid, missing or duplicate parameter.
bool IsHex(const std::string &str)
uint256 ParseHashV(const UniValue &v, std::string strName)
Utilities: convert hex-encoded Values (throws error if not hex).
std::shared_ptr< CWallet > GetWalletForJSONRPCRequest(const JSONRPCRequest &request)
Figures out what wallet, if any, to use for a JSONRPCRequest.
static CTransactionRef MakeTransactionRef(Tx &&txIn)
static std::vector< RPCArg > FundTxDoc()
FlatSigningProvider Merge(const FlatSigningProvider &a, const FlatSigningProvider &b)
std::optional< unsigned int > m_confirm_target
Override the default confirmation target if set.
bool fAllowWatchOnly
Includes watch only addresses which are solvable.
std::string EncodeBase64(Span< const unsigned char > input)
void RPCTypeCheckObj(const UniValue &o, const std::map< std::string, UniValueType > &typesExpected, bool fAllowNull, bool fStrict)
bool FinalizeAndExtractPSBT(PartiallySignedTransaction &psbtx, CMutableTransaction &result)
Finalizes a PSBT if possible, and extracts it to a CMutableTransaction if it could be finalized.
@ OBJ_USER_KEYS
Special type where the user must set the keys e.g. to define multiple addresses; as opposed to e....
std::shared_ptr< const CTransaction > CTransactionRef
void RPCTypeCheckArgument(const UniValue &value, const UniValueType &typeExpected)
Type-check one argument; throws JSONRPCError if wrong type given.
bool pushKV(const std::string &key, const UniValue &val)
Fee rate in satoshis per kilobyte: CAmount / kB.
bool DecodeBase64PSBT(PartiallySignedTransaction &psbt, const std::string &base64_tx, std::string &error)
Decode a base64ed PSBT into a PartiallySignedTransaction.
UniValue ValueFromAmount(const CAmount amount)
bool m_add_inputs
If false, only selected inputs are used.
The basic transaction that is broadcasted on the network and contained in blocks.
std::map< CScriptID, CScript > scripts
const std::string HELP_REQUIRING_PASSPHRASE
void ParsePrevouts(const UniValue &prevTxsUnival, FillableSigningProvider *keystore, std::map< COutPoint, Coin > &coins)
Parse a prevtxs UniValue array and get the map of coins from it.
const std::string & get_str() const
@ RPC_DESERIALIZATION_ERROR
Error parsing or validating structure in raw format.
Wrapper for UniValue::VType, which includes typeAny: Used to denote don't care type.
static const unsigned int DEFAULT_INCREMENTAL_RELAY_FEE
Default for -incrementalrelayfee, which sets the minimum feerate increase for mempool limiting or BIP...
void push_back(const T &value)
void SetInputWeight(const COutPoint &outpoint, int64_t weight)
int64_t get_int64() const
const std::string CURRENCY_UNIT
const UniValue & get_obj() const
@ SAT_VB
Use sat/vB fee rate unit.
std::variant< CNoDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, WitnessUnknown > CTxDestination
A txout script template with a specific destination.
bool IsValidDestination(const CTxDestination &dest)
Check whether a CTxDestination is a CNoDestination.
Result CommitTransaction(CWallet &wallet, const uint256 &txid, CMutableTransaction &&mtx, std::vector< bilingual_str > &errors, uint256 &bumped_txid)
Commit the bumpfee transaction.
@ OMITTED_NAMED_ARG
Optional arg that is a named argument and has a default value of null.
CTxDestination destChange
Custom change destination, if not set an address is generated.
FlatSigningProvider m_external_provider
SigningProvider that has pubkeys and scripts to do spend size estimation for external inputs.
@ STR_HEX
Special type that is a STR with only hex chars.
A CWallet maintains a set of transactions and balances, and provides the ability to create new transa...
bool m_avoid_address_reuse
Forbids inclusion of dirty (previously used) addresses.
bool exists(const std::string &key) const
@ WALLET_FLAG_DISABLE_PRIVATE_KEYS
std::optional< OutputType > m_change_type
Override the default change type if set, ignored if destChange is set.
std::optional< CFeeRate > m_feerate
Override the wallet's m_pay_tx_fee if set.
const std::string CURRENCY_ATOM
@ STR_HEX
Special string with only hex chars.
const std::string InvalidEstimateModeErrorMessage()
int64_t CAmount
Amount in satoshis (Can be negative)
std::string GetHex() const
bool m_avoid_partial_spends
Avoid partial use of funds sent to a given address.
std::optional< bool > m_signal_bip125_rbf
Override the wallet's m_signal_rbf if set.
@ RPC_WALLET_ERROR
Wallet errors.
const std::vector< std::string > & getKeys() const
void FundTransaction(CWallet &wallet, CMutableTransaction &tx, CAmount &fee_out, int &change_position, const UniValue &options, CCoinControl &coinControl, bool override_min_fee)
static RPCHelpMan bumpfee_helper(std::string method_name)
std::string ToString(const FeeEstimateMode &fee_estimate_mode=FeeEstimateMode::BTC_KVB) const
std::map< CKeyID, CPubKey > pubkeys
Serialized script, used inside transaction inputs and outputs.
std::string HelpExampleRpc(const std::string &methodname, const std::string &args)
Result CreateRateBumpTransaction(CWallet &wallet, const uint256 &txid, const CCoinControl &coin_control, std::vector< bilingual_str > &errors, CAmount &old_fee, CAmount &new_fee, CMutableTransaction &mtx)
Create bumpfee transaction based on feerate estimates.
CMutableTransaction ConstructTransaction(const UniValue &inputs_in, const UniValue &outputs_in, const UniValue &locktime, bool rbf)
Create a transaction from univalue parameters.
bool m_include_unsafe_inputs
If false, only safe inputs will be used.
RPCHelpMan signrawtransactionwithwallet()
RPCHelpMan sendtoaddress()
UniValue JSONRPCTransactionError(TransactionError terr, const std::string &err_string)
RPCHelpMan walletprocesspsbt()
bool CreateTransaction(CWallet &wallet, const std::vector< CRecipient > &vecSend, CTransactionRef &tx, CAmount &nFeeRet, int &nChangePosInOut, bilingual_str &error, const CCoinControl &coin_control, FeeCalculation &fee_calc_out, bool sign)
Create a new transaction paying the recipients with a set of coins selected by SelectCoins(); Also cr...
std::string EncodeHexTx(const CTransaction &tx, const int serializeFlags=0)
@ RPC_INVALID_ADDRESS_OR_KEY
Invalid address or key.
std::vector< CTxOut > vout
uint256 ParseHashO(const UniValue &o, std::string strKey)
An encapsulated public key.
bool SignTransaction(CWallet &wallet, CMutableTransaction &mtx)
Sign the new transaction,.
static const unsigned int MAX_STANDARD_TX_WEIGHT
The maximum weight for transactions we're willing to relay/mine.
@ RPC_WALLET_INSUFFICIENT_FUNDS
Not enough funds in wallet or account.
std::string FeeModes(const std::string &delimiter)
void RPCTypeCheck(const UniValue ¶ms, const std::list< UniValueType > &typesExpected, bool fAllowNull)
Type-check arguments; throws JSONRPCError if wrong type given.
static void ParseRecipients(const UniValue &address_amounts, const UniValue &subtract_fee_outputs, std::vector< CRecipient > &recipients)
UniValue JSONRPCError(int code, const std::string &message)
A version of CTransaction with the PSBT format.
void SelectExternal(const COutPoint &outpoint, const CTxOut &txout)
void SignTransactionResultToJSON(CMutableTransaction &mtx, bool complete, const std::map< COutPoint, Coin > &coins, const std::map< int, bilingual_str > &input_errors, UniValue &result)
@ OMITTED
Optional argument with default value omitted because they are implicitly clear.
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.
CTxDestination DecodeDestination(const std::string &str, std::string &error_msg, std::vector< int > *error_locations)
bool push_back(const UniValue &val)
static int64_t GetTransactionInputWeight(const CTxIn &txin)
bool IsFullyValid() const
fully validate whether this is a valid public key (more expensive than IsValid())
const std::string EXAMPLE_ADDRESS[2]
Example bech32 addresses for the RPCExamples help documentation.
const std::vector< UniValue > & getValues() const
Double ended buffer combining vector and stream-like interfaces.
bool fOverrideFeeRate
Override automatic min/max checks on fee, m_feerate must be set if true.
static void SetOptionsInputWeights(const UniValue &inputs, UniValue &options)
@ AMOUNT
Special type representing a floating point amount (can be either NUM or STR)
An outpoint - a combination of a transaction hash and an index n into its vout.
const UniValue & find_value(const UniValue &obj, const std::string &name)
FeeEstimateMode m_fee_mode
Fee estimation mode to control arguments to estimateSmartFee.
bool error(const char *fmt, const Args &... args)
std::string StringForFeeReason(FeeReason reason)
@ STR_AMOUNT
Special string to represent a floating point amount.
A mutable version of CTransaction.
const UniValue & get_array() const
std::map< std::string, std::string > mapValue_t
static CAmount AmountFromValue(const UniValue &value)
A reference to a CScript: the Hash160 of its serialization (see script.h)
std::optional< OutputType > ParseOutputType(const std::string &type)
bool ParseIncludeWatchonly(const UniValue &include_watchonly, const CWallet &wallet)
Used by RPC commands that have an include_watchonly parameter.
CKeyID GetID() const
Get the KeyID of this public key (hash of its serialization)
bool GetAvoidReuseFlag(const CWallet &wallet, const UniValue ¶m)
void EnsureWalletIsUnlocked(const CWallet &wallet)
static const int PROTOCOL_VERSION
network protocol versioning
bool DecodeHexTx(CMutableTransaction &tx, const std::string &hex_tx, bool try_no_witness=false, bool try_witness=true)
int ParseSighashString(const UniValue &sighash)
@ SIGHASH_DEFAULT
Taproot only; implied when sighash byte is missing, and equivalent to SIGHASH_ALL.