diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 964d2e76..0f73afad 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -2353,7 +2353,7 @@ bool wallet2::sweep_bare_unspent_outputs(const currency::account_public_address& ftp.pevents_dispatcher = &m_debug_events_dispatcher; ftp.tx_version = this->get_current_tx_version(); - if (!prepare_tx_sources(decoys_count, ftp.sources, group.tids)) + if (!prepare_tx_sources(decoys_count, /*use_all_decoys_if_found_less_than_required*/ true, ftp.sources, group.tids)) { on_tx_sent(batch_index, transaction{}, 0, 0, false, "sources for tx couldn't be prepared"); LOG_PRINT_L0("prepare_tx_sources failed, batch_index = " << batch_index); @@ -6322,7 +6322,12 @@ void wallet2::prefetch_global_indicies_if_needed(const std::vector& se }*/ } //---------------------------------------------------------------------------------------------------- -bool wallet2::prepare_tx_sources(size_t fake_outputs_count_, std::vector& sources, const std::vector& selected_indicies) +bool wallet2::prepare_tx_sources(size_t fake_outputs_count, std::vector& sources, const std::vector& selected_indicies) +{ + return prepare_tx_sources(fake_outputs_count, false, sources, selected_indicies); +} +//---------------------------------------------------------------------------------------------------- +bool wallet2::prepare_tx_sources(size_t fake_outputs_count_, bool use_all_decoys_if_found_less_than_required, std::vector& sources, const std::vector& selected_indicies) { typedef COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::out_entry out_entry; typedef currency::tx_source_entry::output_entry tx_output_entry; @@ -6400,14 +6405,15 @@ bool wallet2::prepare_tx_sources(size_t fake_outputs_count_, std::vector scanty_outs; THROW_IF_FALSE_WALLET_EX(daemon_resp.outs.size() == req.amounts.size(), error::not_enough_outs_to_mix, scanty_outs, fake_outputs_count); - for(size_t i = 0; i != daemon_resp.outs.size(); i++) + + if (!use_all_decoys_if_found_less_than_required) { - if (req.amounts[i].amount != 0 && daemon_resp.outs[i].outs.size() != req.amounts[i].global_offsets.size()) - { - scanty_outs.push_back(daemon_resp.outs[i]); - } + // make sure we have received the requested number of decoys + for(size_t i = 0; i != daemon_resp.outs.size(); i++) + if (req.amounts[i].amount != 0 && daemon_resp.outs[i].outs.size() != req.amounts[i].global_offsets.size()) + scanty_outs.push_back(daemon_resp.outs[i]); + THROW_IF_FALSE_WALLET_EX(scanty_outs.empty(), error::not_enough_outs_to_mix, scanty_outs, fake_outputs_count); } - THROW_IF_FALSE_WALLET_EX(scanty_outs.empty(), error::not_enough_outs_to_mix, scanty_outs, fake_outputs_count); } } diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index f3b42762..e220959c 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -792,6 +792,7 @@ private: bool build_escrow_proposal(bc_services::contract_private_details& ecrow_details, uint64_t fee, uint64_t unlock_time, currency::tx_service_attachment& att, std::vector& selected_indicies); bool prepare_tx_sources(assets_selection_context& needed_money_map, size_t fake_outputs_count, uint64_t dust_threshold, std::vector& sources, std::vector& selected_indicies); bool prepare_tx_sources(size_t fake_outputs_count, std::vector& sources, const std::vector& selected_indicies); + bool prepare_tx_sources(size_t fake_outputs_count, bool use_all_decoys_if_found_less_than_required, std::vector& sources, const std::vector& selected_indicies); bool prepare_tx_sources(crypto::hash multisig_id, std::vector& sources, uint64_t& found_money); bool prepare_tx_sources_htlc(crypto::hash htlc_tx_id, const std::string& origin, std::vector& sources, uint64_t& found_money); bool prepare_tx_sources_for_defragmentation_tx(std::vector& sources, std::vector& selected_indicies, uint64_t& found_money);