From 48b385f476538d07297f704e78f9f9e92f8f5ddb Mon Sep 17 00:00:00 2001 From: smk762 Date: Tue, 12 Nov 2024 20:30:21 +0800 Subject: [PATCH] fix v2.2.0+ tendermint activation format --- .../rpc2.enable_tendermint_with_assets.cpp | 2 +- .../rpc2.enable_tendermint_with_assets.hpp | 4 +- src/core/atomicdex/config/coins.cfg.cpp | 8 +-- src/core/atomicdex/config/coins.cfg.hpp | 2 +- .../atomicdex/services/kdf/kdf.service.cpp | 61 ++++++++----------- .../atomicdex/services/kdf/kdf.service.hpp | 3 +- 6 files changed, 32 insertions(+), 48 deletions(-) diff --git a/src/core/atomicdex/api/kdf/rpc_v2/rpc2.enable_tendermint_with_assets.cpp b/src/core/atomicdex/api/kdf/rpc_v2/rpc2.enable_tendermint_with_assets.cpp index 95c578ad9..280d6b757 100644 --- a/src/core/atomicdex/api/kdf/rpc_v2/rpc2.enable_tendermint_with_assets.cpp +++ b/src/core/atomicdex/api/kdf/rpc_v2/rpc2.enable_tendermint_with_assets.cpp @@ -7,7 +7,7 @@ namespace atomic_dex::kdf void to_json(nlohmann::json& j, const enable_tendermint_with_assets_request_rpc& in) { j["ticker"] = in.ticker; - j["rpc_urls"] = in.rpc_urls; + j["nodes"] = in.nodes; j["tx_history"] = in.tx_history; j["tokens_params"] = in.tokens_params; if (in.required_confirmations.has_value()) diff --git a/src/core/atomicdex/api/kdf/rpc_v2/rpc2.enable_tendermint_with_assets.hpp b/src/core/atomicdex/api/kdf/rpc_v2/rpc2.enable_tendermint_with_assets.hpp index 05325f95a..714f1f810 100644 --- a/src/core/atomicdex/api/kdf/rpc_v2/rpc2.enable_tendermint_with_assets.hpp +++ b/src/core/atomicdex/api/kdf/rpc_v2/rpc2.enable_tendermint_with_assets.hpp @@ -3,6 +3,7 @@ #include #include "atomicdex/api/kdf/rpc.hpp" +#include "atomicdex/config/enable.cfg.hpp" #include "atomicdex/api/kdf/balance_infos.hpp" #include "atomicdex/config/electrum.cfg.hpp" @@ -20,9 +21,8 @@ namespace atomic_dex::kdf std::string ticker; std::optional required_confirmations; }; - std::string ticker; - std::vector rpc_urls; + std::vector nodes; bool tx_history{true}; std::vector tokens_params; std::optional required_confirmations; diff --git a/src/core/atomicdex/config/coins.cfg.cpp b/src/core/atomicdex/config/coins.cfg.cpp index 9f0d9c806..c5c0ba503 100644 --- a/src/core/atomicdex/config/coins.cfg.cpp +++ b/src/core/atomicdex/config/coins.cfg.cpp @@ -217,13 +217,7 @@ namespace atomic_dex } if (j.contains("rpc_urls")) { - auto rpc_urls_obj = j.at("rpc_urls").get>(); - std::vector rpc_urls_list; - cfg.rpc_urls = rpc_urls_list; - for (const auto& url : rpc_urls_obj) - { - cfg.rpc_urls->push_back(url.url); - } + cfg.rpc_urls = j.at("rpc_urls").get>(); } if (j.contains("allow_slp_unsafe_conf")) { diff --git a/src/core/atomicdex/config/coins.cfg.hpp b/src/core/atomicdex/config/coins.cfg.hpp index 319a68db7..f4fa5bcd5 100644 --- a/src/core/atomicdex/config/coins.cfg.hpp +++ b/src/core/atomicdex/config/coins.cfg.hpp @@ -91,7 +91,7 @@ namespace atomic_dex std::optional> other_types; std::optional electrum_urls; std::optional urls; - std::optional rpc_urls; + std::optional rpc_urls; std::optional z_urls; std::optional eth_family_urls; std::optional bchd_urls; diff --git a/src/core/atomicdex/services/kdf/kdf.service.cpp b/src/core/atomicdex/services/kdf/kdf.service.cpp index 1d3b2ca15..69bef4137 100644 --- a/src/core/atomicdex/services/kdf/kdf.service.cpp +++ b/src/core/atomicdex/services/kdf/kdf.service.cpp @@ -18,6 +18,10 @@ #include #include #include +#include +#include +#include + #include #include @@ -543,9 +547,7 @@ namespace atomic_dex t_coins slp_coins; t_coins slp_testnet_coins; t_coins zhtlc_coins; - t_coins osmosis_coins; - t_coins iris_coins; - t_coins cosmos_coins; + t_coins tendermint_coins; t_coins bep20_coins; t_coins bep20_testnet_coins; @@ -571,23 +573,7 @@ namespace atomic_dex } else if (coin_cfg.coin_type == CoinType::TENDERMINT || coin_cfg.coin_type == CoinType::TENDERMINTTOKEN) { - if (coin_cfg.parent_coin == "ATOM") - { - cosmos_coins.push_back(coin_cfg); - } - else if (coin_cfg.parent_coin == "IRIS") - { - iris_coins.push_back(coin_cfg); - } - else if (coin_cfg.parent_coin == "OSMO") - { - osmosis_coins.push_back(coin_cfg); - } - else - { - SPDLOG_WARN("Unexpected Tendermint ticker: {}", coin_cfg.ticker); - SPDLOG_WARN("Parent coin: {}", coin_cfg.parent_coin); - } + tendermint_coins.push_back(coin_cfg); } else if (coin_cfg.coin_type == CoinType::ZHTLC) { @@ -643,20 +629,12 @@ namespace atomic_dex SPDLOG_INFO(">>>>>>>>>>>>>>>>>>>>>>>>>>> Enabling {} zhtlc_coins <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<", zhtlc_coins.size()); enable_zhtlc(zhtlc_coins); } - if (iris_coins.size() > 0) + if (tendermint_coins.size() > 0) { - SPDLOG_INFO(">>>>>>>>>>>>>>>>>>>>>>>>>>> Enabling {} iris_coins <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<", iris_coins.size()); - enable_tendermint_coins(iris_coins, "IRIS"); - } - if (cosmos_coins.size() > 0) - { - SPDLOG_INFO(">>>>>>>>>>>>>>>>>>>>>>>>>>> Enabling {} cosmos_coins <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<", cosmos_coins.size()); - enable_tendermint_coins(cosmos_coins, "ATOM"); - } - if (osmosis_coins.size() > 0) - { - SPDLOG_INFO(">>>>>>>>>>>>>>>>>>>>>>>>>>> Enabling {} osmosis_coins <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<", osmosis_coins.size()); - enable_tendermint_coins(osmosis_coins, "OSMO"); + SPDLOG_INFO(">>>>>>>>>>>>>>>>>>>>>>>>>>> Enabling {} tendermint_coins <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<", tendermint_coins.size()); + for (const auto& [parent_coin, coins_vector] : groupByParentCoin(tendermint_coins)) { + enable_tendermint_coins(coins_vector, parent_coin); + } } } @@ -1014,9 +992,20 @@ namespace atomic_dex SPDLOG_DEBUG("kdf_service::enable_erc20_coins done for {}", parent_ticker); } - void kdf_service::enable_tendermint_coin(coin_config_t coin_config, std::string parent_ticker) + + std::map> + kdf_service::groupByParentCoin(const std::vector& coins) { + std::map> groupedCoins; + for (const auto& coin : coins) { + groupedCoins[coin.parent_coin].push_back(coin); + } + return groupedCoins; + } + + + void kdf_service::enable_tendermint_coin(coin_config_t coin_config) { - enable_tendermint_coins(t_coins{std::move(coin_config)}, parent_ticker); + enable_tendermint_coins(t_coins{std::move(coin_config)}, coin_config.parent_coin); } void kdf_service::enable_tendermint_coins(const t_coins& coins, const std::string parent_ticker) @@ -1098,7 +1087,7 @@ namespace atomic_dex kdf::enable_tendermint_with_assets_rpc rpc; rpc.request.ticker = parent_ticker_info.ticker; - rpc.request.rpc_urls = parent_ticker_info.rpc_urls.value_or(std::vector{}); + rpc.request.nodes = parent_ticker_info.rpc_urls.value_or(std::vector{}); for (const auto& coin_config : coins) { if (coin_config.ticker == parent_ticker_info.ticker) diff --git a/src/core/atomicdex/services/kdf/kdf.service.hpp b/src/core/atomicdex/services/kdf/kdf.service.hpp index 131d54226..6bcca6cd5 100644 --- a/src/core/atomicdex/services/kdf/kdf.service.hpp +++ b/src/core/atomicdex/services/kdf/kdf.service.hpp @@ -185,7 +185,7 @@ namespace atomic_dex void enable_slp_testnet_coins(const t_coins& coins); void enable_erc20_coin(coin_config_t coin_config, std::string parent_ticker); void enable_erc20_coins(const t_coins& coins, const std::string parent_ticker); - void enable_tendermint_coin(coin_config_t coin_config, std::string parent_ticker); + void enable_tendermint_coin(coin_config_t coin_config); void enable_tendermint_coins(const t_coins& coins, const std::string parent_ticker); void enable_zhtlc(const t_coins& coins); @@ -207,6 +207,7 @@ namespace atomic_dex [[nodiscard]] bool is_zhtlc_coin_ready(const std::string coin) const; [[nodiscard]] nlohmann::json get_zhtlc_status(const std::string coin) const; + std::map groupByParentCoin(const t_coins& coins); //! Cancel zhtlc activation void enable_z_coin_cancel(const std::int8_t task_id);