Skip to content

Commit

Permalink
feat(nspv): add auto login option
Browse files Browse the repository at this point in the history
  • Loading branch information
Milerius committed Nov 19, 2019
1 parent be34a58 commit 02634f5
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
8 changes: 5 additions & 3 deletions modules/blockchain/antara/gaming/blockchain/nspv.system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace antara::gaming::blockchain {
LOG_SCOPE_FUNCTION(INFO);
}

bool nspv::spawn_nspv_instance(const std::string &coin, std::optional<std::size_t> rpcport_in) noexcept {
bool nspv::spawn_nspv_instance(const std::string &coin, bool auto_login, std::optional<std::size_t> rpcport_in) noexcept {
LOG_SCOPE_FUNCTION(INFO);
std::ifstream ifs(tools_path_ / "coins");
assert(ifs);
Expand Down Expand Up @@ -75,8 +75,10 @@ namespace antara::gaming::blockchain {
DVLOG_F(loguru::Verbosity_ERROR, "error: {}", error.message());
return false;
}
if (auto wif = std::getenv("SECRET_WIF_WALLET"); wif != nullptr) {
registry_.at(coin).address = nspv_api::login(registry_.at(coin).endpoint, wif).address;
if (auto_login) {
if (auto wif = std::getenv("SECRET_WIF_WALLET"); wif != nullptr) {
registry_.at(coin).address = nspv_api::login(registry_.at(coin).endpoint, wif).address;
}
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ namespace antara::gaming::blockchain {
static bool is_wif_wallet_exist() noexcept;

bool spawn_nspv_instance(const std::string &coin,
bool auto_login = false,
std::optional<std::size_t> rpcport_in = std::nullopt) noexcept;

double get_balance(const std::string& coin) const noexcept;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace antara::gaming::blockchain::tests {
antara::gaming::ecs::system_manager mgr{entity_registry};

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

Expand Down

0 comments on commit 02634f5

Please sign in to comment.