From f47e9977a5e6f5a8942a804526a375b6accb22d6 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Fri, 17 Mar 2023 19:55:32 +0100 Subject: [PATCH] Implemented generate_ionic_swap_proposal command in simplewallet --- src/simplewallet/simplewallet.cpp | 56 +++++++++++++++++++++++++++ src/simplewallet/simplewallet.h | 5 +++ tests/core_tests/ionic_swap_tests.cpp | 2 - 3 files changed, 61 insertions(+), 2 deletions(-) diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index b93bafbb..d9160494 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -229,6 +229,10 @@ simple_wallet::simple_wallet() m_cmd_binder.set_handler("add_custom_asset_id", boost::bind(&simple_wallet::add_custom_asset_id, this, _1), "Approve asset id to be recognized in the wallet and returned in balances"); m_cmd_binder.set_handler("remove_custom_asset_id", boost::bind(&simple_wallet::remove_custom_asset_id, this, _1), "Cancel previously made approval for asset id"); + m_cmd_binder.set_handler("generate_ionic_swap_proposal", boost::bind(&simple_wallet::generate_ionic_swap_proposal, this, _1), "generate_ionic_swap_proposal - Generates ionic_swap proposal with given conditions"); + m_cmd_binder.set_handler("get_ionic_swap_proposal_info", boost::bind(&simple_wallet::get_ionic_swap_proposal_info, this, _1), "get_ionic_swap_proposal_info - Extracts and display information from ionic_swap proposal raw data"); + m_cmd_binder.set_handler("accept_ionic_swap_proposal", boost::bind(&simple_wallet::accept_ionic_swap_proposal, this, _1), "accept_ionic_swap_proposal - Accept ionic_swap proposal and generates exchange transaction"); + } //---------------------------------------------------------------------------------------------------- simple_wallet::~simple_wallet() @@ -1849,6 +1853,58 @@ bool simple_wallet::add_custom_asset_id(const std::vector &args) } return true; } +//---------------------------------------------------------------------------------------------------- +bool simple_wallet::generate_ionic_swap_proposal(const std::vector &args) +{ + + if (args.size() != 2) + { + fail_msg_writer() << "invalid arguments count: " << args.size() << ", expected 1"; + } + + view::ionic_swap_proposal_info proposal = AUTO_VAL_INIT(proposal); + bool r = epee::serialization::load_t_from_json_file(proposal, args[0]); + if (!r) + { + fail_msg_writer() << "Failed to load json file with asset specification: " << args[0]; + } + currency::account_public_address destination_addr = AUTO_VAL_INIT(destination_addr); + currency::payment_id_t integrated_payment_id; + if (!m_wallet->get_transfer_address(args[1], destination_addr, integrated_payment_id)) + { + fail_msg_writer() << "wrong address: " << args[1]; + return true; + } + if (integrated_payment_id.size()) + { + fail_msg_writer() << "Integrated addresses not supported yet"; + return true; + } + + transaction tx_template = AUTO_VAL_INIT(tx_template); + bool r = m_wallet->create_ionic_swap_proposal(proposal, destination_addr, tx_template); + if (!r) + { + fail_msg_writer() << "Failed to create ionic_swap proposal"; + return true; + } + else + { + success_msg_writer() << "Generated proposal: " << ENDL << epee::string_tools::buff_to_hex_nodelimer(t_serializable_object_to_blob(tx_template)); + } + return true; +} +//---------------------------------------------------------------------------------------------------- +bool simple_wallet::get_ionic_swap_proposal_info(const std::vector &args) +{ + +} +//---------------------------------------------------------------------------------------------------- +bool simple_wallet::accept_ionic_swap_proposal(const std::vector &args) +{ + +} + //---------------------------------------------------------------------------------------------------- bool simple_wallet::remove_custom_asset_id(const std::vector &args) { diff --git a/src/simplewallet/simplewallet.h b/src/simplewallet/simplewallet.h index 823fee05..7ac24682 100644 --- a/src/simplewallet/simplewallet.h +++ b/src/simplewallet/simplewallet.h @@ -92,6 +92,11 @@ namespace currency bool add_custom_asset_id(const std::vector &args); bool remove_custom_asset_id(const std::vector &args); + //---------------------------------------------------------------------------------------------------- + bool generate_ionic_swap_proposal(const std::vector &args); + bool get_ionic_swap_proposal_info(const std::vector &args); + bool accept_ionic_swap_proposal(const std::vector &args); + bool validate_wrap_status(uint64_t amount); bool get_alias_from_daemon(const std::string& alias_name, currency::extra_alias_entry_base& ai); diff --git a/tests/core_tests/ionic_swap_tests.cpp b/tests/core_tests/ionic_swap_tests.cpp index f2838e52..c0206de7 100644 --- a/tests/core_tests/ionic_swap_tests.cpp +++ b/tests/core_tests/ionic_swap_tests.cpp @@ -168,8 +168,6 @@ bool zarcanum_basic_test::c1(currency::core& c, size_t ev_index, const std::vect 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 == mined_balance - 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"); - - return true; }