| 66 | } |
| 67 | |
| 68 | UniValue SendMoney(CWallet& wallet, const CCoinControl &coin_control, std::vector<CRecipient> &recipients, mapValue_t map_value, bool verbose, bool ignore_blind_fail) |
| 69 | { |
| 70 | EnsureWalletIsUnlocked(wallet); |
| 71 | |
| 72 | // This function is only used by sendtoaddress and sendmany. |
| 73 | // This should always try to sign, if we don't have private keys, don't try to do anything here. |
| 74 | if (wallet.IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)) { |
| 75 | throw JSONRPCError(RPC_WALLET_ERROR, "Error: Private keys are disabled for this wallet"); |
| 76 | } |
| 77 | |
| 78 | // Shuffle recipient list |
| 79 | std::shuffle(recipients.begin(), recipients.end(), FastRandomContext()); |
| 80 | |
| 81 | // Send |
| 82 | CAmount nFeeRequired = 0; |
| 83 | int nChangePosRet = -1; |
| 84 | bilingual_str error; |
| 85 | CTransactionRef tx; |
| 86 | FeeCalculation fee_calc_out; |
| 87 | auto blind_details = g_con_elementsmode ? std::make_unique<BlindDetails>() : nullptr; |
| 88 | if (blind_details) blind_details->ignore_blind_failure = ignore_blind_fail; |
| 89 | const bool fCreated = CreateTransaction(wallet, recipients, tx, nFeeRequired, nChangePosRet, error, coin_control, fee_calc_out, true, blind_details.get()); |
| 90 | if (!fCreated) { |
| 91 | throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, error.original); |
| 92 | } |
| 93 | wallet.CommitTransaction(tx, std::move(map_value), {} /* orderForm */, blind_details.get()); |
| 94 | if (verbose) { |
| 95 | UniValue entry(UniValue::VOBJ); |
| 96 | entry.pushKV("txid", tx->GetHash().GetHex()); |
| 97 | entry.pushKV("fee_reason", StringForFeeReason(fee_calc_out.reason)); |
| 98 | return entry; |
| 99 | } |
| 100 | return tx->GetHash().GetHex(); |
| 101 | } |
| 102 | |
| 103 | |
| 104 | /** |
no test coverage detected