| 169 | } |
| 170 | |
| 171 | UniValue 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 | /** |
no test coverage detected