Skip to content

Commit

Permalink
fix v2.2.0+ tendermint activation format
Browse files Browse the repository at this point in the history
  • Loading branch information
smk762 committed Nov 12, 2024
1 parent 2e02d6f commit 48b385f
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <vector>

#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"

Expand All @@ -20,9 +21,8 @@ namespace atomic_dex::kdf
std::string ticker;
std::optional<int> required_confirmations;
};

std::string ticker;
std::vector<std::string> rpc_urls;
std::vector<node> nodes;
bool tx_history{true};
std::vector<tendermint_token_request_t> tokens_params;
std::optional<int> required_confirmations;
Expand Down
8 changes: 1 addition & 7 deletions src/core/atomicdex/config/coins.cfg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,13 +217,7 @@ namespace atomic_dex
}
if (j.contains("rpc_urls"))
{
auto rpc_urls_obj = j.at("rpc_urls").get<std::vector<node>>();
std::vector<std::string> 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<std::vector<node>>();
}
if (j.contains("allow_slp_unsafe_conf"))
{
Expand Down
2 changes: 1 addition & 1 deletion src/core/atomicdex/config/coins.cfg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ namespace atomic_dex
std::optional<std::set<CoinType>> other_types;
std::optional<electrum_servers> electrum_urls;
std::optional<nodes> urls;
std::optional<url_list> rpc_urls;
std::optional<nodes> rpc_urls;
std::optional<light_wallet_d_servers> z_urls;
std::optional<eth_family_url_list> eth_family_urls;
std::optional<bchd_url_list> bchd_urls;
Expand Down
61 changes: 25 additions & 36 deletions src/core/atomicdex/services/kdf/kdf.service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
#include <unordered_set>
#include <iostream>
#include <sstream>
#include <map>
#include <string>
#include <vector>


#include <boost/thread/thread.hpp>
#include <boost/algorithm/string/replace.hpp>
Expand Down Expand Up @@ -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;

Expand All @@ -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)
{
Expand Down Expand Up @@ -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);
}
}
}

Expand Down Expand Up @@ -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<std::string, std::vector<coin_config_t>>
kdf_service::groupByParentCoin(const std::vector<coin_config_t>& coins) {
std::map<std::string, std::vector<coin_config_t>> 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)
Expand Down Expand Up @@ -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<std::string>{});
rpc.request.nodes = parent_ticker_info.rpc_urls.value_or(std::vector<node>{});
for (const auto& coin_config : coins)
{
if (coin_config.ticker == parent_ticker_info.ticker)
Expand Down
3 changes: 2 additions & 1 deletion src/core/atomicdex/services/kdf/kdf.service.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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<std::string, t_coins> groupByParentCoin(const t_coins& coins);

//! Cancel zhtlc activation
void enable_z_coin_cancel(const std::int8_t task_id);
Expand Down

0 comments on commit 48b385f

Please sign in to comment.