diff --git a/modules/blockchain/antara/gaming/blockchain/nspv.system.cpp b/modules/blockchain/antara/gaming/blockchain/nspv.system.cpp index c3f2169f..de76e98e 100644 --- a/modules/blockchain/antara/gaming/blockchain/nspv.system.cpp +++ b/modules/blockchain/antara/gaming/blockchain/nspv.system.cpp @@ -114,4 +114,8 @@ namespace antara::gaming::blockchain { } return true; } + + bool nspv::is_wif_wallet_exist() noexcept { + return std::filesystem::exists(antara::gaming::core::assets_real_path() / "blockchain/encrypted.wallet.wif"); + } } \ No newline at end of file diff --git a/modules/blockchain/antara/gaming/blockchain/nspv.system.hpp b/modules/blockchain/antara/gaming/blockchain/nspv.system.hpp index bcd5326f..8941461a 100644 --- a/modules/blockchain/antara/gaming/blockchain/nspv.system.hpp +++ b/modules/blockchain/antara/gaming/blockchain/nspv.system.hpp @@ -27,58 +27,22 @@ namespace fs = std::filesystem; namespace antara::gaming::blockchain { - class thread_safe_string_sink { - std::string &out_; - std::string &err_; - std::mutex &mutex_; - public: - thread_safe_string_sink(std::string &out, std::string& err, std::mutex &mutex) - : out_(out), err_(err), mutex_(mutex) - {} - - bool - operator()(reproc::stream stream, const uint8_t *buffer, unsigned int size) - { - std::lock_guard lock(mutex_); - switch (stream) { - case reproc::stream::out: - out_.append(reinterpret_cast(buffer), size); - break; - case reproc::stream::err: - err_.append(reinterpret_cast(buffer), size); - break; - case reproc::stream::in: - break; - } - return true; - } - }; - struct nspv_process { nspv_process(reproc::process background_) noexcept: background(std::move(background_)) { - //sink_thread = std::thread([this]() { this->background.drain(thread_safe_string_sink(out, err, process_mutex)); }); } ~nspv_process() { auto ec = background.stop(reproc::cleanup::terminate, reproc::milliseconds(2000), - reproc::cleanup::kill, - reproc::infinite); + reproc::cleanup::kill, + reproc::infinite); if (ec) { VLOG_SCOPE_F(loguru::Verbosity_ERROR, "error: %s", ec.message().c_str()); } - - /*if (sink_thread.joinable()) { - sink_thread.join(); - }*/ } reproc::process background; - //std::string out; - //std::string err; - //std::mutex process_mutex; - //std::thread sink_thread; }; class nspv final : public ecs::logic_update_system { @@ -87,6 +51,8 @@ namespace antara::gaming::blockchain { void update() noexcept final; + static bool is_wif_wallet_exist() noexcept; + bool spawn_nspv_instance(const std::string &coin) noexcept; ~nspv() noexcept final; diff --git a/modules/blockchain/antara/gaming/blockchain/nspv.system.tests.cpp b/modules/blockchain/antara/gaming/blockchain/nspv.system.tests.cpp index 7c430cf0..b33126ed 100644 --- a/modules/blockchain/antara/gaming/blockchain/nspv.system.tests.cpp +++ b/modules/blockchain/antara/gaming/blockchain/nspv.system.tests.cpp @@ -39,5 +39,6 @@ namespace antara::gaming::blockchain::tests auto& nspv_system = mgr.create_system(std::filesystem::current_path() / "nspv/assets/tools"); CHECK(nspv_system.spawn_nspv_instance("RICK")); + CHECK_FALSE(blockchain::nspv::is_wif_wallet_exist()); } } \ No newline at end of file