Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Z coin optional date #2367

Merged
merged 4 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ endif ()
##! We fetch our dependencies
if (APPLE)
FetchContent_Declare(mm2
URL https://github.com/KomodoPlatform/komodo-defi-framework/releases/download/v1.0.7-beta/mm2-79f620559-Darwin-Release.zip)
URL https://sdk.devbuilds.komodo.earth/dev/mm2_a9f606d-mac-x86-64.zip)
elseif (UNIX AND NOT APPLE)
FetchContent_Declare(mm2
URL https://github.com/KomodoPlatform/komodo-defi-framework/releases/download/v1.0.7-beta/mm2-79f620559-Linux-Release.zip)
URL https://sdk.devbuilds.komodo.earth/dev/mm2_a9f606d-linux-x86-64.zip)
else ()
FetchContent_Declare(mm2
URL https://github.com/KomodoPlatform/komodo-defi-framework/releases/download/v1.0.7-beta/mm2-79f620559-Win64.zip)
URL https://sdk.devbuilds.komodo.earth/dev/mm2_a9f606d-win-x86-64.zip)
endif ()

#FetchContent_Declare(qmaterial URL https://github.com/KomodoPlatform/Qaterial/archive/last-clang-working-2.zip)
Expand Down
22 changes: 22 additions & 0 deletions atomic_defi_design/Dex/Settings/SettingModal.qml
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,31 @@ Qaterial.Dialog

Item { Layout.fillWidth: true }

DefaultCheckBox
{
id: use_sync_date_checkbox

spacing: 2

label.wrapMode: Label.NoWrap
label.font.pixelSize: 14
text: qsTr("use date sync")
textColor: Dex.CurrentTheme.foregroundColor2
Component.onCompleted: checked = API.app.settings_pg.get_use_sync_date()
onToggled: {
atomic_settings2.setValue(
"UseSyncDate",
checked
)
}
}

Item { Layout.fillWidth: true }

DatePicker
{
id: sync_date
enabled: use_sync_date_checkbox.checked
titleText: qsTr("Sync Date")
minimumDate: default_min_date
maximumDate: default_max_date
Expand Down
1 change: 1 addition & 0 deletions src/app/main.prerequisites.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ handle_settings(QSettings& settings)
create_settings_functor("2FA", 0);
create_settings_functor("MaximumNbCoinsEnabled", 50);
create_settings_functor("PirateSyncDate", timestamp);
create_settings_functor("UseSyncDate", false);
create_settings_functor("DefaultTradingMode", TradingMode::Simple);
create_settings_functor("FontMode", QQuickWindow::TextRenderType::QtTextRendering);
}
Expand Down
5 changes: 4 additions & 1 deletion src/core/atomicdex/api/mm2/rpc2.task.enable_z_coin.init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ namespace atomic_dex::mm2
{
j["params"]["ticker"] = request.coin_name;
j["params"]["activation_params"]["mode"]["rpc"] = "Light";
j["params"]["activation_params"]["mode"]["rpc_data"]["sync_params"]["height"] = request.sync_height;
if (request.sync_height.has_value())
{
j["params"]["activation_params"]["mode"]["rpc_data"]["sync_params"]["height"] = request.sync_height.value();
}
j["params"]["activation_params"]["mode"]["rpc_data"]["electrum_servers"] = request.servers;
j["params"]["activation_params"]["mode"]["rpc_data"]["light_wallet_d_servers"] = request.z_urls;
j["params"]["activation_params"]["scan_blocks_per_iteration"] = 5000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace atomic_dex::mm2
std::vector<atomic_dex::electrum_server> servers;
std::vector<std::string> z_urls;
CoinType coin_type;
int sync_height{0};
std::optional<int> sync_height;
bool is_testnet{false};
bool with_tx_history{false}; // Not yet in API
};
Expand Down
9 changes: 7 additions & 2 deletions src/core/atomicdex/pages/qt.settings.page.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ namespace atomic_dex { void settings_page::update() {} }
// Getters|Setters
namespace atomic_dex
{
bool settings_page::get_use_sync_date() const
{
QSettings& settings = entity_registry_.ctx<QSettings>();
return settings.value("UseSyncDate").toBool();
}
int settings_page::get_pirate_sync_date() const
{
QSettings& settings = entity_registry_.ctx<QSettings>();
Expand Down Expand Up @@ -108,10 +113,10 @@ namespace atomic_dex
return height;
}

void settings_page::set_pirate_sync_date(int new_timestamp)
void settings_page::set_pirate_sync_date(int new_value)
{
QSettings& settings = entity_registry_.ctx<QSettings>();
settings.setValue("PirateSyncDate", new_timestamp);
settings.setValue("UseSyncDate", new_value);
settings.sync();
}

Expand Down
2 changes: 2 additions & 0 deletions src/core/atomicdex/pages/qt.settings.page.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ namespace atomic_dex
[[nodiscard]] QString get_current_currency_sign() const;
[[nodiscard]] QString get_current_fiat_sign() const;
[[nodiscard]] QString get_current_fiat() const;
void set_use_sync_date(int new_value);
void set_pirate_sync_date(int new_timestamp);
[[nodiscard]] bool is_notification_enabled() const;
void set_notification_enabled(bool is_enabled);
Expand Down Expand Up @@ -109,6 +110,7 @@ namespace atomic_dex
Q_INVOKABLE [[nodiscard]] bool is_this_ticker_present_in_raw_cfg(const QString& ticker) const;
Q_INVOKABLE [[nodiscard]] bool is_this_ticker_present_in_normal_cfg(const QString& ticker) const;
Q_INVOKABLE [[nodiscard]] QString get_custom_coins_icons_path() const;
Q_INVOKABLE [[nodiscard]] bool get_use_sync_date() const;
Q_INVOKABLE [[nodiscard]] int get_pirate_sync_date() const;
Q_INVOKABLE [[nodiscard]] int get_pirate_sync_height(int sync_date, int checkpoint_height, int checkpoint_blocktime) const;
Q_INVOKABLE void process_token_add(const QString& contract_address, const QString& coingecko_id, const QString& icon_filepath, CoinType coin_type);
Expand Down
19 changes: 14 additions & 5 deletions src/core/atomicdex/services/mm2/mm2.service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1394,23 +1394,32 @@ namespace atomic_dex
auto request_functor = [this](coin_config coin_info) -> std::pair<nlohmann::json, std::vector<std::string>>
{
const auto& settings_system = m_system_manager.get_system<settings_page>();
int sync_date = settings_system.get_pirate_sync_date();
int sync_height = settings_system.get_pirate_sync_height(sync_date, coin_info.checkpoint_height, coin_info.checkpoint_blocktime);


t_enable_z_coin_request request{
.coin_name = coin_info.ticker,
.servers = coin_info.electrum_urls.value_or(get_electrum_server_from_token(coin_info.ticker)),
.z_urls = coin_info.z_urls.value_or(std::vector<std::string>{}),
.coin_type = coin_info.coin_type,
.sync_height = sync_height,
.is_testnet = coin_info.is_testnet.value_or(false),
.with_tx_history = false}; // Tx history not yet ready for ZHTLC
bool use_date = settings_system.get_use_sync_date();
SPDLOG_INFO("use_date: {}", use_date);
if (use_date)
{
int sync_date = settings_system.get_pirate_sync_date();
int sync_height = settings_system.get_pirate_sync_height(
sync_date,
coin_info.checkpoint_height,
coin_info.checkpoint_blocktime
);
request.sync_height = sync_height;
}

nlohmann::json j = mm2::template_request("task::enable_z_coin::init", true);
mm2::to_json(j, request);
nlohmann::json batch = nlohmann::json::array();
batch.push_back(j);
// SPDLOG_INFO("ZHTLC request: {}", batch.dump(4));
SPDLOG_INFO("ZHTLC request: {}", batch.dump(4));
return {batch, {coin_info.ticker}};
};

Expand Down
Loading