diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d4e91fc965..929136703d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -117,6 +117,7 @@ add_executable(${PROJECT_NAME}_tests MACOSX_BUNDLE ${ICON} tests/api/komodo_prices/komodo.prices.tests.cpp tests/api/mm2/mm2.rpc.trade.preimage.tests.cpp tests/api/mm2/mm2.fraction.tests.cpp + tests/api/mm2/mm2.api.utxo.merge.params.tests.cpp ##! Utilities tests/utilities/qt.utilities.tests.cpp diff --git a/src/core/atomicdex/api/mm2/rpc.electrum.cpp b/src/core/atomicdex/api/mm2/rpc.electrum.cpp index 86d90c695d..5b37049668 100644 --- a/src/core/atomicdex/api/mm2/rpc.electrum.cpp +++ b/src/core/atomicdex/api/mm2/rpc.electrum.cpp @@ -35,10 +35,14 @@ namespace mm2::api j["swap_contract_address"] = cfg.is_testnet ? cfg.testnet_qrc_swap_contract_address : cfg.mainnet_qrc_swap_contract_address; j["fallback_swap_contract"] = cfg.is_testnet ? cfg.testnet_fallback_qrc_swap_contract_address : cfg.mainnet_fallback_qrc_swap_contract_address; } - if (cfg.address_format.has_value()) { + if (cfg.address_format.has_value()) + { j["address_format"] = cfg.address_format.value(); } - //SPDLOG_INFO("electrum: {}", j.dump()); + if (cfg.merge_params.has_value()) + { + j["utxo_merge_params"] = cfg.merge_params.value(); + } } //! Deserialization diff --git a/src/core/atomicdex/api/mm2/rpc.electrum.hpp b/src/core/atomicdex/api/mm2/rpc.electrum.hpp index 4c206a9d91..194272cab9 100644 --- a/src/core/atomicdex/api/mm2/rpc.electrum.hpp +++ b/src/core/atomicdex/api/mm2/rpc.electrum.hpp @@ -27,16 +27,17 @@ namespace mm2::api { struct electrum_request { - std::string coin_name; - std::vector servers; - CoinType coin_type; - bool is_testnet{false}; - bool with_tx_history{true}; - const std::string testnet_qrc_swap_contract_address{"0xba8b71f3544b93e2f681f996da519a98ace0107a"}; - const std::string testnet_fallback_qrc_swap_contract_address{testnet_qrc_swap_contract_address}; - const std::string mainnet_qrc_swap_contract_address{"0x2f754733acd6d753731c00fee32cb484551cc15d"}; - const std::string mainnet_fallback_qrc_swap_contract_address{mainnet_qrc_swap_contract_address}; - std::optional address_format; + std::string coin_name; + std::vector servers; + CoinType coin_type; + bool is_testnet{false}; + bool with_tx_history{true}; + const std::string testnet_qrc_swap_contract_address{"0xba8b71f3544b93e2f681f996da519a98ace0107a"}; + const std::string testnet_fallback_qrc_swap_contract_address{testnet_qrc_swap_contract_address}; + const std::string mainnet_qrc_swap_contract_address{"0x2f754733acd6d753731c00fee32cb484551cc15d"}; + const std::string mainnet_fallback_qrc_swap_contract_address{mainnet_qrc_swap_contract_address}; + std::optional address_format; + std::optional merge_params; }; struct electrum_answer diff --git a/src/core/atomicdex/api/mm2/utxo.merge.params.cpp b/src/core/atomicdex/api/mm2/utxo.merge.params.cpp new file mode 100644 index 0000000000..ff272b06d7 --- /dev/null +++ b/src/core/atomicdex/api/mm2/utxo.merge.params.cpp @@ -0,0 +1,32 @@ +/****************************************************************************** + * Copyright © 2013-2022 The Komodo Platform Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * Komodo Platform software, including this file may be copied, modified, * + * propagated or distributed except according to the terms contained in the * + * LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + +//! Dependencies Headers +#include + +//! Project Headers +#include "utxo.merge.params.hpp" + +namespace mm2::api +{ + void + to_json(nlohmann::json& j, const utxo_merge_params& cfg) + { + j["merge_at"] = cfg.merge_at; + j["check_every"] = cfg.check_every; + j["max_merge_at_once"] = cfg.max_merge_at_once; + } +} // namespace mm2::api \ No newline at end of file diff --git a/src/core/atomicdex/api/mm2/utxo.merge.params.hpp b/src/core/atomicdex/api/mm2/utxo.merge.params.hpp new file mode 100644 index 0000000000..27d65b631f --- /dev/null +++ b/src/core/atomicdex/api/mm2/utxo.merge.params.hpp @@ -0,0 +1,36 @@ +/****************************************************************************** + * Copyright © 2013-2022 The Komodo Platform Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * Komodo Platform software, including this file may be copied, modified, * + * propagated or distributed except according to the terms contained in the * + * LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + +#pragma once + +#include + +namespace mm2::api +{ + struct utxo_merge_params + { + std::size_t merge_at; + std::size_t check_every; + std::size_t max_merge_at_once; + }; + + void to_json(nlohmann::json& j, const utxo_merge_params& cfg); +} + +namespace atomic_dex +{ + using t_utxo_merge_params = ::mm2::api::utxo_merge_params; +} // namespace atomic_dex \ No newline at end of file diff --git a/src/core/atomicdex/config/coins.cfg.cpp b/src/core/atomicdex/config/coins.cfg.cpp index 7fd94b9c98..48df013364 100644 --- a/src/core/atomicdex/config/coins.cfg.cpp +++ b/src/core/atomicdex/config/coins.cfg.cpp @@ -33,6 +33,11 @@ namespace atomic_dex { cfg.custom_backup = j.at("mm2_backup"); } + + if (j.contains("utxo_merge")) + { + cfg.utxo_merge = j.at("utxo_merge"); + } if (j.contains("electrum")) { cfg.electrum_urls = j.at("electrum").get>(); diff --git a/src/core/atomicdex/config/coins.cfg.hpp b/src/core/atomicdex/config/coins.cfg.hpp index 3c2d7f7033..bb1283ebc3 100644 --- a/src/core/atomicdex/config/coins.cfg.hpp +++ b/src/core/atomicdex/config/coins.cfg.hpp @@ -27,6 +27,7 @@ //! Project #include "atomicdex/api/mm2/mm2.constants.hpp" +#include "atomicdex/api/mm2/utxo.merge.params.hpp" #include "atomicdex/config/electrum.cfg.hpp" #include "atomicdex/constants/qt.coins.enums.hpp" @@ -39,34 +40,35 @@ namespace atomic_dex static constexpr const char* matic_gas_stations = "https://gasstation-mainnet.matic.network/"; using electrum_servers = std::vector; using nodes = std::vector; - std::string ticker; - std::optional alias_ticker{std::nullopt}; - std::string gui_ticker; ///< Ticker displayed in the gui - std::string name; ///< nice name - std::optional electrum_urls; - std::optional urls; - bool is_claimable{false}; - std::string minimal_claim_amount{"0"}; - bool currently_enabled{false}; - bool active{false}; - std::string coinpaprika_id{"test-coin"}; - std::string coingecko_id{"test-coin"}; - std::string nomics_id{"test-coin"}; - bool is_custom_coin{false}; - std::string type; - std::vector explorer_url; ///< usefull for transaction, take this url and append transaction id - std::string tx_uri{"tx/"}; - std::string address_url{"address/"}; - std::optional custom_backup; - std::optional is_testnet{false}; ///< True if testnet (tBTC, tQTUM, QRC-20 on testnet, tETH) - CoinType coin_type; - bool checked{false}; - bool wallet_only{false}; - bool has_parent_fees_ticker{false}; ///< True if parent fees is different from current ticker eg: ERC20 tokens - std::string fees_ticker; - bool segwit{false}; - bool is_segwit_on{false}; - bool is_erc_family{false}; + std::string ticker; + std::optional alias_ticker{std::nullopt}; + std::string gui_ticker; ///< Ticker displayed in the gui + std::string name; ///< nice name + std::optional electrum_urls; + std::optional utxo_merge{false}; + std::optional urls; + bool is_claimable{false}; + std::string minimal_claim_amount{"0"}; + bool currently_enabled{false}; + bool active{false}; + std::string coinpaprika_id{"test-coin"}; + std::string coingecko_id{"test-coin"}; + std::string nomics_id{"test-coin"}; + bool is_custom_coin{false}; + std::string type; + std::vector explorer_url; ///< usefull for transaction, take this url and append transaction id + std::string tx_uri{"tx/"}; + std::string address_url{"address/"}; + std::optional custom_backup; + std::optional is_testnet{false}; ///< True if testnet (tBTC, tQTUM, QRC-20 on testnet, tETH) + CoinType coin_type; + bool checked{false}; + bool wallet_only{false}; + bool has_parent_fees_ticker{false}; ///< True if parent fees is different from current ticker eg: ERC20 tokens + std::string fees_ticker; + bool segwit{false}; + bool is_segwit_on{false}; + bool is_erc_family{false}; }; void from_json(const nlohmann::json& j, coin_config& cfg); diff --git a/src/core/atomicdex/services/mm2/mm2.service.cpp b/src/core/atomicdex/services/mm2/mm2.service.cpp index ae363dcfad..b8f6e39b49 100644 --- a/src/core/atomicdex/services/mm2/mm2.service.cpp +++ b/src/core/atomicdex/services/mm2/mm2.service.cpp @@ -641,6 +641,14 @@ namespace atomic_dex request.address_format = nlohmann::json::object(); request.address_format.value()["format"] = "segwit"; } + + if (coin_info.utxo_merge.value_or(false)) + { + t_utxo_merge_params params{.merge_at = 250, .check_every = 300, .max_merge_at_once = 125}; + nlohmann::json j; + mm2::api::to_json(j, params); + request.merge_params = j; + } nlohmann::json j = ::mm2::api::template_request("electrum"); ::mm2::api::to_json(j, request); batch_array.push_back(j); @@ -655,7 +663,6 @@ namespace atomic_dex .with_tx_history = false}; nlohmann::json j = ::mm2::api::template_request("enable"); ::mm2::api::to_json(j, request); - // SPDLOG_INFO("enable request: {}", j.dump(4)); batch_array.push_back(j); } //! If the coin is a custom coin and not present, then we have a config mismatch, we re-add it to the mm2 coins cfg but this need a app restart. diff --git a/src/tests/api/mm2/mm2.api.utxo.merge.params.tests.cpp b/src/tests/api/mm2/mm2.api.utxo.merge.params.tests.cpp new file mode 100644 index 0000000000..eac5d6e201 --- /dev/null +++ b/src/tests/api/mm2/mm2.api.utxo.merge.params.tests.cpp @@ -0,0 +1,36 @@ +/****************************************************************************** + * Copyright © 2013-2022 The Komodo Platform Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * Komodo Platform software, including this file may be copied, modified, * + * propagated or distributed except according to the terms contained in the * + * LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + +//! Deps +#include "doctest/doctest.h" +#include + +#include "atomicdex/api/mm2/utxo.merge.params.hpp" + +TEST_CASE("mm2::api::utxo_merge_params serialisation") +{ + const nlohmann::json expected_json = R"( + { + "merge_at":50, + "check_every":10, + "max_merge_at_once":25 + } + )"_json; + mm2::api::utxo_merge_params request{.merge_at = 50, .check_every = 10, .max_merge_at_once = 25}; + nlohmann::json j; + mm2::api::to_json(j, request); + CHECK_EQ(j, expected_json); +} \ No newline at end of file