From d89d20ab0e5ec5d7fac1c24b7b174179836cb8a3 Mon Sep 17 00:00:00 2001 From: jeffro256 Date: Wed, 30 Apr 2025 22:32:57 -0500 Subject: [PATCH] carrot_impl: make_carrot_transaction_proposals_wallet2_sweep_all --- src/wallet/tx_builder.cpp | 89 +++++++++++++++++++++++++++++++++++++++ src/wallet/tx_builder.h | 24 ++++++++++- 2 files changed, 112 insertions(+), 1 deletion(-) diff --git a/src/wallet/tx_builder.cpp b/src/wallet/tx_builder.cpp index 4bcd7d9b4..7e5b384d5 100644 --- a/src/wallet/tx_builder.cpp +++ b/src/wallet/tx_builder.cpp @@ -512,5 +512,94 @@ std::vector make_carrot_transaction_proposa top_block_index, w.get_account().get_keys()); } +//------------------------------------------------------------------------------------------------------------------- +std::vector make_carrot_transaction_proposals_wallet2_sweep_all( + const wallet2::transfer_container &transfers, + const std::unordered_map &subaddress_map, + const cryptonote::account_public_address &address, + const bool is_subaddress, + const size_t n_dests, + const rct::xmr_amount fee_per_weight, + const std::vector &extra, + const std::uint32_t subaddr_account, + const std::set &subaddr_indices, + const std::uint64_t top_block_index, + const cryptonote::account_keys &acc_keys) +{ + const std::unordered_map unburned_transfers_by_key_image = + collect_non_burned_transfers_by_key_image(transfers); + + std::vector input_key_images; + input_key_images.reserve(transfers.size()); + for (std::size_t transfer_idx = 0; transfer_idx < transfers.size(); ++transfer_idx) + { + const wallet2::transfer_details &td = transfers.at(transfer_idx); + + if (!is_transfer_usable_for_input_selection(td, + subaddr_account, + subaddr_indices, + MONEY_SUPPLY, + 0, + top_block_index)) + continue; + + const auto ki_it = unburned_transfers_by_key_image.find(td.m_key_image); + if (ki_it == unburned_transfers_by_key_image.cend()) + continue; + else if (ki_it->second != transfer_idx) + continue; + + input_key_images.push_back(td.m_key_image); + } + + CHECK_AND_ASSERT_THROW_MES(!input_key_images.empty(), __func__ << ": no usable transfers to sweep"); + + return make_carrot_transaction_proposals_wallet2_sweep( + transfers, + subaddress_map, + input_key_images, + address, + is_subaddress, + n_dests, + fee_per_weight, + extra, + top_block_index, + acc_keys); +} +//------------------------------------------------------------------------------------------------------------------- +std::vector make_carrot_transaction_proposals_wallet2_sweep_all( + wallet2 &w, + const cryptonote::account_public_address &address, + const bool is_subaddress, + const size_t n_dests, + const std::uint32_t priority, + const std::vector &extra, + const std::uint32_t subaddr_account, + const std::set &subaddr_indices) +{ + wallet2::transfer_container transfers; + w.get_transfers(transfers); + + const rct::xmr_amount fee_per_weight = w.get_base_fee(priority); + + const std::uint64_t current_chain_height = w.get_blockchain_current_height(); + CHECK_AND_ASSERT_THROW_MES(current_chain_height > 0, + "make_carrot_transaction_proposals_wallet2_sweep: chain height is 0, there is no top block"); + const std::uint64_t top_block_index = current_chain_height - 1; + + return make_carrot_transaction_proposals_wallet2_sweep_all( + transfers, + w.get_subaddress_map_ref(), + address, + is_subaddress, + n_dests, + fee_per_weight, + extra, + subaddr_account, + subaddr_indices, + top_block_index, + w.get_account().get_keys()); +} +//------------------------------------------------------------------------------------------------------------------- } //namespace wallet } //namespace tools diff --git a/src/wallet/tx_builder.h b/src/wallet/tx_builder.h index eb5d918cc..333482759 100644 --- a/src/wallet/tx_builder.h +++ b/src/wallet/tx_builder.h @@ -91,7 +91,7 @@ std::vector make_carrot_transaction_proposa const std::vector& extra, const std::uint64_t top_block_index, const cryptonote::account_keys &acc_keys); - std::vector make_carrot_transaction_proposals_wallet2_sweep( +std::vector make_carrot_transaction_proposals_wallet2_sweep( wallet2 &w, const std::vector &input_key_images, const cryptonote::account_public_address &address, @@ -99,5 +99,27 @@ std::vector make_carrot_transaction_proposa const size_t n_dests, const std::uint32_t priority, const std::vector &extra); + +std::vector make_carrot_transaction_proposals_wallet2_sweep_all( + const wallet2::transfer_container &transfers, + const std::unordered_map &subaddress_map, + const cryptonote::account_public_address &address, + const bool is_subaddress, + const size_t n_dests, + const rct::xmr_amount fee_per_weight, + const std::vector &extra, + const std::uint32_t subaddr_account, + const std::set &subaddr_indices, + const std::uint64_t top_block_index, + const cryptonote::account_keys &acc_keys); +std::vector make_carrot_transaction_proposals_wallet2_sweep_all( + wallet2 &w, + const cryptonote::account_public_address &address, + const bool is_subaddress, + const size_t n_dests, + const std::uint32_t priority, + const std::vector &extra, + const std::uint32_t subaddr_account, + const std::set &subaddr_indices); } //namespace wallet } //namespace tools