diff --git a/CMakeLists.txt b/CMakeLists.txt index 689a88efa..36679e302 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -78,7 +78,7 @@ FetchContent_Declare( ) FetchContent_Declare(jl777-coins - URL https://github.com/KomodoPlatform/coins/archive/master.zip) + URL https://github.com/KomodoPlatform/coins/archive/add/tendermint-coins.zip) #FetchContent_Declare(adex-generics-coins # URL https://github.com/KomodoPlatform/komodo-wallet-desktop/archive/main.zip) diff --git a/atomic_defi_design/Dex/Components/AddressField.qml b/atomic_defi_design/Dex/Components/AddressField.qml index aa972a1a9..d3c31e846 100644 --- a/atomic_defi_design/Dex/Components/AddressField.qml +++ b/atomic_defi_design/Dex/Components/AddressField.qml @@ -1,6 +1,6 @@ import QtQuick 2.15 -DefaultTextField { +DexTextField { readonly property int max_length: 50 validator: RegExpValidator { diff --git a/atomic_defi_design/Dex/Components/AmountField.qml b/atomic_defi_design/Dex/Components/AmountField.qml index 1d280a8bc..ed2ce8d9f 100644 --- a/atomic_defi_design/Dex/Components/AmountField.qml +++ b/atomic_defi_design/Dex/Components/AmountField.qml @@ -1,6 +1,6 @@ import QtQuick 2.15 -DefaultTextField +DexTextField { validator: RegExpValidator { diff --git a/atomic_defi_design/Dex/Components/AmountFloatField.qml b/atomic_defi_design/Dex/Components/AmountFloatField.qml index 06af631e1..17bc43ef5 100644 --- a/atomic_defi_design/Dex/Components/AmountFloatField.qml +++ b/atomic_defi_design/Dex/Components/AmountFloatField.qml @@ -1,6 +1,6 @@ import QtQuick 2.15 -DefaultTextField +DexTextField { validator: RegExpValidator { diff --git a/atomic_defi_design/Dex/Components/AmountIntField.qml b/atomic_defi_design/Dex/Components/AmountIntField.qml index 30dce4be6..6a78de3d8 100644 --- a/atomic_defi_design/Dex/Components/AmountIntField.qml +++ b/atomic_defi_design/Dex/Components/AmountIntField.qml @@ -1,6 +1,6 @@ import QtQuick 2.15 -DefaultTextField +DexTextField { property bool allowFloat: false validator: RegExpValidator diff --git a/atomic_defi_design/Dex/Components/DefaultTextField.qml b/atomic_defi_design/Dex/Components/DefaultTextField.qml deleted file mode 100644 index a0c57e16c..000000000 --- a/atomic_defi_design/Dex/Components/DefaultTextField.qml +++ /dev/null @@ -1,8 +0,0 @@ -import QtQuick 2.15 -import QtQuick.Controls 2.15 -import "../Constants" -import App 1.0 - -DexTextField { - -} diff --git a/atomic_defi_design/Dex/Components/DexSweetComboBox.qml b/atomic_defi_design/Dex/Components/DexSweetComboBox.qml index cc47e64e6..cacef269b 100644 --- a/atomic_defi_design/Dex/Components/DexSweetComboBox.qml +++ b/atomic_defi_design/Dex/Components/DexSweetComboBox.qml @@ -85,7 +85,7 @@ ComboBox { anchors.rightMargin: 5 - DefaultTextField + DexTextField { id: input_coin_filter placeholderText: qsTr("Search") diff --git a/atomic_defi_design/Dex/Components/SearchField.qml b/atomic_defi_design/Dex/Components/SearchField.qml index 40bcae12d..34353082e 100644 --- a/atomic_defi_design/Dex/Components/SearchField.qml +++ b/atomic_defi_design/Dex/Components/SearchField.qml @@ -37,7 +37,7 @@ Rectangle } } - DefaultTextField + DexTextField { id: _textField diff --git a/atomic_defi_design/Dex/Components/TextFieldWithTitle.qml b/atomic_defi_design/Dex/Components/TextFieldWithTitle.qml index e0bd8aae3..4d74cd8f3 100644 --- a/atomic_defi_design/Dex/Components/TextFieldWithTitle.qml +++ b/atomic_defi_design/Dex/Components/TextFieldWithTitle.qml @@ -51,7 +51,7 @@ ColumnLayout } } - DefaultTextField + DexTextField { id: input_field diff --git a/atomic_defi_design/Dex/Components/qmldir b/atomic_defi_design/Dex/Components/qmldir index dab879424..248066ada 100644 --- a/atomic_defi_design/Dex/Components/qmldir +++ b/atomic_defi_design/Dex/Components/qmldir @@ -16,7 +16,7 @@ Rectangle 1.0 DefaultRectangle.qml ScrollView 1.0 DefaultScrollView.qml SearchField 1.0 SearchField.qml Text 1.0 DefaultText.qml -TextField 1.0 DefaultTextField.qml +TextField 1.0 DexTextField.qml TextFieldWithTitle 1.0 TextFieldWithTitle.qml ToolTip 1.0 DefaultTooltip.qml UserIcon 1.0 UserIcon.qml diff --git a/atomic_defi_design/Dex/Screens/Startup/WalletsView.qml b/atomic_defi_design/Dex/Screens/Startup/WalletsView.qml index 32b0c8592..e0b0fff90 100644 --- a/atomic_defi_design/Dex/Screens/Startup/WalletsView.qml +++ b/atomic_defi_design/Dex/Screens/Startup/WalletsView.qml @@ -79,7 +79,7 @@ SetupPage visible: wallet_count > 0 // Searchbar - DefaultTextField + DexTextField { id: wallet_search visible: wallet_count > 5 diff --git a/atomic_defi_design/Dex/Settings/RecoverSeedModal.qml b/atomic_defi_design/Dex/Settings/RecoverSeedModal.qml index 39253a778..967b29227 100644 --- a/atomic_defi_design/Dex/Settings/RecoverSeedModal.qml +++ b/atomic_defi_design/Dex/Settings/RecoverSeedModal.qml @@ -262,7 +262,7 @@ MultipageModal HorizontalLine { Layout.fillWidth: true } - DefaultTextField + DexTextField { visible: coinsList.visible enabled: coinsList.enabled diff --git a/atomic_defi_design/Dex/Wallet/SendModal.qml b/atomic_defi_design/Dex/Wallet/SendModal.qml index aedb0f768..0b19e98ee 100644 --- a/atomic_defi_design/Dex/Wallet/SendModal.qml +++ b/atomic_defi_design/Dex/Wallet/SendModal.qml @@ -47,7 +47,7 @@ MultipageModal function getCryptoAmount() { return _preparePage.cryptoSendMode ? input_amount.text : equivalentAmount.value } - function prepareSendCoin(address, amount, with_fees, fees_amount, is_special_token, gas_limit, gas_price, memo="") { + function prepareSendCoin(address, amount, with_fees, fees_amount, is_special_token, gas_limit, gas_price, memo="", ibc_source_channel="") { let max = parseFloat(current_ticker_infos.balance) === parseFloat(amount) // Save for later check async_param_max = max @@ -60,7 +60,7 @@ MultipageModal gas_price, gas_limit: gas_limit === "" ? 0 : parseInt(gas_limit) } - api_wallet_page.send(address, amount, max, with_fees, fees_info, memo) + api_wallet_page.send(address, amount, max, with_fees, fees_info, memo, ibc_source_channel) } function sendCoin() { @@ -263,7 +263,7 @@ MultipageModal color: input_address.background.color radius: input_address.background.radius - DefaultTextField + DexTextField { id: input_address @@ -567,7 +567,7 @@ MultipageModal color: input_memo.background.color radius: input_memo.background.radius - DefaultTextField + DexTextField { id: input_memo @@ -579,6 +579,31 @@ MultipageModal } } + // IBC channel ID + DefaultRectangle + { + visible: (["TENDERMINT", "TENDERMINTTOKEN"].includes(current_ticker_infos.type)) + enabled: !root.is_send_busy + + Layout.preferredWidth: 500 + Layout.preferredHeight: 44 + Layout.alignment: Qt.AlignHCenter + + color: input_memo.background.color + radius: input_memo.background.radius + + DexTextField + { + id: input_ibc_channel_id + + width: 470 + height: 44 + placeholderText: qsTr("Enter IBC channel ID") + forceFocus: true + font: DexTypo.body3 + } + } + ColumnLayout { visible: General.getCustomFeeType(current_ticker_infos) @@ -786,7 +811,8 @@ MultipageModal General.isSpecialToken(current_ticker_infos), input_custom_fees_gas.text, input_custom_fees_gas_price.text, - input_memo.text + input_memo.text, + input_ibc_channel_id.text ) } } diff --git a/atomic_defi_design/Dex/Wallet/SendModalContactList.qml b/atomic_defi_design/Dex/Wallet/SendModalContactList.qml index 9e9bbd58a..ac9ace2a7 100644 --- a/atomic_defi_design/Dex/Wallet/SendModalContactList.qml +++ b/atomic_defi_design/Dex/Wallet/SendModalContactList.qml @@ -26,7 +26,7 @@ MultipageModal titleText: qsTr("Select a contact with an %1 address").arg(ticker) // Searchbar - DefaultTextField + DexTextField { Layout.alignment: Qt.AlignHCenter Layout.fillWidth: true diff --git a/src/core/atomicdex/api/kdf/balance_info.cpp b/src/core/atomicdex/api/kdf/balance_info.cpp deleted file mode 100644 index d300f6a1b..000000000 --- a/src/core/atomicdex/api/kdf/balance_info.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include - -#include "atomicdex/api/kdf/balance_info.hpp" - -namespace atomic_dex::kdf -{ - void from_json(const nlohmann::json& j, balance_info& in) - { - j.at("spendable").get_to(in.spendable); - j.at("unspendable").get_to(in.unspendable); - } -} \ No newline at end of file diff --git a/src/core/atomicdex/api/kdf/balance_info.hpp b/src/core/atomicdex/api/kdf/balance_info.hpp deleted file mode 100644 index 94f896197..000000000 --- a/src/core/atomicdex/api/kdf/balance_info.hpp +++ /dev/null @@ -1,16 +0,0 @@ -#pragma once - -#include - -#include //> nlohmann::json - -namespace atomic_dex::kdf -{ - struct balance_info - { - std::string spendable; - std::string unspendable; - }; - - void from_json(const nlohmann::json& j, balance_info& in); -} \ No newline at end of file diff --git a/src/core/atomicdex/api/kdf/kdf.client.cpp b/src/core/atomicdex/api/kdf/kdf.client.cpp index 0d01945d3..29c112487 100644 --- a/src/core/atomicdex/api/kdf/kdf.client.cpp +++ b/src/core/atomicdex/api/kdf/kdf.client.cpp @@ -71,6 +71,7 @@ namespace json_req.insert(json_req.end(), json_data); } request.set_body(json_req.dump()); + // SPDLOG_DEBUG("request: {}", json_req.dump()); return request; } @@ -78,17 +79,18 @@ namespace Rpc process_rpc_answer(const web::http::http_response& answer) { std::string body = TO_STD_STR(answer.extract_string(true).get()); - // SPDLOG_DEBUG("body: {}", body); + // SPDLOG_INFO("body: {}", body); nlohmann::json json_answer; Rpc rpc; try { json_answer = nlohmann::json::parse(body); - // SPDLOG_DEBUG("rpc answer: {}", json_answer.dump(4)); + // SPDLOG_DEBUG("json_answer: {}", json_answer.dump(4)); } catch (const nlohmann::json::parse_error& error) { SPDLOG_ERROR("rpc answer error: {}", error.what()); + // SPDLOG_DEBUG("body: {}", body); } if (Rpc::is_v2) @@ -103,7 +105,6 @@ namespace SPDLOG_DEBUG("rpc2 answer: error"); rpc.error = json_answer.get(); rpc.raw_result = json_answer.dump(); - SPDLOG_DEBUG("rpc.raw_result: {}", rpc.raw_result); } } else diff --git a/src/core/atomicdex/api/kdf/rpc_v2/rpc2.enable_bch_with_tokens_rpc.hpp b/src/core/atomicdex/api/kdf/rpc_v2/rpc2.enable_bch_with_tokens_rpc.hpp index 038902918..658bc96f7 100644 --- a/src/core/atomicdex/api/kdf/rpc_v2/rpc2.enable_bch_with_tokens_rpc.hpp +++ b/src/core/atomicdex/api/kdf/rpc_v2/rpc2.enable_bch_with_tokens_rpc.hpp @@ -20,7 +20,7 @@ #include "atomicdex/config/electrum.cfg.hpp" #include "atomicdex/api/kdf/address_format.hpp" -#include "atomicdex/api/kdf/balance_info.hpp" +#include "atomicdex/api/kdf/balance_infos.hpp" #include "atomicdex/api/kdf/rpc.hpp" #include "atomicdex/api/kdf/utxo_merge_params.hpp" @@ -65,13 +65,13 @@ namespace atomic_dex::kdf { derivation_method_t derivation_method; std::string pubkey; - balance_info balances; + balance_infos balances; }; struct slp_address_infos_t { derivation_method_t derivation_method; std::string pubkey; - std::unordered_map balances; + std::unordered_map balances; }; std::size_t current_block; diff --git a/src/core/atomicdex/api/kdf/rpc_v2/rpc2.enable_erc20.cpp b/src/core/atomicdex/api/kdf/rpc_v2/rpc2.enable_erc20.cpp index b36673023..0587f0305 100644 --- a/src/core/atomicdex/api/kdf/rpc_v2/rpc2.enable_erc20.cpp +++ b/src/core/atomicdex/api/kdf/rpc_v2/rpc2.enable_erc20.cpp @@ -21,6 +21,6 @@ namespace atomic_dex::kdf { j.at("platform_coin").get_to(in.platform_coin); j.at("required_confirmations").get_to(in.required_confirmations); - j.at("balances").get_to>(in.balances); + j.at("balances").get_to>(in.balances); } } \ No newline at end of file diff --git a/src/core/atomicdex/api/kdf/rpc_v2/rpc2.enable_erc20.hpp b/src/core/atomicdex/api/kdf/rpc_v2/rpc2.enable_erc20.hpp index ae2d22a80..c99b07fe7 100644 --- a/src/core/atomicdex/api/kdf/rpc_v2/rpc2.enable_erc20.hpp +++ b/src/core/atomicdex/api/kdf/rpc_v2/rpc2.enable_erc20.hpp @@ -21,7 +21,7 @@ #include //> nlohmann::json #include "atomicdex/api/kdf/rpc.hpp" -#include "atomicdex/api/kdf/balance_info.hpp" +#include "atomicdex/api/kdf/balance_infos.hpp" namespace atomic_dex::kdf { @@ -40,7 +40,7 @@ namespace atomic_dex::kdf { std::string platform_coin; int required_confirmations; - std::unordered_map balances; + std::unordered_map balances; }; using expected_error_type = rpc_basic_error_type; diff --git a/src/core/atomicdex/api/kdf/rpc_v2/rpc2.enable_eth_with_tokens.hpp b/src/core/atomicdex/api/kdf/rpc_v2/rpc2.enable_eth_with_tokens.hpp index 3b40f1748..7e378aac2 100644 --- a/src/core/atomicdex/api/kdf/rpc_v2/rpc2.enable_eth_with_tokens.hpp +++ b/src/core/atomicdex/api/kdf/rpc_v2/rpc2.enable_eth_with_tokens.hpp @@ -19,7 +19,7 @@ #include #include "atomicdex/api/kdf/rpc.hpp" -#include "atomicdex/api/kdf/balance_info.hpp" +#include "atomicdex/api/kdf/balance_infos.hpp" #include "atomicdex/config/enable.cfg.hpp" #include "atomicdex/constants/qt.coins.enums.hpp" @@ -60,13 +60,13 @@ namespace atomic_dex::kdf { derivation_method_t derivation_method; std::string pubkey; - balance_info balances; + balance_infos balances; }; struct erc20_address_infos_t { derivation_method_t derivation_method; std::string pubkey; - std::unordered_map balances; + std::unordered_map balances; }; std::size_t current_block; diff --git a/src/core/atomicdex/api/kdf/rpc_v2/rpc2.enable_slp_rpc.cpp b/src/core/atomicdex/api/kdf/rpc_v2/rpc2.enable_slp_rpc.cpp index 9906fae3c..0422df437 100644 --- a/src/core/atomicdex/api/kdf/rpc_v2/rpc2.enable_slp_rpc.cpp +++ b/src/core/atomicdex/api/kdf/rpc_v2/rpc2.enable_slp_rpc.cpp @@ -22,6 +22,6 @@ namespace atomic_dex::kdf j.at("platform_coin").get_to(in.platform_coin); j.at("required_confirmations").get_to(in.required_confirmations); j.at("token_id").get_to(in.token_id); - j.at("balances").get_to>(in.balances); + j.at("balances").get_to>(in.balances); } } \ No newline at end of file diff --git a/src/core/atomicdex/api/kdf/rpc_v2/rpc2.enable_slp_rpc.hpp b/src/core/atomicdex/api/kdf/rpc_v2/rpc2.enable_slp_rpc.hpp index 1fbe40301..4ed2462a1 100644 --- a/src/core/atomicdex/api/kdf/rpc_v2/rpc2.enable_slp_rpc.hpp +++ b/src/core/atomicdex/api/kdf/rpc_v2/rpc2.enable_slp_rpc.hpp @@ -23,7 +23,7 @@ #include //> nlohmann::json #include "atomicdex/api/kdf/rpc.hpp" -#include "atomicdex/api/kdf/balance_info.hpp" +#include "atomicdex/api/kdf/balance_infos.hpp" namespace atomic_dex::kdf { @@ -43,7 +43,7 @@ namespace atomic_dex::kdf std::string token_id; std::string platform_coin; int required_confirmations; - std::unordered_map balances; + std::unordered_map balances; }; using expected_error_type = rpc_basic_error_type; diff --git a/src/core/atomicdex/api/kdf/rpc_v2/rpc2.enable_tendermint_token.cpp b/src/core/atomicdex/api/kdf/rpc_v2/rpc2.enable_tendermint_token.cpp index 81bafbc1b..cbdf20206 100644 --- a/src/core/atomicdex/api/kdf/rpc_v2/rpc2.enable_tendermint_token.cpp +++ b/src/core/atomicdex/api/kdf/rpc_v2/rpc2.enable_tendermint_token.cpp @@ -20,6 +20,6 @@ namespace atomic_dex::kdf void from_json(const nlohmann::json& j, enable_tendermint_token_rpc_result& in) { j.at("platform_coin").get_to(in.platform_coin); - j.at("balances").get_to>(in.balances); + j.at("balances").get_to>(in.balances); } } \ No newline at end of file diff --git a/src/core/atomicdex/api/kdf/rpc_v2/rpc2.enable_tendermint_token.hpp b/src/core/atomicdex/api/kdf/rpc_v2/rpc2.enable_tendermint_token.hpp index 9597d1a38..fcf180a9f 100644 --- a/src/core/atomicdex/api/kdf/rpc_v2/rpc2.enable_tendermint_token.hpp +++ b/src/core/atomicdex/api/kdf/rpc_v2/rpc2.enable_tendermint_token.hpp @@ -22,7 +22,7 @@ #include //> nlohmann::json #include "atomicdex/api/kdf/rpc.hpp" -#include "atomicdex/api/kdf/balance_info.hpp" +#include "atomicdex/api/kdf/balance_infos.hpp" namespace atomic_dex::kdf { @@ -40,7 +40,7 @@ namespace atomic_dex::kdf struct expected_result_type { std::string platform_coin; - std::unordered_map balances; + std::unordered_map balances; }; using expected_error_type = rpc_basic_error_type; @@ -48,7 +48,7 @@ namespace atomic_dex::kdf expected_request_type request; std::optional result; std::optional error; - std::string raw_result; + std::string raw_result; }; using enable_tendermint_token_rpc_request = enable_tendermint_token_rpc::expected_request_type; 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 cc28a43f4..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()) @@ -25,6 +25,7 @@ namespace atomic_dex::kdf void from_json(const nlohmann::json& json, enable_tendermint_with_assets_result_rpc& out) { + out.ticker = json["ticker"]; out.address = json["address"]; out.current_block = json["current_block"]; out.tendermint_balances_infos = json["balance"].get(); 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 6bad7330a..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,7 +3,8 @@ #include #include "atomicdex/api/kdf/rpc.hpp" -#include "atomicdex/api/kdf/balance_info.hpp" +#include "atomicdex/config/enable.cfg.hpp" +#include "atomicdex/api/kdf/balance_infos.hpp" #include "atomicdex/config/electrum.cfg.hpp" namespace atomic_dex::kdf @@ -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; @@ -33,13 +33,14 @@ namespace atomic_dex::kdf { struct tendermint_balance_infos_t { - balance_info balances; + balance_infos balances; }; + std::string ticker; std::string address; std::size_t current_block; tendermint_balance_infos_t tendermint_balances_infos; - std::unordered_map tendermint_token_balances_infos; + std::unordered_map tendermint_token_balances_infos; }; using expected_error_type = rpc_basic_error_type; diff --git a/src/core/atomicdex/api/kdf/rpc_v2/rpc2.withdraw.cpp b/src/core/atomicdex/api/kdf/rpc_v2/rpc2.withdraw.cpp index ac0b96a04..d0a9d1a34 100644 --- a/src/core/atomicdex/api/kdf/rpc_v2/rpc2.withdraw.cpp +++ b/src/core/atomicdex/api/kdf/rpc_v2/rpc2.withdraw.cpp @@ -47,6 +47,10 @@ namespace atomic_dex::kdf obj["params"]["to"] = cfg.to; obj["params"]["max"] = cfg.max; if (cfg.memo.has_value()) + { + obj["params"]["ibc_source_channel"] = cfg.ibc_source_channel.value(); + } + if (cfg.memo.has_value()) { obj["params"]["memo"] = cfg.memo.value(); } diff --git a/src/core/atomicdex/api/kdf/rpc_v2/rpc2.withdraw.hpp b/src/core/atomicdex/api/kdf/rpc_v2/rpc2.withdraw.hpp index 76b4b74bd..2bd780fae 100644 --- a/src/core/atomicdex/api/kdf/rpc_v2/rpc2.withdraw.hpp +++ b/src/core/atomicdex/api/kdf/rpc_v2/rpc2.withdraw.hpp @@ -30,6 +30,7 @@ namespace atomic_dex::kdf std::string amount; ///< ignored if max is true std::optional fees{std::nullopt}; ///< ignored if std::nullopt std::optional memo; ///< memo for tendermint + std::optional ibc_source_channel; ///< ibc_source_channel for tendermint bool max{false}; }; diff --git a/src/core/atomicdex/api/kdf/transaction.data.cpp b/src/core/atomicdex/api/kdf/transaction.data.cpp index c9975f984..f8b97c6cb 100644 --- a/src/core/atomicdex/api/kdf/transaction.data.cpp +++ b/src/core/atomicdex/api/kdf/transaction.data.cpp @@ -114,7 +114,24 @@ namespace atomic_dex::kdf if (j.contains("transaction_type")) { - cfg.transaction_type = j.at("transaction_type").get(); + // Check if the "transaction_type" is an object for tendermint + if (j.at("transaction_type").is_object()) + { + for (auto& [k, v] : j.at("transaction_type").items()) { + cfg.tendermint_transaction_type = k; + cfg.tendermint_transaction_type_hash = v; + } + } + // Check if "transaction_type" is a string + else if (j.at("transaction_type").is_string()) + { + cfg.transaction_type = j.at("transaction_type").get(); + } + else + { + // Handle the case where "transaction_type" is neither a string nor an object + SPDLOG_ERROR("Unexpected type for transaction_type in JSON"); + } } // transaction_fee only in ZHTLC response diff --git a/src/core/atomicdex/api/kdf/transaction.data.hpp b/src/core/atomicdex/api/kdf/transaction.data.hpp index f25c9e9bf..296c89efe 100644 --- a/src/core/atomicdex/api/kdf/transaction.data.hpp +++ b/src/core/atomicdex/api/kdf/transaction.data.hpp @@ -74,6 +74,8 @@ namespace atomic_dex::kdf std::optional internal_id; std::optional confirmations; std::optional transaction_type; + std::optional tendermint_transaction_type; + std::optional tendermint_transaction_type_hash; std::optional memo; std::string timestamp_as_date; ///< human readeable timestamp }; 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/pages/qt.wallet.page.cpp b/src/core/atomicdex/pages/qt.wallet.page.cpp index 97fe85771..d9b7fa9d5 100644 --- a/src/core/atomicdex/pages/qt.wallet.page.cpp +++ b/src/core/atomicdex/pages/qt.wallet.page.cpp @@ -508,7 +508,7 @@ namespace atomic_dex } void - wallet_page::send(const QString& address, const QString& amount, bool max, bool with_fees, QVariantMap fees_data, const QString& memo) + wallet_page::send(const QString& address, const QString& amount, bool max, bool with_fees, QVariantMap fees_data, const QString& memo, const QString& ibc_source_channel) { //! Preparation this->set_send_busy(true); @@ -693,6 +693,7 @@ namespace atomic_dex .to = address.toStdString(), .amount = max ? "0" : amount.toStdString(), .memo = memo.toStdString(), + .ibc_source_channel = ibc_source_channel.toStdString(), .max = max }; @@ -735,6 +736,7 @@ namespace atomic_dex nlohmann::json json_data = kdf::template_request("withdraw", true); kdf::to_json(json_data, withdraw_req); + SPDLOG_DEBUG("withdraw request: {}", json_data.dump(4)); batch.push_back(json_data); diff --git a/src/core/atomicdex/pages/qt.wallet.page.hpp b/src/core/atomicdex/pages/qt.wallet.page.hpp index 97b90f739..678d0164d 100644 --- a/src/core/atomicdex/pages/qt.wallet.page.hpp +++ b/src/core/atomicdex/pages/qt.wallet.page.hpp @@ -88,7 +88,7 @@ namespace atomic_dex bool is_auth, const QString& tx_hex, bool is_claiming, bool is_max, const QString& amount); // Broadcast requires OS local user credentials verification. This is called by the Q_INVOKABLE broadcast() method after // entering credentials. - Q_INVOKABLE void send(const QString& address, const QString& amount, bool max, bool with_fees, QVariantMap fees_data, const QString& memo); + Q_INVOKABLE void send(const QString& address, const QString& amount, bool max, bool with_fees, QVariantMap fees_data, const QString& memo, const QString& ibc_source_channel); // QML API Properties Q_PROPERTY(transactions_model* transactions_mdl READ get_transactions_mdl NOTIFY transactionsMdlChanged) diff --git a/src/core/atomicdex/services/kdf/kdf.service.cpp b/src/core/atomicdex/services/kdf/kdf.service.cpp index f1df43e9c..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 @@ -332,10 +336,14 @@ namespace atomic_dex } } - if (s_info >= 29s) + if (s_info >= 23s) { - fetch_infos_thread(); // leads to batch_balance_and_tx - m_info_clock = std::chrono::high_resolution_clock::now(); + std::unique_lock lock(m_activation_mutex); + if (m_activation_queue.empty()) + { + fetch_infos_thread(); // leads to batch_balance_and_tx + m_info_clock = std::chrono::high_resolution_clock::now(); + } } } @@ -539,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; @@ -567,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) { @@ -639,20 +629,12 @@ namespace atomic_dex SPDLOG_INFO(">>>>>>>>>>>>>>>>>>>>>>>>>>> Enabling {} zhtlc_coins <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<", zhtlc_coins.size()); enable_zhtlc(zhtlc_coins); } - if (iris_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) + if (tendermint_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); + } } } @@ -1010,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) @@ -1033,16 +1026,16 @@ namespace atomic_dex { for (const auto& tendermint_coin_info : rpc.request.tokens_params) { - SPDLOG_ERROR("{} {}: ", tendermint_coin_info.ticker, rpc.error->error_type); - fetch_single_balance(get_coin_info(tendermint_coin_info.ticker)); std::unique_lock lock(m_coin_cfg_mutex); m_coins_informations[tendermint_coin_info.ticker].currently_enabled = true; + fetch_single_balance(get_coin_info(tendermint_coin_info.ticker)); dispatcher_.trigger(coin_fully_initialized{.tickers = {tendermint_coin_info.ticker}}); } } } else { + SPDLOG_DEBUG("{} failed to activate", rpc.request.ticker); std::unique_lock lock(m_coin_cfg_mutex); m_coins_informations[rpc.request.ticker].currently_enabled = false; update_coin_active({rpc.request.ticker}, false); @@ -1060,12 +1053,9 @@ namespace atomic_dex for (const auto& tendermint_token_addresses_info : rpc.result->tendermint_token_balances_infos) { dispatcher_.trigger(coin_fully_initialized{.tickers = {tendermint_token_addresses_info.first}}); - process_balance_answer(rpc); - std::unique_lock lock(m_coin_cfg_mutex); m_coins_informations[tendermint_token_addresses_info.first].currently_enabled = true; } } - process_balance_answer(rpc); } }; @@ -1097,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) @@ -1178,7 +1168,6 @@ namespace atomic_dex { const auto& answer = rpc.result.value(); kdf::balance_answer balance_answer; - balance_answer.address = answer.balances.begin()->first; balance_answer.balance = answer.balances.begin()->second.spendable; balance_answer.coin = answer.platform_coin; @@ -1195,7 +1184,7 @@ namespace atomic_dex { kdf::balance_answer balance_answer; - balance_answer.coin = rpc.request.ticker; + balance_answer.coin = answer.ticker; balance_answer.balance = answer.tendermint_balances_infos.balances.spendable; balance_answer.address = answer.address; { @@ -1520,10 +1509,18 @@ namespace atomic_dex { auto& answer = answers[i]; std::string ticker; + // SPDLOG_DEBUG("batch_balance_and_tx answer: {}", answer.dump(4)); if (batch_array[i].contains("mmrpc") && batch_array[i].at("mmrpc") == "2.0") { - ticker = batch_array[i].at("params").at("coin"); + if (batch_array[i].at("params").contains("coin")) + { + ticker = batch_array[i].at("params").at("coin"); + } + else if (batch_array[i].at("params").contains("ticker")) + { + ticker = batch_array[i].at("params").at("ticker"); + } } else { 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);