34 std::vector<CRecipient>
CreateRecipients(
const std::vector<std::pair<CTxDestination, CAmount>>& outputs,
const std::set<int>& subtract_fee_outputs)
36 std::vector<CRecipient> recipients;
37 for (
size_t i = 0; i < outputs.size(); ++i) {
38 const auto& [destination, amount] = outputs.at(i);
39 CRecipient recipient{destination, amount, subtract_fee_outputs.contains(i)};
40 recipients.push_back(recipient);
47 if (options.
exists(
"conf_target") || options.
exists(
"estimate_mode")) {
52 options.
pushKV(
"conf_target", conf_target);
53 options.
pushKV(
"estimate_mode", estimate_mode);
55 if (options.
exists(
"fee_rate")) {
60 options.
pushKV(
"fee_rate", fee_rate);
62 if (!options[
"conf_target"].isNull() && (options[
"estimate_mode"].isNull() || (options[
"estimate_mode"].get_str() ==
"unset"))) {
69 std::set<int> sffo_set;
70 if (sffo_instructions.
isNull())
return sffo_set;
71 if (sffo_instructions.
isBool()) {
72 if (sffo_instructions.
get_bool()) sffo_set.insert(0);
75 for (
const auto& sffo : sffo_instructions.
getValues()) {
77 for (
size_t i = 0; i < destinations.size(); ++i) {
78 if (sffo.get_str() == destinations.at(i)) {
85 int pos = sffo.getInt<
int>();
86 if (sffo_set.contains(pos))
90 if (pos >=
int(destinations.size()))
107 const auto err{pwallet->FillPSBT(psbtx, complete,
SIGHASH_DEFAULT,
true,
false)};
117 const bool psbt_opt_in{options.
exists(
"psbt") && options[
"psbt"].
get_bool()};
118 bool add_to_wallet{options.
exists(
"add_to_wallet") ? options[
"add_to_wallet"].
get_bool() :
true};
119 if (psbt_opt_in || !complete || !add_to_wallet) {
129 result.
pushKV(
"txid", tx->GetHash().GetHex());
130 if (add_to_wallet && !psbt_opt_in) {
131 pwallet->CommitTransaction(tx, {}, {});
133 result.
pushKV(
"hex", hex);
136 result.
pushKV(
"complete", complete);
143 if (options.
exists(
"feeRate")) {
146 if (options.
exists(
"changeAddress")) {
149 if (options.
exists(
"changePosition")) {
152 if (options.
exists(
"includeWatching")) {
155 if (options.
exists(
"lockUnspents")) {
158 if (options.
exists(
"subtractFeeFromOutputs")) {
182 wallet.CommitTransaction(tx, std::move(map_value), {});
185 entry.
pushKV(
"txid", tx->GetHash().GetHex());
189 return tx->GetHash().GetHex();
209 if (!conf_target.
isNull()) {
210 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.");
212 if (!estimate_mode.
isNull() && estimate_mode.
get_str() !=
"unset") {
225 if (!conf_target.
isNull()) {
233 "\nSend an amount to a given address." +
239 "This is not part of the transaction, just kept in your wallet."},
241 "to which you're sending the transaction. This is not part of the \n" 242 "transaction, just kept in your wallet."},
244 "The recipient will receive less bitcoins than you enter in the amount field."},
248 +
FeeModesDetail(std::string(
"economical mode is used if the transaction is replaceable;\notherwise, conservative mode is used"))},
249 {
"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" 250 "dirty if they have previously been used in a transaction. If true, this also activates avoidpartialspends, grouping outputs by their addresses."},
255 RPCResult{
"if verbose is not set or set to false",
269 "\nSend 0.1 BTC with a confirmation target of 6 blocks in economical fee estimate mode using positional arguments\n" 271 "\nSend 0.1 BTC with a fee rate of 1.1 " +
CURRENCY_ATOM +
"/vB, subtract fee from amount, BIP125-replaceable, using positional arguments\n" 273 "\nSend 0.2 BTC with a confirmation target of 6 blocks in economical fee estimate mode using named arguments\n" 275 "\nSend 0.5 BTC with a fee rate of 25 " +
CURRENCY_ATOM +
"/vB using named arguments\n" 277 +
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")
286 pwallet->BlockUntilSyncedToCurrentChain();
288 LOCK(pwallet->cs_wallet);
292 if (!request.params[2].isNull() && !request.params[2].get_str().empty())
293 mapValue[
"comment"] = request.params[2].get_str();
294 if (!request.params[3].isNull() && !request.params[3].get_str().empty())
295 mapValue[
"to"] = request.params[3].get_str();
298 if (!request.params[5].isNull()) {
306 SetFeeEstimateMode(*pwallet, coin_control, request.params[6], request.params[7], request.params[9],
false);
311 const std::string address = request.params[0].get_str();
312 address_amounts.
pushKV(address, request.params[1]);
317 const bool verbose{request.params[10].isNull() ? false : request.params[10].get_bool()};
319 return SendMoney(*pwallet, coin_control, recipients, mapValue, verbose);
327 "Send multiple times. Amounts are double-precision floating point numbers." +
342 "The fee will be equally deducted from the amount of each selected address.\n" 343 "Those recipients will receive less bitcoins than you enter in their corresponding amount field.\n" 344 "If no addresses are specified here, the sender pays the fee.",
352 +
FeeModesDetail(std::string(
"economical mode is used if the transaction is replaceable;\notherwise, conservative mode is used"))},
357 RPCResult{
"if verbose is not set or set to false",
359 "the number of addresses." 365 "the number of addresses."},
371 "\nSend two amounts to two different addresses:\n" 373 "\nSend two amounts to two different addresses setting the confirmation and comment:\n" 375 "\nSend two amounts to two different addresses, subtract fee from amount:\n" 377 "\nAs a JSON-RPC call\n" 387 pwallet->BlockUntilSyncedToCurrentChain();
389 LOCK(pwallet->cs_wallet);
391 if (!request.params[0].isNull() && !request.params[0].get_str().empty()) {
397 if (!request.params[3].isNull() && !request.params[3].get_str().empty())
398 mapValue[
"comment"] = request.params[3].
get_str();
401 if (!request.params[5].isNull()) {
405 SetFeeEstimateMode(*pwallet, coin_control, request.params[6], request.params[7], request.params[8],
false);
411 const bool verbose{request.params[9].isNull() ? false : request.params[9].get_bool()};
413 return SendMoney(*pwallet, coin_control, recipients, std::move(mapValue), verbose);
421 "\nSet the transaction fee rate in " +
CURRENCY_UNIT +
"/kvB for this wallet. Overrides the global -paytxfee command line parameter.\n" 422 "Can be deactivated by passing 0 as the fee. In that case automatic fee selection will be used by default.\n",
438 LOCK(pwallet->cs_wallet);
441 CFeeRate tx_fee_rate(nAmount, 1000);
442 CFeeRate max_tx_fee_rate(pwallet->m_default_max_tx_fee, 1000);
445 }
else if (tx_fee_rate < pwallet->chain().relayMinFee()) {
447 }
else if (tx_fee_rate < pwallet->m_min_fee) {
449 }
else if (tx_fee_rate > max_tx_fee_rate) {
453 pwallet->m_pay_tx_fee = tx_fee_rate;
461 static std::vector<RPCArg>
FundTxDoc(
bool solving_data =
true)
463 std::vector<RPCArg>
args = {
469 "Allows this transaction to be replaced by a transaction with higher fees" 474 "Used for fee estimation during coin selection.",
507 wallet.BlockUntilSyncedToCurrentChain();
509 std::optional<unsigned int> change_position;
510 bool lockUnspents =
false;
549 if (options.
exists(
"add_inputs")) {
553 if (options.
exists(
"changeAddress") || options.
exists(
"change_address")) {
554 const std::string change_address_str = (options.
exists(
"change_address") ? options[
"change_address"] : options[
"changeAddress"]).get_str();
564 if (options.
exists(
"changePosition") || options.
exists(
"change_position")) {
565 int pos = (options.
exists(
"change_position") ? options[
"change_position"] : options[
"changePosition"]).getInt<int>();
566 if (pos < 0 || (
unsigned int)pos > recipients.size()) {
569 change_position = (
unsigned int)pos;
572 if (options.
exists(
"change_type")) {
573 if (options.
exists(
"changeAddress") || options.
exists(
"change_address")) {
576 if (std::optional<OutputType> parsed =
ParseOutputType(options[
"change_type"].get_str())) {
583 const UniValue include_watching_option = options.
exists(
"include_watching") ? options[
"include_watching"] : options[
"includeWatching"];
586 if (options.
exists(
"lockUnspents") || options.
exists(
"lock_unspents")) {
587 lockUnspents = (options.
exists(
"lock_unspents") ? options[
"lock_unspents"] : options[
"lockUnspents"]).get_bool();
590 if (options.
exists(
"include_unsafe")) {
594 if (options.
exists(
"feeRate")) {
595 if (options.
exists(
"fee_rate")) {
598 if (options.
exists(
"conf_target")) {
599 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.");
601 if (options.
exists(
"estimate_mode")) {
608 if (options.
exists(
"replaceable")) {
612 if (options.
exists(
"minconf")) {
620 if (options.
exists(
"maxconf")) {
627 SetFeeEstimateMode(
wallet, coinControl, options[
"conf_target"], options[
"estimate_mode"], options[
"fee_rate"], override_min_fee);
634 if (options.
exists(
"solving_data")) {
636 if (solving_data.
exists(
"pubkeys")) {
637 for (
const UniValue& pk_univ : solving_data[
"pubkeys"].get_array().
getValues()) {
646 if (solving_data.
exists(
"scripts")) {
647 for (
const UniValue& script_univ : solving_data[
"scripts"].get_array().
getValues()) {
648 const std::string& script_str = script_univ.get_str();
649 if (!
IsHex(script_str)) {
652 std::vector<unsigned char> script_data(
ParseHex(script_str));
653 const CScript script(script_data.begin(), script_data.end());
658 if (solving_data.
exists(
"descriptors")) {
659 for (
const UniValue& desc_univ : solving_data[
"descriptors"].get_array().
getValues()) {
660 const std::string& desc_str = desc_univ.get_str();
663 std::vector<CScript> scripts_temp;
664 std::unique_ptr<Descriptor> desc =
Parse(desc_str, desc_out, error,
true);
668 desc->Expand(0, desc_out, scripts_temp, desc_out);
674 if (options.
exists(
"input_weights")) {
679 if (!vout_v.
isNum()) {
682 int vout = vout_v.
getInt<
int>();
688 if (!weight_v.
isNum()) {
691 int64_t weight = weight_v.
getInt<int64_t>();
694 if (weight < min_input_weight) {
695 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)");
705 if (options.
exists(
"max_tx_weight")) {
709 if (recipients.empty())
721 if (options.
exists(
"input_weights")) {
724 if (inputs.
size() == 0) {
729 if (input.exists(
"weight")) {
733 options.
pushKV(
"input_weights", std::move(weights));
739 "\nIf the transaction has no inputs, they will be automatically selected to meet its out value.\n" 740 "It will add at most one change output to the outputs.\n" 741 "No existing outputs will be modified unless \"subtractFeeFromOutputs\" is specified.\n" 742 "Note that inputs which were signed may need to be resigned after completion since in/outputs have been added.\n" 743 "The inputs added will not be signed, use signrawtransactionwithkey\n" 744 "or signrawtransactionwithwallet for that.\n" 745 "All existing inputs must either have their previous output transaction be in the wallet\n" 746 "or be in the UTXO set. Solving data must be provided for non-wallet inputs.\n" 747 "Note that all inputs selected must be of standard form and P2SH scripts must be\n" 748 "in the wallet using importaddress or addmultisigaddress (to calculate fees).\n" 749 "You can see whether this is the case by checking the \"solvable\" field in the listunspent output.\n" 750 "Only pay-to-pubkey, multisig, and P2SH versions thereof are currently supported for watch-only\n",
754 Cat<std::vector<RPCArg>>(
757 {
"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" 758 "Warning: the resulting transaction may become invalid if one of the unsafe inputs disappears.\n" 759 "If that happens, you will need to fund the transaction with different inputs and republish it."},
764 {
"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\", \"bech32\", and \"bech32m\"."},
766 "Only solvable inputs can be used. Watch-only destinations are solvable if the public key and/or output script was imported,\n" 767 "e.g. with 'importpubkey' or 'importmulti' with the 'pubkeys' or 'desc' field."},
772 "The fee will be equally deducted from the amount of each specified output.\n" 773 "Those recipients will receive less bitcoins than you enter in their corresponding amount field.\n" 774 "If no outputs are specified here, the sender pays the fee.",
786 "including the weight of the outpoint and sequence number. " 787 "Note that serialized signature sizes are not guaranteed to be consistent, " 788 "so the maximum DER signatures size of 73 bytes should be used when considering ECDSA signatures." 789 "Remember to convert serialized sizes to weight units when necessary."},
795 "Transaction building will fail if this can not be satisfied."},
800 .oneline_description =
"options",
803 "If iswitness is not present, heuristic tests will be used in decoding.\n" 804 "If true, only witness deserialization will be tried.\n" 805 "If false, only non-witness deserialization will be tried.\n" 806 "This boolean should reflect whether the transaction has inputs\n" 807 "(e.g. fully valid, or on-chain transactions), if known by the caller." 819 "\nCreate a transaction with no inputs\n" 820 +
HelpExampleCli(
"createrawtransaction",
"\"[]\" \"{\\\"myaddress\\\":0.01}\"") +
821 "\nAdd sufficient unsigned inputs to meet the output value\n" 823 "\nSign the transaction\n" 824 +
HelpExampleCli(
"signrawtransactionwithwallet",
"\"fundedtransactionhex\"") +
825 "\nSend the transaction\n" 826 +
HelpExampleCli(
"sendrawtransaction",
"\"signedtransactionhex\"")
835 bool try_witness = request.params[2].isNull() ? true : request.params[2].get_bool();
836 bool try_no_witness = request.params[2].isNull() ? true : !request.params[2].get_bool();
837 if (!
DecodeHexTx(tx, request.params[0].get_str(), try_no_witness, try_witness)) {
840 UniValue options = request.params[1];
841 std::vector<std::pair<CTxDestination, CAmount>> destinations;
842 for (
const auto& tx_out : tx.
vout) {
845 destinations.emplace_back(dest, tx_out.nValue);
847 std::vector<std::string> dummy(destinations.size(),
"dummy");
858 auto txr =
FundTransaction(*pwallet, tx, recipients, options, coin_control,
true);
863 result.
pushKV(
"changepos", txr.change_pos ? (
int)*txr.change_pos : -1);
872 return RPCHelpMan{
"signrawtransactionwithwallet",
873 "\nSign inputs for raw transaction (serialized, hex-encoded).\n" 874 "The second optional argument (may be null) is an array of previous transaction outputs that\n" 875 "this transaction depends on but may not yet be in the block chain." +
898 " \"ALL|ANYONECANPAY\"\n" 899 " \"NONE|ANYONECANPAY\"\n" 900 " \"SINGLE|ANYONECANPAY\""},
934 if (!
DecodeHexTx(mtx, request.params[0].get_str())) {
939 LOCK(pwallet->cs_wallet);
943 std::map<COutPoint, Coin> coins;
947 pwallet->chain().findCoins(coins);
955 std::map<int, bilingual_str> input_errors;
957 bool complete = pwallet->SignTransaction(mtx, coins, nHashType, input_errors);
974 "the value (float or string) is the amount in " +
CURRENCY_UNIT +
""},
987 const bool want_psbt = method_name ==
"psbtbumpfee";
991 "\nBumps the fee of an opt-in-RBF transaction T, replacing it with a new transaction B.\n" 992 + std::string(want_psbt ?
"Returns a PSBT instead of creating and signing a new transaction.\n" :
"") +
993 "An opt-in RBF transaction with the given txid must be in the wallet.\n" 994 "The command will pay the additional fee by reducing change outputs or adding inputs when necessary.\n" 995 "It may add a new change output if one does not already exist.\n" 996 "All inputs in the original transaction will be included in the replacement transaction.\n" 997 "The command will fail if the wallet or mempool contains a transaction that spends one of T's outputs.\n" 998 "By default, the new fee will be calculated automatically using the estimatesmartfee RPC.\n" 999 "The user can specify a confirmation target for estimatesmartfee.\n" 1000 "Alternatively, the user can specify a fee rate in " +
CURRENCY_ATOM +
"/vB for the new transaction.\n" 1001 "At a minimum, the new fee rate must be high enough to pay an additional new relay fee (incrementalfee\n" 1002 "returned by getnetworkinfo) to enter the node's mempool.\n" 1003 "* WARNING: before version 0.21, fee_rate was in " +
CURRENCY_UNIT +
"/kvB. As of 0.21, fee_rate is in " +
CURRENCY_ATOM +
"/vB. *\n",
1010 "\nSpecify a fee rate in " +
CURRENCY_ATOM +
"/vB instead of relying on the built-in fee estimator.\n" 1011 "Must be at least " + incremental_fee +
" higher than the current transaction fee rate.\n" 1012 "WARNING: before version 0.21, fee_rate was in " +
CURRENCY_UNIT +
"/kvB. As of 0.21, fee_rate is in " +
CURRENCY_ATOM +
"/vB.\n"},
1014 "marked bip-125 replaceable. If true, the sequence numbers in the transaction will\n" 1015 "be left unchanged from the original. If false, any input sequence numbers in the\n" 1016 "original transaction that were less than 0xfffffffe will be increased to 0xfffffffe\n" 1017 "so the new transaction will not be explicitly bip-125 replaceable (though it may\n" 1018 "still be replaceable in practice, for example if it has unconfirmed ancestors which\n" 1019 "are replaceable).\n"},
1021 +
FeeModesDetail(std::string(
"economical mode is used if the transaction is replaceable;\notherwise, conservative mode is used"))},
1023 "Each key may only appear once, i.e. there can only be one 'data' output, and no address may be duplicated.\n" 1024 "At least one output of either type must be specified.\n" 1025 "Cannot be provided if 'original_change_index' is specified.",
1028 {
"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. " 1029 "The indicated output will be recycled into the new change output on the bumped transaction. " 1030 "The remainder after paying the recipients and fees will be sent to the output script of the " 1031 "original change output. The change output’s amount can increase if bumping the transaction " 1032 "adds new inputs, otherwise it will decrease. Cannot be used in combination with the 'outputs' option."},
1039 std::vector<RPCResult>{{
RPCResult::Type::STR,
"psbt",
"The base64-encoded unsigned PSBT of the new transaction."}} :
1051 "\nBump the fee, get the new transaction\'s " + std::string(want_psbt ?
"psbt" :
"txid") +
"\n" +
1060 throw JSONRPCError(
RPC_WALLET_ERROR,
"bumpfee is not available with wallets that have private keys disabled. Use psbtbumpfee instead.");
1069 std::vector<CTxOut> outputs;
1071 std::optional<uint32_t> original_change_index;
1073 if (!request.params[1].isNull()) {
1074 UniValue options = request.params[1];
1087 if (options.
exists(
"confTarget") && options.
exists(
"conf_target")) {
1091 auto conf_target = options.
exists(
"confTarget") ? options[
"confTarget"] : options[
"conf_target"];
1093 if (options.
exists(
"replaceable")) {
1096 SetFeeEstimateMode(*pwallet, coin_control, conf_target, options[
"estimate_mode"], options[
"fee_rate"],
false);
1099 if (!options[
"outputs"].isNull()) {
1100 if (options[
"outputs"].isArray() && options[
"outputs"].empty()) {
1105 outputs = tempTx.
vout;
1108 if (options.
exists(
"original_change_index")) {
1109 original_change_index = options[
"original_change_index"].
getInt<uint32_t>();
1115 pwallet->BlockUntilSyncedToCurrentChain();
1117 LOCK(pwallet->cs_wallet);
1122 std::vector<bilingual_str> errors;
1169 bool complete =
false;
1170 const auto err{pwallet->FillPSBT(psbtx, complete,
SIGHASH_DEFAULT,
false,
true)};
1182 result_errors.
push_back(error.original);
1184 result.
pushKV(
"errors", std::move(result_errors));
1197 "\nEXPERIMENTAL warning: this call may be changed in future releases.\n" 1198 "\nSend a transaction.\n",
1201 "Each key may only appear once, i.e. there can only be one 'data' output, and no address may be duplicated.\n" 1202 "At least one output of either type must be specified.\n" 1203 "For convenience, a dictionary, which holds the key-value pairs directly, is also accepted.",
1208 +
FeeModesDetail(std::string(
"economical mode is used if the transaction is replaceable;\notherwise, conservative mode is used"))},
1211 Cat<std::vector<RPCArg>>(
1213 {
"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"},
1214 {
"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" 1215 "Warning: the resulting transaction may become invalid if one of the unsafe inputs disappears.\n" 1216 "If that happens, you will need to fund the transaction with different inputs and republish it."},
1219 {
"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 {
"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\", \"bech32\" and \"bech32m\"."},
1225 "Only solvable inputs can be used. Watch-only destinations are solvable if the public key and/or output script was imported,\n" 1226 "e.g. with 'importpubkey' or 'importmulti' with the 'pubkeys' or 'desc' field."},
1233 "including the weight of the outpoint and sequence number. " 1234 "Note that signature sizes are not guaranteed to be consistent, " 1235 "so the maximum DER signatures size of 73 bytes should be used when considering ECDSA signatures." 1236 "Remember to convert serialized sizes to weight units when necessary."},
1243 "The fee will be equally deducted from the amount of each specified output.\n" 1244 "Those recipients will receive less bitcoins than you enter in their corresponding amount field.\n" 1245 "If no outputs are specified here, the sender pays the fee.",
1251 "Transaction building will fail if this can not be satisfied."},
1260 {
RPCResult::Type::STR_HEX,
"txid",
true,
"The transaction id for the send. Only 1 transaction is created regardless of the number of addresses."},
1261 {
RPCResult::Type::STR_HEX,
"hex",
true,
"If add_to_wallet is false, the hex-encoded raw transaction with signature(s)"},
1262 {
RPCResult::Type::STR,
"psbt",
true,
"If more signatures are needed, or if add_to_wallet is false, the base64-encoded (partially) signed transaction"}
1266 "\nSend 0.1 BTC with a confirmation target of 6 blocks in economical fee estimate mode\n" 1268 "Send 0.2 BTC with a fee rate of 1.1 " +
CURRENCY_ATOM +
"/vB using positional arguments\n" 1270 "Send 0.2 BTC with a fee rate of 1 " +
CURRENCY_ATOM +
"/vB using the options argument\n" 1272 "Send 0.3 BTC with a fee rate of 25 " +
CURRENCY_ATOM +
"/vB using named arguments\n" 1274 "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" 1275 +
HelpExampleCli(
"send",
"'{\"" +
EXAMPLE_ADDRESS[0] +
"\": 0.1}' 1 economical '{\"add_to_wallet\": false, \"inputs\": [{\"txid\":\"a08e6907dbbd3d809776dbfc5d82e371b764ed838b5655e72f463568df1aadf0\", \"vout\":1}]}'")
1287 bool rbf{options.exists(
"replaceable") ? options[
"replaceable"].get_bool() : pwallet->m_signal_rbf};
1299 if (options.exists(
"max_tx_weight")) {
1300 coin_control.
m_max_tx_weight = options[
"max_tx_weight"].getInt<
int>();
1306 auto txr =
FundTransaction(*pwallet, rawTx, recipients, options, coin_control,
false);
1316 "EXPERIMENTAL warning: this call may be changed in future releases.\n" 1317 "\nSpend the value of all (or specific) confirmed UTXOs and unconfirmed change in the wallet to one or more recipients.\n" 1318 "Unconfirmed inbound UTXOs and locked UTXOs will not be spent. Sendall will respect the avoid_reuse wallet flag.\n" 1319 "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",
1322 "Optionally some recipients can be specified with an amount to perform payments, but at least one address must appear without a specified amount.\n",
1334 +
FeeModesDetail(std::string(
"economical mode is used if the transaction is replaceable;\notherwise, conservative mode is used"))},
1338 Cat<std::vector<RPCArg>>(
1343 "Only solvable inputs can be used. Watch-only destinations are solvable if the public key and/or output script was imported,\n" 1344 "e.g. with 'importpubkey' or 'importmulti' with the 'pubkeys' or 'desc' field."},
1359 {
"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."},
1372 {
RPCResult::Type::STR_HEX,
"txid",
true,
"The transaction id for the send. Only 1 transaction is created regardless of the number of addresses."},
1373 {
RPCResult::Type::STR_HEX,
"hex",
true,
"If add_to_wallet is false, the hex-encoded raw transaction with signature(s)"},
1374 {
RPCResult::Type::STR,
"psbt",
true,
"If more signatures are needed, or if add_to_wallet is false, the base64-encoded (partially) signed transaction"}
1378 "\nSpend all UTXOs from the wallet with a fee rate of 1Â " +
CURRENCY_ATOM +
"/vB using named arguments\n" 1380 "Spend all UTXOs with a fee rate of 1.1 " +
CURRENCY_ATOM +
"/vB using positional arguments\n" 1382 "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" 1384 "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" 1386 "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" 1395 pwallet->BlockUntilSyncedToCurrentChain();
1402 std::set<std::string> addresses_without_amount;
1404 const UniValue& recipients{request.params[0]};
1405 for (
unsigned int i = 0; i < recipients.size(); ++i) {
1406 const UniValue& recipient{recipients[i]};
1407 if (recipient.isStr()) {
1409 rkvp.
pushKV(recipient.get_str(), 0);
1410 recipient_key_value_pairs.
push_back(std::move(rkvp));
1411 addresses_without_amount.insert(recipient.get_str());
1413 recipient_key_value_pairs.
push_back(recipient);
1417 if (addresses_without_amount.size() == 0) {
1423 SetFeeEstimateMode(*pwallet, coin_control, options[
"conf_target"], options[
"estimate_mode"], options[
"fee_rate"],
false);
1427 if (options.exists(
"minconf")) {
1428 if (options[
"minconf"].getInt<int>() < 0)
1433 coin_control.
m_min_depth = options[
"minconf"].getInt<
int>();
1436 if (options.exists(
"maxconf")) {
1437 coin_control.
m_max_depth = options[
"maxconf"].getInt<
int>();
1444 const bool rbf{options.exists(
"replaceable") ? options[
"replaceable"].get_bool() : pwallet->m_signal_rbf};
1459 LOCK(pwallet->cs_wallet);
1462 bool send_max{options.exists(
"send_max") ? options[
"send_max"].get_bool() :
false};
1463 if (options.exists(
"inputs") && options.exists(
"send_max")) {
1465 }
else if (options.exists(
"inputs") && (options.exists(
"minconf") || options.exists(
"maxconf"))) {
1467 }
else if (options.exists(
"inputs")) {
1468 for (
const CTxIn& input : rawTx.vin) {
1469 if (pwallet->IsSpent(input.
prevout)) {
1476 total_input_value += tx->tx->vout[input.
prevout.
n].nValue;
1483 if (send_max && fee_rate.GetFee(output.input_bytes) > output.txout.nValue) {
1487 rawTx.vin.push_back(input);
1488 total_input_value += output.txout.nValue;
1492 std::vector<COutPoint> outpoints_spent;
1493 outpoints_spent.reserve(rawTx.vin.size());
1495 for (
const CTxIn& tx_in : rawTx.vin) {
1496 outpoints_spent.push_back(tx_in.
prevout);
1501 const CAmount fee_from_size{fee_rate.GetFee(tx_size.vsize)};
1502 const std::optional<CAmount> total_bump_fees{pwallet->chain().calculateCombinedBumpFee(outpoints_spent, fee_rate)};
1503 CAmount effective_value = total_input_value - fee_from_size - total_bump_fees.value_or(0);
1505 if (fee_from_size > pwallet->m_default_max_tx_fee) {
1509 if (effective_value <= 0) {
1522 CAmount output_amounts_claimed{0};
1524 output_amounts_claimed +=
out.nValue;
1527 if (output_amounts_claimed > total_input_value) {
1531 const CAmount remainder{effective_value - output_amounts_claimed};
1532 if (remainder < 0) {
1536 const CAmount per_output_without_amount{remainder / (long)addresses_without_amount.size()};
1538 bool gave_remaining_to_first{
false};
1543 if (addresses_without_amount.count(addr) > 0) {
1544 out.nValue = per_output_without_amount;
1545 if (!gave_remaining_to_first) {
1546 out.nValue += remainder % addresses_without_amount.size();
1547 gave_remaining_to_first =
true;
1549 if (
IsDust(
out, pwallet->chain().relayDustFee())) {
1554 if (
IsDust(
out, pwallet->chain().relayDustFee())) {
1561 const bool lock_unspents{options.exists(
"lock_unspents") ? options[
"lock_unspents"].get_bool() :
false};
1562 if (lock_unspents) {
1563 for (
const CTxIn& txin : rawTx.vin) {
1564 pwallet->LockCoin(txin.
prevout);
1576 "\nUpdate a PSBT with input information from our wallet and then sign inputs\n" 1577 "that we can sign for." +
1582 {
"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" 1587 " \"ALL|ANYONECANPAY\"\n" 1588 " \"NONE|ANYONECANPAY\"\n" 1589 " \"SINGLE|ANYONECANPAY\""},
1612 wallet.BlockUntilSyncedToCurrentChain();
1625 bool sign = request.params[1].isNull() ? true : request.params[1].get_bool();
1626 bool bip32derivs = request.params[3].isNull() ? true : request.params[3].get_bool();
1627 bool finalize = request.params[4].isNull() ? true : request.params[4].get_bool();
1628 bool complete =
true;
1632 const auto err{
wallet.FillPSBT(psbtx, complete, nHashType, sign, bip32derivs,
nullptr, finalize)};
1641 result.
pushKV(
"complete", complete);
1659 "\nCreates and funds a transaction in the Partially Signed Transaction format.\n" 1660 "Implements the Creator and Updater roles.\n" 1661 "All existing inputs must either have their previous output transaction be in the wallet\n" 1662 "or be in the UTXO set. Solving data must be provided for non-wallet inputs.\n",
1672 "including the weight of the outpoint and sequence number. " 1673 "Note that signature sizes are not guaranteed to be consistent, " 1674 "so the maximum DER signatures size of 73 bytes should be used when considering ECDSA signatures." 1675 "Remember to convert serialized sizes to weight units when necessary."},
1681 "Each key may only appear once, i.e. there can only be one 'data' output, and no address may be duplicated.\n" 1682 "At least one output of either type must be specified.\n" 1683 "For compatibility reasons, a dictionary, which holds the key-value pairs directly, is also\n" 1684 "accepted as second parameter.",
1689 Cat<std::vector<RPCArg>>(
1691 {
"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"},
1692 {
"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" 1693 "Warning: the resulting transaction may become invalid if one of the unsafe inputs disappears.\n" 1694 "If that happens, you will need to fund the transaction with different inputs and republish it."},
1699 {
"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\", \"bech32\", and \"bech32m\"."},
1705 "The fee will be equally deducted from the amount of each specified output.\n" 1706 "Those recipients will receive less bitcoins than you enter in their corresponding amount field.\n" 1707 "If no outputs are specified here, the sender pays the fee.",
1713 "Transaction building will fail if this can not be satisfied."},
1728 "\nCreate a transaction with no inputs\n" 1729 +
HelpExampleCli(
"walletcreatefundedpsbt",
"\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]\" \"[{\\\"data\\\":\\\"00010203\\\"}]\"")
1739 wallet.BlockUntilSyncedToCurrentChain();
1743 const UniValue &replaceable_arg = options[
"replaceable"];
1766 bool bip32derivs = request.params[4].isNull() ? true : request.params[4].get_bool();
1767 bool complete =
true;
1768 const auto err{
wallet.FillPSBT(psbtx, complete, 1,
false, bip32derivs)};
1780 result.
pushKV(
"changepos", txr.change_pos ? (
int)*txr.change_pos : -1);
std::shared_ptr< const CTransaction > CTransactionRef
static RPCHelpMan bumpfee_helper(std::string method_name)
static UniValue Parse(std::string_view raw)
Parse string to UniValue or throw runtime_error if string contains invalid JSON.
void push_back(UniValue val)
bool m_avoid_partial_spends
Avoid partial use of funds sent to a given address.
std::optional< unsigned int > m_confirm_target
Override the default confirmation target if set.
static constexpr unsigned int DEFAULT_INCREMENTAL_RELAY_FEE
Default for -incrementalrelayfee, which sets the minimum feerate increase for mempool limiting or rep...
const std::vector< UniValue > & getValues() const
std::vector< Byte > ParseHex(std::string_view hex_str)
Like TryParseHex, but returns an empty vector on invalid input.
uint256 ParseHashO(const UniValue &o, std::string_view strKey)
void RPCTypeCheckObj(const UniValue &o, const std::map< std::string, UniValueType > &typesExpected, bool fAllowNull, bool fStrict)
bool IsValidDestination(const CTxDestination &dest)
Check whether a CTxDestination corresponds to one with an address.
std::string StringForFeeReason(FeeReason reason)
is a home for simple string functions returning descriptive messages that are used in RPC and GUI int...
CTxDestination destChange
Custom change destination, if not set an address is generated.
bool also_positional
If set allows a named-parameter field in an OBJ_NAMED_PARAM options object to have the same name as a...
std::map< std::string, std::string > mapValue_t
Taproot only; implied when sighash byte is missing, and equivalent to SIGHASH_ALL.
RPCHelpMan sendtoaddress()
static const uint32_t SEQUENCE_FINAL
Setting nSequence to this value for every input in a transaction disables nLockTime/IsFinalTx().
UniValue NormalizeOutputs(const UniValue &outputs_in)
Normalize univalue-represented outputs.
int ParseSighashString(const UniValue &sighash)
Returns a sighash value corresponding to the passed in argument.
#define CHECK_NONFATAL(condition)
Identity function.
bool IsHex(std::string_view str)
Special type that behaves almost exactly like OBJ, defining an options object with a list of pre-defi...
std::optional< int > m_max_tx_weight
Caps weight of resulting tx.
std::vector< CRecipient > CreateRecipients(const std::vector< std::pair< CTxDestination, CAmount >> &outputs, const std::set< int > &subtract_fee_outputs)
bool ParseIncludeWatchonly(const UniValue &include_watchonly, const CWallet &wallet)
Used by RPC commands that have an include_watchonly parameter.
CPubKey HexToPubKey(const std::string &hex_in)
static std::vector< RPCArg > FundTxDoc(bool solving_data=true)
std::string InvalidEstimateModeErrorMessage()
std::string EncodeBase64(Span< const unsigned char > input)
bool fAllowWatchOnly
Includes watch only addresses which are solvable.
bool FeeModeFromString(const std::string &mode_string, FeeEstimateMode &fee_estimate_mode)
const std::string & get_str() const
static std::vector< RPCArg > OutputsDoc()
const std::string EXAMPLE_ADDRESS[2]
Example bech32 addresses for the RPCExamples help documentation.
Use sat/vB fee rate unit.
unsigned int ParseConfirmTarget(const UniValue &value, unsigned int max_target)
Parse a confirm target option and raise an RPC error if it is invalid.
FlatSigningProvider m_external_provider
SigningProvider that has pubkeys and scripts to do spend size estimation for external inputs...
A version of CTransaction with the PSBT format.
Result CreateRateBumpTransaction(CWallet &wallet, const uint256 &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.
static void SetOptionsInputWeights(const UniValue &inputs, UniValue &options)
const std::vector< std::string > & getKeys() const
void AddOutputs(CMutableTransaction &rawTx, const UniValue &outputs_in)
Normalize, parse, and add outputs to the transaction.
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)
CKeyID GetID() const
Get the KeyID of this public key (hash of its serialization)
bilingual_str TransactionErrorString(const TransactionError err)
Invalid, missing or duplicate parameter.
Result CommitTransaction(CWallet &wallet, const uint256 &txid, CMutableTransaction &&mtx, std::vector< bilingual_str > &errors, uint256 &bumped_txid)
Commit the bumpfee transaction.
std::optional< OutputType > m_change_type
Override the default change type if set, ignored if destChange is set.
RPCHelpMan walletcreatefundedpsbt()
int64_t CAmount
Amount in satoshis (Can be negative)
const UniValue & find_value(std::string_view key) const
A transaction with a bunch of additional info that only the owner cares about.
std::string oneline_description
Should be empty unless it is supposed to override the auto-generated summary line.
Special type that is a STR with only hex chars.
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.
Indicates that the wallet needs an external signer.
std::string HelpExampleRpc(const std::string &methodname, const std::string &args)
RPCHelpMan fundrawtransaction()
static constexpr uint32_t MAX_BIP125_RBF_SEQUENCE
UniValue JSONRPCError(int code, const std::string &message)
RPCHelpMan signrawtransactionwithwallet()
Special string with only hex chars.
const std::string CURRENCY_ATOM
static CAmount AmountFromValue(const UniValue &value)
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet)
Parse a scriptPubKey for the destination.
RPCHelpMan walletprocesspsbt()
std::map< CScriptID, CScript > scripts
An input of a transaction.
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...
bool DecodeBase64PSBT(PartiallySignedTransaction &psbt, const std::string &base64_tx, std::string &error)
Decode a base64ed PSBT into a PartiallySignedTransaction.
static int64_t GetTransactionInputWeight(const CTxIn &txin)
Double ended buffer combining vector and stream-like interfaces.
bool exists(const std::string &key) const
std::optional< OutputType > ParseOutputType(const std::string &type)
UniValue JSONRPCPSBTError(PSBTError err)
An encapsulated public key.
std::string ToString(const FeeEstimateMode &fee_estimate_mode=FeeEstimateMode::BTC_KVB) const
std::map< CKeyID, CPubKey > pubkeys
Special type where the user must set the keys e.g. to define multiple addresses; as opposed to e...
bool IsDust(const CRecipient &recipient, const CFeeRate &dustRelayFee)
bool fOverrideFeeRate
Override automatic min/max checks on fee, m_feerate must be set if true.
std::string ToString() const
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.
const std::string CURRENCY_UNIT
void SetInputWeight(const COutPoint &outpoint, int64_t weight)
Set an input's weight.
std::set< int > InterpretSubtractFeeFromOutputInstructions(const UniValue &sffo_instructions, const std::vector< std::string > &destinations)
A CWallet maintains a set of transactions and balances, and provides the ability to create new transa...
General application defined errors.
CMutableTransaction ConstructTransaction(const UniValue &inputs_in, const UniValue &outputs_in, const UniValue &locktime, std::optional< bool > rbf)
Create a transaction from univalue parameters.
std::string DefaultHint
Hint for default value.
An output of a transaction.
An outpoint - a combination of a transaction hash and an index n into its vout.
std::string HelpExampleCli(const std::string &methodname, const std::string &args)
std::vector< CTxOut > vout
const std::string HELP_REQUIRING_PASSPHRASE
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...
bool m_avoid_address_reuse
Forbids inclusion of dirty (previously used) addresses.
CFeeRate GetMinimumFeeRate(const CWallet &wallet, const CCoinControl &coin_control, FeeCalculation *feeCalc)
Estimate the minimum fee rate considering user set parameters and the required fee.
FlatSigningProvider & Merge(FlatSigningProvider &&b) LIFETIMEBOUND
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
static CTransactionRef MakeTransactionRef(Tx &&txIn)
static void PreventOutdatedOptions(const UniValue &options)
bool SignTransaction(CWallet &wallet, CMutableTransaction &mtx)
Sign the new transaction,.
Optional argument for which the default value is omitted from help text for one of two reasons: ...
static constexpr int32_t MAX_STANDARD_TX_WEIGHT
The maximum weight for transactions we're willing to relay/mine.
std::string EncodeHexTx(const CTransaction &tx)
int m_min_depth
Minimum chain depth value for coin availability.
Special string to represent a floating point amount.
void pushKV(std::string key, UniValue val)
Serialized script, used inside transaction inputs and outputs.
static transaction_identifier FromUint256(const uint256 &id)
CreatedTransactionResult FundTransaction(CWallet &wallet, const CMutableTransaction &tx, const std::vector< CRecipient > &recipients, const UniValue &options, CCoinControl &coinControl, bool override_min_fee)
uint256 ParseHashV(const UniValue &v, std::string_view name)
Utilities: convert hex-encoded Values (throws error if not hex).
bool m_include_unsafe_inputs
If false, only safe inputs will be used.
Not enough funds in wallet or account.
FeeEstimateMode m_fee_mode
Fee estimation mode to control arguments to estimateSmartFee.
const UniValue & get_obj() const
std::variant< CNoDestination, PubKeyDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, PayToAnchor, WitnessUnknown > CTxDestination
A txout script categorized into standard templates.
Special type representing a floating point amount (can be either NUM or STR)
bool DecodeHexTx(CMutableTransaction &tx, const std::string &hex_tx, bool try_no_witness=false, bool try_witness=true)
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.
std::string GetHex() const
bool m_allow_other_inputs
If true, the selection process can add extra unselected inputs from the wallet while requires all sel...
std::string HexStr(const Span< const uint8_t > s)
Convert a span of bytes to a lower-case hexadecimal string.
UniValue ValueFromAmount(const CAmount amount)
Fee rate in satoshis per kilovirtualbyte: CAmount / kvB.
const UniValue NullUniValue
bool GetAvoidReuseFlag(const CWallet &wallet, const UniValue ¶m)
void EnsureWalletIsUnlocked(const CWallet &wallet)
bilingual_str ErrorString(const Result< T > &result)
A reference to a CScript: the Hash160 of its serialization.
std::vector< std::pair< CTxDestination, CAmount > > ParseOutputs(const UniValue &outputs)
Parse normalized outputs into destination, amount tuples.
std::string EncodeDestination(const CTxDestination &dest)
Standard JSON-RPC 2.0 errors.
A mutable version of CTransaction.
The basic transaction that is broadcasted on the network and contained in blocks. ...
static void InterpretFeeEstimationInstructions(const UniValue &conf_target, const UniValue &estimate_mode, const UniValue &fee_rate, UniValue &options)
int m_max_depth
Maximum chain depth value for coin availability.
CTxDestination DecodeDestination(const std::string &str, std::string &error_msg, std::vector< int > *error_locations)
is a home for public enum and struct type definitions that are used by internally by node code...
static UniValue FinishTransaction(const std::shared_ptr< CWallet > pwallet, const UniValue &options, const CMutableTransaction &rawTx)
std::optional< bool > m_signal_bip125_rbf
Override the wallet's m_signal_rbf if set.
A UTXO under consideration for use in funding a new transaction.
std::optional< CFeeRate > m_feerate
Override the wallet's m_pay_tx_fee if set.
std::string FeeModesDetail(std::string default_info)
Wrapper for UniValue::VType, which includes typeAny: Used to denote don't care type.
std::shared_ptr< CWallet > GetWalletForJSONRPCRequest(const JSONRPCRequest &request)
Figures out what wallet, if any, to use for a JSONRPCRequest.
UniValue SendMoney(CWallet &wallet, const CCoinControl &coin_control, std::vector< CRecipient > &recipients, mapValue_t map_value, bool verbose)
Error parsing or validating structure in raw format.
static constexpr TransactionSerParams TX_WITH_WITNESS
V Cat(V v1, V &&v2)
Concatenate two vectors, moving elements.