Skip to content

Commit

Permalink
feat(nspv): finish get balance nspv system call
Browse files Browse the repository at this point in the history
  • Loading branch information
Milerius committed Nov 19, 2019
1 parent 0f3b554 commit be34a58
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
10 changes: 10 additions & 0 deletions modules/blockchain/antara/gaming/blockchain/nspv.system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ 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;
}
return true;
}

Expand All @@ -84,11 +87,18 @@ namespace antara::gaming::blockchain {
}

void nspv::set_pin_for_the_session(const std::string &pin) {
LOG_SCOPE_FUNCTION(INFO);
pin_ = std::stoi(pin);
is_pin_set_for_the_session_ = true;
}

const std::string &nspv::get_endpoint(const std::string& coin) const noexcept {
LOG_SCOPE_FUNCTION(INFO);
return registry_.at(coin).endpoint;
}

double nspv::get_balance(const std::string &coin) const noexcept {
LOG_SCOPE_FUNCTION(INFO);
return nspv_api::listunspent(get_endpoint(coin), registry_.at(coin).address).balance;
}
}
2 changes: 2 additions & 0 deletions modules/blockchain/antara/gaming/blockchain/nspv.system.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ namespace antara::gaming::blockchain {
bool spawn_nspv_instance(const std::string &coin,
std::optional<std::size_t> rpcport_in = std::nullopt) noexcept;

double get_balance(const std::string& coin) const noexcept;


const std::string& get_endpoint(const std::string& coin) const noexcept;
~nspv() noexcept final;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,7 @@ namespace antara::gaming::blockchain::tests {
auto unspent_answer = blockchain::nspv_api::listunspent(endpoint, answer.address);
CHECK_NE(unspent_answer.rpc_result_code, -1);
CHECK_GT(unspent_answer.balance, 0.0);

CHECK_GT(nspv_system.get_balance("RICK"), 0.0);
}
}

0 comments on commit be34a58

Please sign in to comment.