diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index e43c628..77f4ad9 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -8394,86 +8394,42 @@ bool simple_wallet::supply_info(const std::vector &args) { //---------------------------------------------------------------------------------------------------- bool simple_wallet::yield_info(const std::vector &args) { - // Get the total circulating supply of SALs - std::vector> supply_amounts; - if(!m_wallet->get_circulating_supply(supply_amounts)) { - fail_msg_writer() << "failed to get circulating supply. Make sure you are connected to a daemon."; - return false; - } - boost::multiprecision::uint128_t total_supply_128 = 0; - for (auto supply_asset: supply_amounts) { - if (supply_asset.first == "SAL") { - boost::multiprecision::uint128_t supply_128(supply_asset.second); - total_supply_128 = supply_128; - break; - } - } + // EXPERIMENTAL - change to get_yield_summary_info() method + uint64_t t_burnt, t_supply, t_locked, t_yield, yps, ybi_size; + std::vector> yield_payouts; + bool ok = m_wallet->get_yield_summary_info(t_burnt, t_supply, t_locked, t_yield, yps, ybi_size, yield_payouts); - // Get the yield data from the blockchain - std::vector ybi_data; - bool r = m_wallet->get_yield_info(ybi_data); - if (!r) - return false; - - // Scan the entries we have received to gather the state (total yield over period captured) - uint64_t total_burnt = 0; - uint64_t total_yield = 0; - uint64_t yield_per_stake = 0; - for (size_t idx=1; idx 0) { - boost::multiprecision::uint128_t yield_per_stake_128 = ybi_data.back().slippage_total_this_block; - yield_per_stake_128 *= COIN; - yield_per_stake_128 /= ybi_data.back().locked_coins_tally; - yield_per_stake = yield_per_stake_128.convert_to(); - } + // Get the chain height + const uint64_t blockchain_height = m_wallet->get_blockchain_current_height(); - // Output the necessary information about yield stats - message_writer(console_color_default, false) << boost::format(tr("YIELD INFO:\n\tSupply coins burnt over last %s: %d\n\tTotal coins locked: %d\n\tYield accrued over last %s: %d\n\tYield per SAL staked: %d")) - % get_human_readable_timespan((ybi_data.size()-1) * DIFFICULTY_TARGET_V2) - % print_money(total_burnt) - % print_money(ybi_data.back().locked_coins_tally) - % get_human_readable_timespan((ybi_data.size()-1) * DIFFICULTY_TARGET_V2) - % print_money(total_yield) - % print_money(yield_per_stake); - - // Now summarise our own YIELD TXs that are yet to mature - tools::wallet2::transfer_container transfers; - m_wallet->get_transfers(transfers); - if (transfers.empty()) - return true; - - std::map payouts; message_writer(console_color_default, false) << boost::format(tr("\nSTAKED FUNDS:")); - for (size_t idx = transfers.size()-1; idx>0; --idx) { - const tools::wallet2::transfer_details& td = transfers[idx]; - //if (td.m_block_height < ybi_data[0].block_height) break; - if (td.m_tx.type == cryptonote::transaction_type::STAKE) { - if (payouts.count(idx)) { - message_writer(console_color_green, true) << boost::format(tr("Height %d, txid %s, staked %s SAL, earned %s SAL")) - % td.m_block_height - % td.m_txid - % print_money(td.m_tx.amount_burnt) - % print_money(transfers[payouts[idx]].m_amount - td.m_tx.amount_burnt); - } else { - message_writer(console_color_green, false) << boost::format(tr("Height %d, txid %s, staked %s SAL")) - % td.m_block_height - % td.m_txid - % print_money(td.m_tx.amount_burnt); - } - } else if (td.m_tx.type == cryptonote::transaction_type::PROTOCOL) { - // Store list of reverse-lookup indices to tell YIELD TXs how much they earned - if (transfers[td.m_td_origin_idx].m_tx.type == cryptonote::transaction_type::STAKE) - payouts[td.m_td_origin_idx] = idx; - } - } + for (auto &p: yield_payouts) { + uint64_t height, burnt, yield; + std::string txid; + std::tie(height, txid, burnt, yield) = p; + if (blockchain_height > ybi_size + height) + message_writer(console_color_green, true) << boost::format(tr("Height %d, txid %s, staked %s SAL, earned %s SAL")) + % height + % txid + % print_money(burnt) + % print_money(yield); + else + message_writer(console_color_green, false) << boost::format(tr("Height %d, txid %s, staked %s SAL, %s SAL accrued so far")) + % height + % txid + % print_money(burnt) + % print_money(yield); + } + + // Output the necessary information about yield stats + message_writer(console_color_default, false) << boost::format(tr("\nYIELD INFO:\n\tSupply coins burnt over last %s: %d\n\tTotal coins locked: %d\n\tYield accrued over last %s: %d\n\tYield per SAL staked: %d")) + % get_human_readable_timespan((ybi_size-1) * DIFFICULTY_TARGET_V2) + % print_money(t_burnt) + % print_money(t_locked) + % get_human_readable_timespan((ybi_size-1) * DIFFICULTY_TARGET_V2) + % print_money(t_yield) + % print_money(yps); + return true; } //---------------------------------------------------------------------------------------------------- diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 8f5c966..6b0eb09 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -2411,6 +2411,27 @@ bool wallet2::get_yield_summary_info(uint64_t &total_burnt, return false; ybi_data_size = ybi_data.size(); + + // Iterate over the transfers in our wallet + std::map map_payouts; + std::map>> payouts_active; + for (size_t idx = m_transfers.size()-1; idx>0; --idx) { + const tools::wallet2::transfer_details& td = m_transfers[idx]; + //if (td.m_block_height < ybi_data[0].block_height) break; + if (td.m_tx.type == cryptonote::transaction_type::STAKE) { + if (map_payouts.count(idx)) { + payouts.push_back(std::make_tuple(td.m_block_height, epee::string_tools::pod_to_hex(td.m_txid), td.m_tx.amount_burnt, m_transfers[map_payouts[idx]].m_amount - td.m_tx.amount_burnt)); + } else { + //payouts.push_back(std::make_tuple(td.m_block_height, epee::string_tools::pod_to_hex(td.m_txid), td.m_tx.amount_burnt, 0)); + payouts_active[epee::string_tools::pod_to_hex(td.m_txid)] = std::make_pair(td.m_block_height, std::make_pair(td.m_tx.amount_burnt, 0)); + } + } else if (td.m_tx.type == cryptonote::transaction_type::PROTOCOL) { + // Store list of reverse-lookup indices to tell YIELD TXs how much they earned + if (m_transfers[td.m_td_origin_idx].m_tx.type == cryptonote::transaction_type::STAKE) + map_payouts[td.m_td_origin_idx] = idx; + } + } + // Scan the entries we have received to gather the state (total yield over period captured) total_burnt = 0; @@ -2421,9 +2442,23 @@ bool wallet2::get_yield_summary_info(uint64_t &total_burnt, total_burnt += ybi_data[idx].slippage_total_this_block; } else { total_yield += ybi_data[idx].slippage_total_this_block; + + // EXPERIMENTAL - add up yield earned for active STAKE TXs + for (auto &payout: payouts_active) { + if (ybi_data[idx].block_height < payout.second.first) continue; + boost::multiprecision::uint128_t amount_128 = ybi_data[idx].slippage_total_this_block; + amount_128 *= payout.second.second.first; + amount_128 /= ybi_data[idx].locked_coins_tally; + payout.second.second.second += amount_128.convert_to(); + } } } + for (auto &payout: payouts_active) { + // Copy to the list of payouts proper + payouts.push_back(std::make_tuple(payout.second.first, payout.first, payout.second.second.first, payout.second.second.second)); + } + // Get the total currently locked total_locked = ybi_data.back().locked_coins_tally; @@ -2434,7 +2469,7 @@ bool wallet2::get_yield_summary_info(uint64_t &total_burnt, yield_per_stake_128 /= ybi_data.back().locked_coins_tally; yield_per_stake = yield_per_stake_128.convert_to(); } - + /* // Iterate over the transfers in our wallet std::map map_payouts; for (size_t idx = m_transfers.size()-1; idx>0; --idx) { @@ -2452,7 +2487,7 @@ bool wallet2::get_yield_summary_info(uint64_t &total_burnt, map_payouts[td.m_td_origin_idx] = idx; } } - + */ // Return success to caller return true; }