MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / SendMoney

Function SendMoney

src/wallet/rpc/spend.cpp:171–202  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

169}
170
171UniValue SendMoney(CWallet& wallet, const CCoinControl &coin_control, std::vector<CRecipient> &recipients, mapValue_t map_value, bool verbose)
172{
173 EnsureWalletIsUnlocked(wallet);
174
175 // This function is only used by sendtoaddress and sendmany.
176 // This should always try to sign, if we don't have (all) private keys, don't
177 // try to do anything here.
178 if (wallet.IsWalletFlagSet(WALLET_FLAG_EXTERNAL_SIGNER)) {
179 throw JSONRPCError(RPC_WALLET_ERROR, "Error: sendtoaddress and sendmany are not supported for wallets with external signers; use send instead");
180 }
181 if (wallet.IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)) {
182 throw JSONRPCError(RPC_WALLET_ERROR, "Error: Private keys are disabled for this wallet");
183 }
184
185 // Shuffle recipient list
186 std::shuffle(recipients.begin(), recipients.end(), FastRandomContext());
187
188 // Send
189 auto res = CreateTransaction(wallet, recipients, /*change_pos=*/std::nullopt, coin_control, true);
190 if (!res) {
191 throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, util::ErrorString(res).original);
192 }
193 const CTransactionRef& tx = res->tx;
194 wallet.CommitTransaction(tx, std::move(map_value), /*orderForm=*/{});
195 if (verbose) {
196 UniValue entry(UniValue::VOBJ);
197 entry.pushKV("txid", tx->GetHash().GetHex());
198 entry.pushKV("fee_reason", StringForFeeReason(res->fee_calc.reason));
199 return entry;
200 }
201 return tx->GetHash().GetHex();
202}
203
204
205/**

Callers 2

sendtoaddressFunction · 0.85
sendmanyFunction · 0.85

Calls 13

EnsureWalletIsUnlockedFunction · 0.85
JSONRPCErrorFunction · 0.85
CreateTransactionFunction · 0.85
ErrorStringFunction · 0.85
StringForFeeReasonFunction · 0.85
IsWalletFlagSetMethod · 0.80
CommitTransactionMethod · 0.80
pushKVMethod · 0.80
FastRandomContextClass · 0.50
beginMethod · 0.45
endMethod · 0.45
GetHexMethod · 0.45

Tested by

no test coverage detected