diff --git a/src/wallet/tx_builder.cpp b/src/wallet/tx_builder.cpp index b11b35b..56f63ea 100644 --- a/src/wallet/tx_builder.cpp +++ b/src/wallet/tx_builder.cpp @@ -33,6 +33,10 @@ #include "carrot_core/config.h" #include "carrot_core/device_ram_borrowed.h" #include "carrot_core/enote_utils.h" +#include "carrot_core/exceptions.h" +#include "carrot_core/output_set_finalization.h" +#include "carrot_core/scan.h" +#include "carrot_impl/address_device_ram_borrowed.h" #include "carrot_impl/tx_builder_outputs.h" #include "carrot_impl/format_utils.h" #include "carrot_impl/input_selection.h" @@ -295,8 +299,7 @@ std::vector make_carrot_transaction_proposa const rct::xmr_amount ignore_above, const rct::xmr_amount ignore_below, wallet2::unique_index_container subtract_fee_from_outputs, - const std::uint64_t top_block_index, - const cryptonote::account_keys &acc_keys) + const std::uint64_t top_block_index) { wallet2::transfer_container unused_transfers(transfers); @@ -408,8 +411,7 @@ std::vector make_carrot_transaction_proposa w.ignore_outputs_above(), w.ignore_outputs_below(), subtract_fee_from_outputs, - top_block_index, - w.get_account().get_keys()); + top_block_index); } //------------------------------------------------------------------------------------------------------------------- std::vector make_carrot_transaction_proposals_wallet2_sweep( @@ -420,9 +422,8 @@ std::vector make_carrot_transaction_proposa const bool is_subaddress, const size_t n_dests, const rct::xmr_amount fee_per_weight, - const std::vector& extra, - const std::uint64_t top_block_index, - const cryptonote::account_keys &acc_keys) + const std::vector &extra, + const std::uint64_t top_block_index) { const size_t n_inputs = input_key_images.size(); CHECK_AND_ASSERT_THROW_MES(n_inputs, @@ -567,8 +568,7 @@ std::vector make_carrot_transaction_proposa n_dests, fee_per_weight, extra, - top_block_index, - w.get_account().get_keys()); + top_block_index); } //------------------------------------------------------------------------------------------------------------------- std::vector make_carrot_transaction_proposals_wallet2_sweep_all( @@ -582,8 +582,7 @@ std::vector make_carrot_transaction_proposa 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::uint64_t top_block_index) { const std::unordered_map unburned_transfers_by_key_image = collect_non_burned_transfers_by_key_image(transfers); @@ -622,8 +621,7 @@ std::vector make_carrot_transaction_proposa n_dests, fee_per_weight, extra, - top_block_index, - acc_keys); + top_block_index); } //------------------------------------------------------------------------------------------------------------------- std::vector make_carrot_transaction_proposals_wallet2_sweep_all( @@ -658,19 +656,22 @@ std::vector make_carrot_transaction_proposa extra, subaddr_account, subaddr_indices, - top_block_index, - w.get_account().get_keys()); + top_block_index); } //------------------------------------------------------------------------------------------------------------------- wallet2::pending_tx make_pending_carrot_tx(const carrot::CarrotTransactionProposalV1 &tx_proposal, const wallet2::transfer_container &transfers, - const cryptonote::account_keys &acc_keys) + const crypto::secret_key &k_view, + hw::device &hwdev) { const std::size_t n_inputs = tx_proposal.key_images_sorted.size(); const std::size_t n_outputs = tx_proposal.normal_payment_proposals.size() + tx_proposal.selfsend_payment_proposals.size(); const bool shared_ephemeral_pubkey = n_outputs == 2; + CARROT_CHECK_AND_THROW(n_inputs >= 1, carrot::too_few_inputs, "carrot tx proposal missing inputs"); + CARROT_CHECK_AND_THROW(n_outputs >= 2, carrot::too_few_outputs, "carrot tx proposal missing outputs"); + const crypto::key_image &tx_first_key_image = tx_proposal.key_images_sorted.at(0); // collect non-burned transfers @@ -694,7 +695,7 @@ wallet2::pending_tx make_pending_carrot_tx(const carrot::CarrotTransactionPropos } //! @TODO: HW device - carrot::view_incoming_key_ram_borrowed_device k_view_dev(acc_keys.m_view_secret_key); + carrot::view_incoming_key_ram_borrowed_device k_view_dev(k_view); // get order of payment proposals std::vector output_enote_proposals; diff --git a/src/wallet/tx_builder.h b/src/wallet/tx_builder.h index ca97759..c897376 100644 --- a/src/wallet/tx_builder.h +++ b/src/wallet/tx_builder.h @@ -67,8 +67,7 @@ std::vector make_carrot_transaction_proposa const rct::xmr_amount ignore_above, const rct::xmr_amount ignore_below, wallet2::unique_index_container subtract_fee_from_outputs, - const std::uint64_t top_block_index, - const cryptonote::account_keys &acc_keys); + const std::uint64_t top_block_index); std::vector make_carrot_transaction_proposals_wallet2_transfer( wallet2 &w, const std::vector &dsts, @@ -86,9 +85,8 @@ std::vector make_carrot_transaction_proposa const bool is_subaddress, const size_t n_dests, const rct::xmr_amount fee_per_weight, - const std::vector& extra, - const std::uint64_t top_block_index, - const cryptonote::account_keys &acc_keys); + const std::vector &extra, + const std::uint64_t top_block_index); std::vector make_carrot_transaction_proposals_wallet2_sweep( wallet2 &w, const std::vector &input_key_images, @@ -109,8 +107,7 @@ std::vector make_carrot_transaction_proposa 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::uint64_t top_block_index); std::vector make_carrot_transaction_proposals_wallet2_sweep_all( wallet2 &w, const rct::xmr_amount only_below, @@ -123,6 +120,7 @@ std::vector make_carrot_transaction_proposa const std::set &subaddr_indices); wallet2::pending_tx make_pending_carrot_tx(const carrot::CarrotTransactionProposalV1 &tx_proposal, const wallet2::transfer_container &transfers, - const cryptonote::account_keys &acc_keys); + const crypto::secret_key &k_view, + hw::device &hwdev); } //namespace wallet } //namespace tools diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index 3fe729e..877280c 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -2756,6 +2756,8 @@ namespace boost tools::wallet2::tx_construction_data pre_carrot_construction_data; a & pre_carrot_construction_data; x.construction_data = pre_carrot_construction_data; + x.subaddr_account = pre_carrot_construction_data.subaddr_account; + x.subaddr_indices = pre_carrot_construction_data.subaddr_indices; } else // ver >= 4 { diff --git a/tests/unit_tests/wallet_tx_builder.cpp b/tests/unit_tests/wallet_tx_builder.cpp index 9281fa9..33e1e74 100644 --- a/tests/unit_tests/wallet_tx_builder.cpp +++ b/tests/unit_tests/wallet_tx_builder.cpp @@ -171,8 +171,7 @@ TEST(wallet_tx_builder, make_carrot_transaction_proposals_wallet2_transfer_1) /*ignore_above=*/MONEY_SUPPLY, /*ignore_below=*/0, {}, - top_block_index, - alice.get_keys()); + top_block_index); ASSERT_EQ(1, tx_proposals.size()); const carrot::CarrotTransactionProposalV1 tx_proposal = tx_proposals.at(0); @@ -235,8 +234,7 @@ TEST(wallet_tx_builder, make_carrot_transaction_proposals_wallet2_transfer_2) /*ignore_above=*/MONEY_SUPPLY, /*ignore_below=*/0, {}, - top_block_index, - alice.legacy_acb.get_keys()); + top_block_index); ASSERT_EQ(1, tx_proposals.size()); const carrot::CarrotTransactionProposalV1 &tx_proposal = tx_proposals.at(0); @@ -301,8 +299,7 @@ TEST(wallet_tx_builder, make_carrot_transaction_proposals_wallet2_sweep_1) /*n_dests=*/1, /*fee_per_weight=*/1, /*extra=*/{}, - transfers.front().m_block_height + CRYPTONOTE_DEFAULT_TX_SPENDABLE_AGE, - alice.get_keys()); + transfers.front().m_block_height + CRYPTONOTE_DEFAULT_TX_SPENDABLE_AGE); ASSERT_EQ(1, tx_proposals.size()); const carrot::CarrotTransactionProposalV1 &tx_proposal = tx_proposals.at(0); @@ -336,8 +333,7 @@ TEST(wallet_tx_builder, make_carrot_transaction_proposals_wallet2_sweep_2) /*n_dests=*/FCMP_PLUS_PLUS_MAX_OUTPUTS - 1, /*fee_per_weight=*/1, /*extra=*/{}, - transfers.front().m_block_height + CRYPTONOTE_DEFAULT_TX_SPENDABLE_AGE, - alice.get_keys()); + transfers.front().m_block_height + CRYPTONOTE_DEFAULT_TX_SPENDABLE_AGE); ASSERT_EQ(1, tx_proposals.size()); const carrot::CarrotTransactionProposalV1 &tx_proposal = tx_proposals.at(0); @@ -379,8 +375,7 @@ TEST(wallet_tx_builder, make_carrot_transaction_proposals_wallet2_sweep_3) /*n_dests=*/FCMP_PLUS_PLUS_MAX_OUTPUTS, /*fee_per_weight=*/1, /*extra=*/{}, - transfers.front().m_block_height + CRYPTONOTE_DEFAULT_TX_SPENDABLE_AGE, - alice.get_keys()); + transfers.front().m_block_height + CRYPTONOTE_DEFAULT_TX_SPENDABLE_AGE); ASSERT_EQ(1, tx_proposals.size()); const carrot::CarrotTransactionProposalV1 &tx_proposal = tx_proposals.at(0); @@ -455,8 +450,7 @@ TEST(wallet_tx_builder, make_carrot_transaction_proposals_wallet2_sweep_4) /*n_dests=*/n_dests, /*fee_per_weight=*/1, /*extra=*/{}, - top_block_index, - alice.get_keys()); + top_block_index); ASSERT_EQ(4, tx_proposals.size()); std::set actual_seen_kis; @@ -538,8 +532,7 @@ TEST(wallet_tx_builder, make_carrot_transaction_proposals_wallet2_sweep_5) /*n_dests=*/n_dests, /*fee_per_weight=*/1, /*extra=*/{}, - top_block_index, - alice.get_keys()); + top_block_index); ASSERT_EQ(8, tx_proposals.size()); std::set actual_seen_kis; @@ -621,8 +614,7 @@ TEST(wallet_tx_builder, make_carrot_transaction_proposals_wallet2_sweep_6) /*n_dests=*/n_dests, /*fee_per_weight=*/1, /*extra=*/{}, - top_block_index, - alice.get_keys()); + top_block_index); ASSERT_EQ(1, tx_proposals.size()); const carrot::CarrotTransactionProposalV1 &tx_proposal = tx_proposals.at(0); @@ -718,23 +710,22 @@ TEST(wallet_tx_builder, make_carrot_transaction_proposals_wallet2_sweep_6) // ASSERT_EQ(2, alice.m_transfers.size()); // ASSERT_EQ(amount0 + amount1, alice.balance_all(true)); // really, we care about unlocked_balance_all() for sending, but that call uses RPC -// // 6. -// LOG_PRINT_L2("Alice feels pity on Bob and proposes to send his broke ass some dough"); -// const rct::xmr_amount out_amount = rct::randXmrAmount(amount0 + amount1); -// const std::vector tx_proposals = -// tools::wallet::make_carrot_transaction_proposals_wallet2_transfer( // stupidly long function name ;( -// alice.m_transfers, -// alice.m_subaddresses, -// {cryptonote::tx_destination_entry(out_amount, bob_main_addr, false)}, -// /*fee_per_weight=*/1, -// /*extra=*/{}, -// /*subaddr_account=*/0, -// /*subaddr_indices=*/{}, -// /*ignore_above=*/std::numeric_limits::max(), -// /*ignore_below=*/0, -// {}, -// /*top_block_index=*/bc.height()-1, -// alice_keys); + // 6. + LOG_PRINT_L2("Alice feels pity on Bob and proposes to send his broke ass some dough"); + const rct::xmr_amount out_amount = rct::randXmrAmount(amount0 + amount1); + const std::vector tx_proposals = + tools::wallet::make_carrot_transaction_proposals_wallet2_transfer( // stupidly long function name ;( + alice.m_transfers, + alice.m_subaddresses, + {cryptonote::tx_destination_entry(out_amount, bob_main_addr, false)}, + /*fee_per_weight=*/1, + /*extra=*/{}, + /*subaddr_account=*/0, + /*subaddr_indices=*/{}, + /*ignore_above=*/std::numeric_limits::max(), + /*ignore_below=*/0, + {}, + /*top_block_index=*/bc.height()-1); // ASSERT_EQ(1, tx_proposals.size()); // const carrot::CarrotTransactionProposalV1 tx_proposal = tx_proposals.at(0);