Show total staked and unlocking amounts in cli balance

E.g.:

    [wallet T6TSSZ (has locked stakes)]: balance
    Currently selected account: [0] Primary account
    Tag: (No tag assigned)
    Balance: 73541.719401728, unlocked balance: 72339.332202963 (23 block(s) to unlock)
    Total staked: 919.987654321, 0.000000000 unlocking
    Pending SN rewards: 49.419920278,  (next payout: block 10433, in about 26 minutes)
This commit is contained in:
Jason Rhinelander 2022-06-10 22:17:15 -03:00
parent dd30873e19
commit f487affdd9
No known key found for this signature in database
GPG Key ID: C4992CE7A88D4262
4 changed files with 24 additions and 37 deletions

View File

@ -5061,16 +5061,30 @@ bool simple_wallet::show_balance_unlocked(bool detailed)
std::map<uint32_t, uint64_t> balance_per_subaddress = m_wallet->balance_per_subaddress(m_current_subaddress_account, false);
std::map<uint32_t, std::pair<uint64_t, std::pair<uint64_t, uint64_t>>> unlocked_balance_per_subaddress = m_wallet->unlocked_balance_per_subaddress(m_current_subaddress_account, false);
if (m_current_subaddress_account == 0) { // Only the primary account can earn rewards, currently
if (m_current_subaddress_account == 0) { // Only the primary account can stake and earn rewards, currently
if (auto stakes = m_wallet->get_staked_service_nodes(); !stakes.empty()) {
auto my_addr = m_wallet->get_address_as_str();
uint64_t total_staked = 0, stakes_unlocking = 0;
for (auto& stake : stakes)
for (auto& contr : stake.contributors)
if (contr.address == my_addr)
{
total_staked += contr.amount;
if (stake.requested_unlock_height > 0)
stakes_unlocking += contr.amount;
}
success_msg_writer() << fmt::format(tr("Total staked: {}, {} unlocking"), print_money(total_staked), print_money(stakes_unlocking));
}
if (uint64_t batched_amount = m_wallet->get_batched_amount(); batched_amount > 0)
{
uint64_t next_payout_block = m_wallet->get_next_batch_payout();
uint64_t blockchain_height = m_wallet->get_blockchain_current_height();
std::string next_batch_payout = next_payout_block > 0
? fmt::format(" (next payout: block {}, in about {})",
? fmt::format(tr(" (next payout: block {}, in about {})"),
next_payout_block,
tools::get_human_readable_timespan((next_payout_block - blockchain_height) * TARGET_BLOCK_TIME))
: " (next payout: unknown)";
: tr(" (next payout: unknown)");
success_msg_writer() << tr("Pending SN rewards: ")
<< print_money(batched_amount) << ", "
<< next_batch_payout;
@ -6275,9 +6289,8 @@ bool simple_wallet::query_locked_stakes(bool print_result)
std::string msg_buf;
{
using namespace cryptonote;
auto response = m_wallet->list_current_stakes();
for (rpc::GET_SERVICE_NODES::response::entry const &node_info : response)
for (const auto &node_info : m_wallet->get_staked_service_nodes())
{
bool only_once = true;
for (const auto& contributor : node_info.contributors)

View File

@ -1080,7 +1080,7 @@ std::vector<Wallet::stake_info>* WalletImpl::listCurrentStakes() const
{
auto* stakes = new std::vector<Wallet::stake_info>;
auto response = wallet()->list_current_stakes();
auto response = wallet()->get_staked_service_nodes();
auto main_addr = mainAddress();
for (const auto& node_info : response)

View File

@ -12948,37 +12948,10 @@ uint64_t wallet2::get_approximate_blockchain_height() const
return approx_blockchain_height;
}
std::vector<rpc::GET_SERVICE_NODES::response::entry> wallet2::list_current_stakes()
std::vector<rpc::GET_SERVICE_NODES::response::entry> wallet2::get_staked_service_nodes()
{
std::vector<rpc::GET_SERVICE_NODES::response::entry> service_node_states;
auto [success, all_nodes] = this->get_all_service_nodes();
if (!success)
{
return service_node_states;
}
const auto primary_address = this->get_address();
for (auto& node_info : all_nodes)
{
for (const auto& contributor : node_info.contributors)
{
address_parse_info address_info = {};
if (!cryptonote::get_account_address_from_str(address_info, this->nettype(), contributor.address))
{
continue;
}
if (primary_address != address_info.address)
continue;
service_node_states.push_back(std::move(node_info));
break;
}
}
return service_node_states;
auto [success, contributed_nodes] = m_node_rpc_proxy.get_contributed_service_nodes(get_address_as_str());
return std::move(contributed_nodes);
}
void wallet2::set_ons_cache_record(wallet2::ons_detail detail)

View File

@ -830,7 +830,8 @@ private:
auto get_all_service_nodes() const { return m_node_rpc_proxy.get_all_service_nodes(); }
auto get_service_nodes(std::vector<std::string> const &pubkeys) const { return m_node_rpc_proxy.get_service_nodes(pubkeys); }
auto get_service_node_blacklisted_key_images() const { return m_node_rpc_proxy.get_service_node_blacklisted_key_images(); }
std::vector<cryptonote::rpc::GET_SERVICE_NODES::response::entry> list_current_stakes();
// List of service nodes this wallet has a stake in:
std::vector<cryptonote::rpc::GET_SERVICE_NODES::response::entry> get_staked_service_nodes();
auto ons_owners_to_names(cryptonote::rpc::ONS_OWNERS_TO_NAMES::request const &request) const { return m_node_rpc_proxy.ons_owners_to_names(request); }
auto ons_names_to_owners(cryptonote::rpc::ONS_NAMES_TO_OWNERS::request const &request) const { return m_node_rpc_proxy.ons_names_to_owners(request); }
auto resolve(cryptonote::rpc::ONS_RESOLVE::request const &request) const { return m_node_rpc_proxy.ons_resolve(request); }