Skip to content

Commit

Permalink
Merge pull request #1908 from KomodoPlatform/whitelabel-rpcport
Browse files Browse the repository at this point in the history
Use env variables for mm2 / RPC
  • Loading branch information
tonymorony authored Aug 9, 2022
2 parents d441e4f + 7463ae2 commit a5961d3
Show file tree
Hide file tree
Showing 14 changed files with 37 additions and 14 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/atomicdex-desktop-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ on:
- cron: '0 0 * * 1'

env:
DEX_API: "mm2"
DEX_RPCPORT: 7783
DEX_RPC: "http://127.0.0.1:7783"
DEX_PROJECT_NAME: "atomicdex-desktop"
DEX_DISPLAY_NAME: "AtomicDex Desktop"
DEX_COMPANY: "KomodoPlatform"
Expand Down
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ FetchContent_MakeAvailable(mm2 jl777-coins qmaterial)
if (UNIX)
configure_file(assets/config/${PROJECT_VERSION}-coins.json ${CMAKE_CURRENT_SOURCE_DIR}/assets/config/${PROJECT_VERSION}-coins.json COPYONLY)
configure_file(${jl777-coins_SOURCE_DIR}/coins ${CMAKE_CURRENT_SOURCE_DIR}/assets/tools/mm2/coins COPYONLY)
configure_file(${mm2_SOURCE_DIR}/mm2 ${CMAKE_CURRENT_SOURCE_DIR}/assets/tools/mm2/mm2 COPYONLY)
configure_file(${mm2_SOURCE_DIR}/mm2 ${CMAKE_CURRENT_SOURCE_DIR}/assets/tools/mm2/${DEX_API} COPYONLY)
else ()
configure_file(assets/config/${PROJECT_VERSION}-coins.json ${CMAKE_BINARY_DIR}/bin/assets/config/${PROJECT_VERSION}-coins.json COPYONLY)
configure_file(${jl777-coins_SOURCE_DIR}/coins ${CMAKE_BINARY_DIR}/bin/assets/tools/mm2/coins COPYONLY)
configure_file(${mm2_SOURCE_DIR}/mm2.exe ${CMAKE_BINARY_DIR}/bin/assets/tools/mm2/mm2.exe COPYONLY)
configure_file(${mm2_SOURCE_DIR}/mm2.exe ${CMAKE_BINARY_DIR}/bin/assets/tools/mm2/${DEX_API}.exe COPYONLY)
configure_file(${mm2_SOURCE_DIR}/msvcp140.dll ${CMAKE_BINARY_DIR}/bin/assets/tools/mm2/msvcp140.dll COPYONLY)
configure_file(${mm2_SOURCE_DIR}/msvcr100.dll ${CMAKE_BINARY_DIR}/bin/assets/tools/mm2/msvcr100.dll COPYONLY)
configure_file(${mm2_SOURCE_DIR}/vcruntime140.dll ${CMAKE_BINARY_DIR}/bin/assets/tools/mm2/vcruntime140.dll COPYONLY)
Expand Down
2 changes: 1 addition & 1 deletion cmake/install/macos/osx_post_install.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ if (NOT EXISTS ${CMAKE_SOURCE_DIR}/bin/${DEX_PROJECT_NAME}.dmg)
ECHO_OUTPUT_VARIABLE
ECHO_ERROR_VARIABLE)

