diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index 33bd6efa..c45055e1 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -309,7 +309,7 @@ simple_wallet::simple_wallet() m_cmd_binder.set_handler("tor_enable", boost::bind(&simple_wallet::tor_enable, this, ph::_1), "Enable relaying transactions over TOR network(enabled by default)"); m_cmd_binder.set_handler("tor_disable", boost::bind(&simple_wallet::tor_disable, this, ph::_1), "Enable relaying transactions over TOR network(enabled by default)"); m_cmd_binder.set_handler("deploy_new_asset", boost::bind(&simple_wallet::deploy_new_asset, this, ph::_1), "deploy_new_asset - Deploys new asset in the network, with current wallet as a maintainer"); - m_cmd_binder.set_handler("emmit_asset", boost::bind(&simple_wallet::emmit_asset, this, ph::_1), "emmit_asset - Emmit more coins for the asset, possible only if current wallet is a maintainer for the asset"); + m_cmd_binder.set_handler("emit_asset", boost::bind(&simple_wallet::emit_asset, this, ph::_1), "emit_asset - Emmit more coins for the asset, possible only if current wallet is a maintainer for the asset"); m_cmd_binder.set_handler("burn_asset", boost::bind(&simple_wallet::burn_asset, this, ph::_1), "burn_asset - Burn coins for the asset, possible only if current wallet is a maintainer for the asset AND possess given amount of coins to burn"); m_cmd_binder.set_handler("update_asset", boost::bind(&simple_wallet::update_asset, this, ph::_1), "update_asset - Update asset descriptor's metadata, possible only if current wallet is a maintainer for the asset"); @@ -1912,7 +1912,7 @@ bool simple_wallet::deploy_new_asset(const std::vector &args) return true; } //---------------------------------------------------------------------------------------------------- -bool simple_wallet::emmit_asset(const std::vector &args) +bool simple_wallet::emit_asset(const std::vector &args) { SIMPLE_WALLET_BEGIN_TRY_ENTRY(); diff --git a/src/simplewallet/simplewallet.h b/src/simplewallet/simplewallet.h index 817bb210..82400621 100644 --- a/src/simplewallet/simplewallet.h +++ b/src/simplewallet/simplewallet.h @@ -91,7 +91,7 @@ namespace currency bool deploy_new_asset(const std::vector &args); bool add_custom_asset_id(const std::vector &args); bool remove_custom_asset_id(const std::vector &args); - bool emmit_asset(const std::vector &args); + bool emit_asset(const std::vector &args); bool burn_asset(const std::vector &args); bool update_asset(const std::vector &args); diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 4de65dd0..7fcf76d5 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -6608,16 +6608,24 @@ void wallet2::prepare_tx_destinations(const assets_selection_context& needed_mon const std::vector& dsts, std::vector& final_destinations) { + + /* + let's account all processes assets, so if there are some destinations + that haven't been present in needed_money_map we can add it to final destinations + (could be in ionic swaps for example) + */ + std::unordered_set processed_assets; for (auto& el: needed_money_map) { prepare_tx_destinations(el.second.needed_amount, el.second.found_amount, destination_split_strategy_id, dust_policy, dsts, final_destinations, el.first); + processed_assets.insert(el.first); } if (is_in_hardfork_zone(ZANO_HARDFORK_04_ZARCANUM)) { // special case for asset minting destinations for (auto& dst : dsts) - if (dst.asset_id == currency::null_pkey) + if (dst.asset_id == currency::null_pkey || processed_assets.count(dst.asset_id) == 0) final_destinations.emplace_back(dst.amount, dst.addr, dst.asset_id); //exclude destinations that supposed to be burned (for ASSET_DESCRIPTOR_OPERATION_PUBLIC_BURN) diff --git a/tests/core_tests/ionic_swap_tests.cpp b/tests/core_tests/ionic_swap_tests.cpp index 5bbe8bf6..5c5f9e19 100644 --- a/tests/core_tests/ionic_swap_tests.cpp +++ b/tests/core_tests/ionic_swap_tests.cpp @@ -137,33 +137,35 @@ bool ionic_swap_basic_test::c1(currency::core& c, size_t ev_index, const std::ve const uint64_t assets_to_exchange = 10 * COIN; const uint64_t native_tokens_to_exchange = COIN/2; - //alice_wlt want to trade with bob_wlt, to exchange 10.0 TCT to 1.0 ZANO - view::ionic_swap_proposal_info proposal_details = AUTO_VAL_INIT(proposal_details); - proposal_details.expiration_time = alice_wlt->get_core_runtime_config().get_core_time() + 10 * 60; - proposal_details.fee_paid_by_a = TESTS_DEFAULT_FEE; - proposal_details.mixins = 10; - proposal_details.to_bob.push_back(view::asset_funds{ asset_id , assets_to_exchange }); - proposal_details.to_alice.push_back(view::asset_funds{ currency::native_coin_asset_id , native_tokens_to_exchange }); - - tools::wallet_public::ionic_swap_proposal proposal = AUTO_VAL_INIT(proposal); - alice_wlt->create_ionic_swap_proposal(proposal_details, bob_wlt->get_account().get_public_address(), proposal); - - view::ionic_swap_proposal_info proposal_decoded_info = AUTO_VAL_INIT(proposal_decoded_info); - bob_wlt->get_ionic_swap_proposal_info(proposal, proposal_decoded_info); - - //Validate proposal - if (proposal_decoded_info.to_bob != proposal_details.to_bob - || proposal_decoded_info.to_alice != proposal_details.to_alice - || proposal_decoded_info.fee_paid_by_a != proposal_details.fee_paid_by_a - || proposal_decoded_info.mixins != proposal_details.mixins - ) { - CHECK_AND_ASSERT_MES(false, false, "proposal actual and proposals decoded mismatch"); - } + //alice_wlt want to trade with bob_wlt, to exchange 10.0 TCT to 1.0 ZANO + view::ionic_swap_proposal_info proposal_details = AUTO_VAL_INIT(proposal_details); + proposal_details.expiration_time = alice_wlt->get_core_runtime_config().get_core_time() + 10 * 60; + proposal_details.fee_paid_by_a = TESTS_DEFAULT_FEE; + proposal_details.mixins = 10; + proposal_details.to_bob.push_back(view::asset_funds{ asset_id , assets_to_exchange }); + proposal_details.to_alice.push_back(view::asset_funds{ currency::native_coin_asset_id , native_tokens_to_exchange }); - currency::transaction res_tx2 = AUTO_VAL_INIT(res_tx2); - r = bob_wlt->accept_ionic_swap_proposal(proposal, res_tx2); - CHECK_AND_ASSERT_MES(r, false, "Failed to accept ionic proposal"); + tools::wallet_public::ionic_swap_proposal proposal = AUTO_VAL_INIT(proposal); + alice_wlt->create_ionic_swap_proposal(proposal_details, bob_wlt->get_account().get_public_address(), proposal); + + view::ionic_swap_proposal_info proposal_decoded_info = AUTO_VAL_INIT(proposal_decoded_info); + bob_wlt->get_ionic_swap_proposal_info(proposal, proposal_decoded_info); + + //Validate proposal + if (proposal_decoded_info.to_bob != proposal_details.to_bob + || proposal_decoded_info.to_alice != proposal_details.to_alice + || proposal_decoded_info.fee_paid_by_a != proposal_details.fee_paid_by_a + || proposal_decoded_info.mixins != proposal_details.mixins + ) + { + CHECK_AND_ASSERT_MES(false, false, "proposal actual and proposals decoded mismatch"); + } + currency::transaction res_tx2 = AUTO_VAL_INIT(res_tx2); + r = bob_wlt->accept_ionic_swap_proposal(proposal, res_tx2); + CHECK_AND_ASSERT_MES(r, false, "Failed to accept ionic proposal"); + + } r = mine_next_pow_blocks_in_playtime(miner_wlt->get_account().get_public_address(), c, CURRENCY_MINED_MONEY_UNLOCK_WINDOW); CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_blocks_in_playtime failed"); @@ -193,6 +195,70 @@ bool ionic_swap_basic_test::c1(currency::core& c, size_t ev_index, const std::ve CHECK_AND_ASSERT_MES(it_native->second.total == COIN - native_tokens_to_exchange, false, "Failed to find needed asset in result balances"); CHECK_AND_ASSERT_MES(it_asset->second.total == AMOUNT_ASSETS_TO_TRANSFER_MULTIASSETS_BASIC + assets_to_exchange, false, "Failed to find needed asset in result balances"); + { + //now alice_wlt want to trade with bob_wlt, to send 1.0 ZANO and get 10.0 TCT in exchange + view::ionic_swap_proposal_info proposal_details = AUTO_VAL_INIT(proposal_details); + proposal_details.expiration_time = alice_wlt->get_core_runtime_config().get_core_time() + 10 * 60; + proposal_details.fee_paid_by_a = TESTS_DEFAULT_FEE; + proposal_details.mixins = 10; + proposal_details.to_bob.push_back(view::asset_funds{ currency::native_coin_asset_id , native_tokens_to_exchange }); + proposal_details.to_alice.push_back(view::asset_funds{ asset_id , assets_to_exchange }); + + tools::wallet_public::ionic_swap_proposal proposal = AUTO_VAL_INIT(proposal); + alice_wlt->create_ionic_swap_proposal(proposal_details, bob_wlt->get_account().get_public_address(), proposal); + + view::ionic_swap_proposal_info proposal_decoded_info = AUTO_VAL_INIT(proposal_decoded_info); + bob_wlt->get_ionic_swap_proposal_info(proposal, proposal_decoded_info); + + //Validate proposal + if (proposal_decoded_info.to_bob != proposal_details.to_bob + || proposal_decoded_info.to_alice != proposal_details.to_alice + || proposal_decoded_info.fee_paid_by_a != proposal_details.fee_paid_by_a + || proposal_decoded_info.mixins != proposal_details.mixins + ) + { + CHECK_AND_ASSERT_MES(false, false, "proposal actual and proposals decoded mismatch"); + } + currency::transaction res_tx2 = AUTO_VAL_INIT(res_tx2); + r = bob_wlt->accept_ionic_swap_proposal(proposal, res_tx2); + CHECK_AND_ASSERT_MES(r, false, "Failed to accept ionic proposal"); + + } + + r = mine_next_pow_blocks_in_playtime(miner_wlt->get_account().get_public_address(), c, CURRENCY_MINED_MONEY_UNLOCK_WINDOW); + CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_blocks_in_playtime failed"); + + bob_wlt->refresh(); + alice_wlt->refresh(); + + + balances.clear(); + alice_wlt->balance(balances, mined); + + it_asset = balances.find(asset_id); + it_native = balances.find(currency::native_coin_asset_id); + + CHECK_AND_ASSERT_MES(it_asset != balances.end(), false, "Failed to find needed asset in result balances"); + CHECK_AND_ASSERT_MES(it_native->second.total == native_tokens_to_exchange + COIN - TESTS_DEFAULT_FEE * 2 - native_tokens_to_exchange, false, "Failed to find needed asset in result balances"); + CHECK_AND_ASSERT_MES(it_asset->second.total == AMOUNT_ASSETS_TO_TRANSFER_MULTIASSETS_BASIC - assets_to_exchange + assets_to_exchange, false, "Failed to find needed asset in result balances"); + + + balances.clear(); + bob_wlt->balance(balances, mined); + it_asset = balances.find(asset_id); + it_native = balances.find(currency::native_coin_asset_id); + + + CHECK_AND_ASSERT_MES(it_asset != balances.end(), false, "Failed to find needed asset in result balances"); + CHECK_AND_ASSERT_MES(it_native->second.total == COIN - native_tokens_to_exchange + native_tokens_to_exchange, false, "Failed to find needed asset in result balances"); + CHECK_AND_ASSERT_MES(it_asset->second.total == AMOUNT_ASSETS_TO_TRANSFER_MULTIASSETS_BASIC + assets_to_exchange - assets_to_exchange, false, "Failed to find needed asset in result balances"); + + + + + + + //TODO: // add fee paid by bob scenario