Skip to content

Commit

Permalink
feat(nspv): add is wif wallet exist
Browse files Browse the repository at this point in the history
  • Loading branch information
Milerius committed Nov 19, 2019
1 parent a99b3de commit 7912710
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 38 deletions.
4 changes: 4 additions & 0 deletions modules/blockchain/antara/gaming/blockchain/nspv.system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
42 changes: 4 additions & 38 deletions modules/blockchain/antara/gaming/blockchain/nspv.system.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::mutex> lock(mutex_);
switch (stream) {
case reproc::stream::out:
out_.append(reinterpret_cast<const char *>(buffer), size);
break;
case reproc::stream::err:
err_.append(reinterpret_cast<const char *>(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<nspv> {
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,6 @@ namespace antara::gaming::blockchain::tests

auto& nspv_system = mgr.create_system<blockchain::nspv>(std::filesystem::current_path() / "nspv/assets/tools");
CHECK(nspv_system.spawn_nspv_instance("RICK"));
CHECK_FALSE(blockchain::nspv::is_wif_wallet_exist());
}
}

0 comments on commit 7912710

Please sign in to comment.