execute_process(COMMAND codesign --deep --force -v -s "$ENV{MAC_SIGN_IDENTITY}" -o runtime --timestamp ${PROJECT_APP_PATH}/Contents/Resources/assets/tools/mm2/mm2
execute_process(COMMAND codesign --deep --force -v -s "$ENV{MAC_SIGN_IDENTITY}" -o runtime --timestamp ${PROJECT_APP_PATH}/Contents/Resources/assets/tools/mm2/${DEX_API}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
ECHO_OUTPUT_VARIABLE
ECHO_ERROR_VARIABLE)
Expand Down
12 changes: 12 additions & 0 deletions cmake/project.metadata.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Default project values
set(DEX_API "mm2")
set(DEX_RPCPORT 7783)
set(DEX_RPC "http://127.0.0.1:7783")
set(DEX_PROJECT_NAME "atomicdex-desktop")
set(DEX_DISPLAY_NAME "AtomicDEX Desktop")
set(DEX_MAINTENANCE_TOOL_NAME "AtomicDEX Maintenance Tool")
Expand All @@ -25,6 +28,15 @@ if (UNIX AND NOT APPLE)
endif ()

# Erases default project values with environment variables if they exist.
if (DEFINED ENV{DEX_API})
set(DEX_API $ENV{DEX_API})
endif ()
if (DEFINED ENV{DEX_RPCPORT})
set(DEX_RPCPORT $ENV{DEX_RPCPORT})
endif ()
if (DEFINED ENV{DEX_RPC})
set(DEX_RPC $ENV{DEX_RPC})
endif ()
if (DEFINED ENV{DEX_PROJECT_NAME})
set(DEX_PROJECT_NAME $ENV{DEX_PROJECT_NAME})
endif ()
Expand Down
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ DEX_NEW_LIB(core INTERFACE
$<$<PLATFORM_ID:Windows>:NOMINMAX>
$<$<PLATFORM_ID:Windows>:SPDLOG_WCHAR_TO_UTF8_SUPPORT>
_TURN_OFF_PLATFORM_STRING
DEX_NAME="${DEX_DISPLAY_NAME}" DEX_WEBSITE_URL="${DEX_WEBSITE}"
DEX_API="${DEX_API}" DEX_RPC="${DEX_RPC}" DEX_RPCPORT="${DEX_RPCPORT}" DEX_NAME="${DEX_DISPLAY_NAME}" DEX_WEBSITE_URL="${DEX_WEBSITE}"
DEX_SUPPORT_URL="${DEX_SUPPORT_PAGE}" DEX_DISCORD_URL="${DEX_DISCORD}" DEX_TWITTER_URL="${DEX_TWITTER}"
DEX_PRIMARY_COIN="${DEX_PRIMARY_COIN}" DEX_SECOND_PRIMARY_COIN="${DEX_SECOND_PRIMARY_COIN}" #DEX_COMMON_DATA_FOLDER="${DEX_COMMON_DATA_FOLDER}"
DEX_PROJECT_NAME="${DEX_PROJECT_NAME}" DEX_COMPANY_NAME="${DEX_COMPANY_NAME}"
Expand Down
5 changes: 3 additions & 2 deletions src/app/main.prerequisites.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
//! Project Headers
#include "app.hpp"
#include "atomicdex/constants/qt.wallet.enums.hpp"
#include "atomicdex/constants/dex.constants.hpp"
#include "atomicdex/models/qt.portfolio.model.hpp"
#include "atomicdex/utilities/kill.hpp"
#include "atomicdex/utilities/qt.utilities.hpp"
Expand Down Expand Up @@ -104,7 +105,7 @@ static void
signal_handler(int signal)
{
SPDLOG_ERROR("sigabort received, cleaning mm2");
atomic_dex::kill_executable("mm2");
atomic_dex::kill_executable(atomic_dex::g_dex_api);
#if defined(linux) || defined(__APPLE__)
boost::stacktrace::safe_dump_to("./backtrace.dump");
std::ifstream ifs("./backtrace.dump");
Expand Down Expand Up @@ -158,7 +159,7 @@ static void
clean_previous_run()
{
SPDLOG_INFO("cleaning previous mm2 instance");
atomic_dex::kill_executable("mm2");
atomic_dex::kill_executable(atomic_dex::g_dex_api);
}

static void
Expand Down
3 changes: 2 additions & 1 deletion src/core/atomicdex/api/mm2/mm2.client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "atomicdex/api/mm2/mm2.client.hpp"
#include "atomicdex/api/mm2/mm2.hpp"
#include "atomicdex/api/mm2/rpc.tx.history.hpp"
#include "atomicdex/constants/dex.constants.hpp"
#include "rpc.get.public.key.hpp"
#include "rpc.hpp"

Expand All @@ -34,7 +35,7 @@ namespace
web::http::client::http_client_config cfg;
using namespace std::chrono_literals;
cfg.set_timeout(30s);
return web::http::client::http_client(FROM_STD_STR(::mm2::api::g_endpoint), cfg);
return web::http::client::http_client(FROM_STD_STR(atomic_dex::g_dex_rpc), cfg);
}

template <mm2::api::rpc Rpc>
Expand Down
2 changes: 1 addition & 1 deletion src/core/atomicdex/api/mm2/mm2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ namespace mm2::api
nlohmann::json json_data = template_request("version");
try
{
auto client = std::make_unique<web::http::client::http_client>(FROM_STD_STR("http://127.0.0.1:7783"));
auto client = std::make_unique<web::http::client::http_client>(FROM_STD_STR(atomic_dex::g_dex_rpc));
web::http::http_request request;
request.set_method(web::http::methods::POST);
request.set_body(json_data.dump());
Expand Down
1 change: 0 additions & 1 deletion src/core/atomicdex/api/mm2/mm2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ namespace ag = antara::gaming;

namespace mm2::api
{
inline constexpr const char* g_endpoint = "http://127.0.0.1:7783";
inline constexpr const char* g_etherscan_proxy_endpoint = "https://komodo.live:3334";
inline std::unique_ptr<web::http::client::http_client> g_etherscan_proxy_http_client{
std::make_unique<web::http::client::http_client>(FROM_STD_STR(g_etherscan_proxy_endpoint))};
Expand Down
4 changes: 4 additions & 0 deletions src/core/atomicdex/config/mm2.cfg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
//! Headers
#include "atomicdex/utilities/global.utilities.hpp"
#include "atomicdex/version/version.hpp"
#include "atomicdex/constants/dex.constants.hpp"

namespace atomic_dex
{
Expand All @@ -32,6 +33,7 @@ namespace atomic_dex
{
std::string gui{std::string(DEX_NAME) + " "s + atomic_dex::get_version()};
int64_t netid{7777};
int64_t rpcport{atomic_dex::g_dex_rpcport};
std::vector<std::string> seednodes{};
//std::vector<std::string> seednodes{"195.201.91.96", "195.201.91.53", "168.119.174.126", "46.4.78.11", "46.4.87.18"};
//std::vector<std::string> seednodes{"46.4.78.11", "46.4.87.18"};
Expand All @@ -54,6 +56,7 @@ namespace atomic_dex
{
cfg.gui = j.at("gui").get<std::string>();
cfg.netid = j.at("netid").get<int64_t>();
cfg.rpcport = j.at("rpcport").get<int64_t>();
cfg.userhome = j.at("userhome").get<std::string>();
cfg.passphrase = j.at("passphrase").get<std::string>();
cfg.rpc_password = j.at("rpc_password").get<std::string>();
Expand All @@ -66,6 +69,7 @@ namespace atomic_dex
j = json::object();
j["gui"] = cfg.gui;
j["netid"] = cfg.netid;
j["rpcport"] = cfg.rpcport;
j["userhome"] = cfg.userhome;
j["passphrase"] = cfg.passphrase;
j["rpc_password"] = cfg.rpc_password;
Expand Down
3 changes: 3 additions & 0 deletions src/core/atomicdex/constants/dex.constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace atomic_dex
{
inline const char* g_dex_api{DEX_API};
inline const std::string g_dex_rpc{DEX_RPC};
inline const int64_t g_dex_rpcport{std::stoi(DEX_RPCPORT)};
inline const std::string g_primary_dex_coin{DEX_PRIMARY_COIN};
inline const std::string g_second_primary_dex_coin{DEX_SECOND_PRIMARY_COIN};
inline const std::vector<std::string> g_default_coins{g_primary_dex_coin, g_second_primary_dex_coin};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include <nlohmann/json.hpp>

//! Our project
#include "atomicdex/constants/dex.constants.hpp"
#include "atomicdex/services/internet/internet.checker.service.hpp"
#include "atomicdex/services/mm2/mm2.service.hpp"
#include "atomicdex/utilities/cpprestsdk.utilities.hpp"
Expand Down Expand Up @@ -178,7 +177,7 @@ namespace atomic_dex
::mm2::api::to_json(current_request, req_orderbook);
batch.push_back(current_request);
auto async_answer = mm2.get_mm2_client().async_rpc_batch_standalone(batch);
generic_treat_answer(async_answer, "http://127.0.0.1:7783", &internet_service_checker::is_mm2_endpoint_alive);
generic_treat_answer(async_answer, TO_STD_STR(atomic_dex::g_dex_rpc), &internet_service_checker::is_mm2_endpoint_alive);
}
else
{
Expand Down
5 changes: 3 additions & 2 deletions src/core/atomicdex/services/mm2/mm2.service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "atomicdex/api/mm2/rpc.min.volume.hpp"
#include "atomicdex/api/mm2/rpc.tx.history.hpp"
#include "atomicdex/config/mm2.cfg.hpp"
#include "atomicdex/constants/dex.constants.hpp"
#include "atomicdex/managers/qt.wallet.manager.hpp"
#include "atomicdex/pages/qt.portfolio.page.hpp"
#include "atomicdex/services/internet/internet.checker.service.hpp"
Expand Down Expand Up @@ -323,7 +324,7 @@ namespace atomic_dex
{
SPDLOG_INFO("mm2 didn't stop yet with rpc stop, stopping process manually");
#if defined(_WIN32) || defined(WIN32)
atomic_dex::kill_executable("mm2");
atomic_dex::kill_executable(atomic_dex::g_dex_api);
#else
/*const reproc::stop_actions stop_actions = {
{reproc::stop::terminate, reproc::milliseconds(2000)},
Expand Down Expand Up @@ -990,7 +991,7 @@ namespace atomic_dex
env.insert("MM_LOG", std_path_to_qstring(utils::get_mm2_atomic_dex_current_log_file()));
env.insert("MM_COINS_PATH", std_path_to_qstring((utils::get_current_configs_path() / "coins.json")));
QProcess mm2_instance;
mm2_instance.setProgram(std_path_to_qstring((tools_path / "mm2")));
mm2_instance.setProgram(std_path_to_qstring((tools_path / atomic_dex::g_dex_api)));
mm2_instance.setWorkingDirectory(std_path_to_qstring(tools_path));
mm2_instance.setProcessEnvironment(env);
bool started = mm2_instance.startDetached();
Expand Down
2 changes: 1 addition & 1 deletion src/tests/atomic.dex.tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ main(int argc, char** argv)

context.applyCommandLine(argc, argv);

atomic_dex::kill_executable("mm2");
atomic_dex::kill_executable(atomic_dex::g_dex_api);

QStringList args;
const int ac = argc;
Expand Down

0 comments on commit a5961d3

Please sign in to comment.