From f07d3942e141fac61aee75552afcf108ae0f3cb0 Mon Sep 17 00:00:00 2001 From: Some Random Crypto Guy Date: Sat, 22 Jun 2024 19:40:19 +0100 Subject: [PATCH] fixed stake returned wallet balance; updated yield_info and supply_info commands --- src/blockchain_db/lmdb/db_lmdb.cpp | 3 ++- src/simplewallet/simplewallet.cpp | 6 +++--- src/version.cpp.in | 2 +- src/wallet/wallet2.cpp | 21 ++++++++++++++------- 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/blockchain_db/lmdb/db_lmdb.cpp b/src/blockchain_db/lmdb/db_lmdb.cpp index f990950f1..3da4e5391 100644 --- a/src/blockchain_db/lmdb/db_lmdb.cpp +++ b/src/blockchain_db/lmdb/db_lmdb.cpp @@ -1381,7 +1381,7 @@ void BlockchainLMDB::remove_transaction_data(const crypto::hash& tx_hash, const LOG_PRINT_L1("tx ID " << tip->data.tx_id << "\n\tTally before burn = " << source_tally.str() << "\n\tTally after burn = " << final_source_tally.str()); } - if (tx.type == cryptonote::transaction_type::CONVERT || tx.type == cryptonote::transaction_type::BURN || tx.type == cryptonote::transaction_type::STAKE) { + if (tx.type == cryptonote::transaction_type::BURN || tx.type == cryptonote::transaction_type::CONVERT || tx.type == cryptonote::transaction_type::STAKE) { // Get the current tally value for the source currency type MDB_val_copy source_idx(cryptonote::asset_id_from_type(tx.source_asset_type)); @@ -3502,6 +3502,7 @@ std::map BlockchainLMDB::get_circulating_supply() const if (circulating_supply.empty()) { circulating_supply["SAL"] = m_coinbase; } + circulating_supply["BURN"] = m_coinbase - circulating_supply["SAL"]; return circulating_supply; } diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index 03584a6f3..ca43430a1 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -8370,7 +8370,7 @@ bool simple_wallet::supply_info(const std::vector &args) { //supply_128 /= COIN; uint64_t supply = supply_128.convert_to(); - message_writer(console_color_default, false) << boost::format(tr("\t%s\t:\t%d")) % supply_asset.first % print_money(supply); + message_writer(console_color_default, false) << boost::format(tr("\t%6s : %21.8d")) % supply_asset.first % print_money(supply); /* // get price @@ -8431,8 +8431,8 @@ bool simple_wallet::yield_info(const std::vector &args) { } // Output the necessary information about yield stats - message_writer(console_color_default, false) << boost::format(tr("YIELD INFO:\n\tTotal SAL supply: %d\n\tTotal coins burnt: %d\n\tTotal coins locked: %d\n\tYield accrued over last %s: %d\n\tYield per SAL staked: %d")) - % print_money(total_supply_128.convert_to()) + 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) diff --git a/src/version.cpp.in b/src/version.cpp.in index 5f278e08c..6db1665f6 100644 --- a/src/version.cpp.in +++ b/src/version.cpp.in @@ -1,5 +1,5 @@ #define DEF_SALVIUM_VERSION_TAG "7f6b8da" -#define DEF_SALVIUM_VERSION "0.3.0" +#define DEF_SALVIUM_VERSION "0.3.1" #define DEF_MONERO_VERSION_TAG "@VERSIONTAG@" #define DEF_MONERO_VERSION "0.18.3.3" #define DEF_MONERO_RELEASE_NAME "Zero" diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index b007709df..7b0a5c4b8 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -2543,12 +2543,6 @@ void wallet2::process_new_transaction(const crypto::hash &txid, const cryptonote bool ok = m_account.get_device().derive_subaddress_public_key(output_public_key, derivation, i, pk_change); THROW_WALLET_EXCEPTION_IF(!ok, error::wallet_internal_error, "Failed to derive subaddress public key for TRANSFER TX"); - // Find the TX public key for P_change - //auto search = m_salvium_txs.find(pk_change); - //if (search != m_salvium_txs.end()) { - // Store the origin index for the TX - this is needed when we want to SPEND the returned funds - - check_acc_out_precomp_once(tx.vout[i], derivation, additional_derivations, i, is_out_data_ptr, tx_scan_info[i], output_found[i]); THROW_WALLET_EXCEPTION_IF(tx_scan_info[i].error, error::acc_outs_lookup_error, tx, tx_pub_key, m_account.get_keys()); if (tx_scan_info[i].received) @@ -2564,6 +2558,19 @@ void wallet2::process_new_transaction(const crypto::hash &txid, const cryptonote // Copy the origin TD td_origin_idx = tx_scan_info[i].origin_idx; + + if (tx.type == cryptonote::transaction_type::PROTOCOL) { + + THROW_WALLET_EXCEPTION_IF(td_origin_idx >= get_num_transfer_details(), error::wallet_internal_error, "cannot locate protocol TX origin in m_transfers"); + const transfer_details& td_origin = get_transfer_details(td_origin_idx); + THROW_WALLET_EXCEPTION_IF(td_origin.m_tx.type != cryptonote::transaction_type::STAKE, error::wallet_internal_error, "incorrect TX type for protocol_tx origin in m_transfers"); + + // Get the output key for the change entry + crypto::public_key pk_locked_coins = crypto::null_pkey; + THROW_WALLET_EXCEPTION_IF(!get_output_public_key(td_origin.m_tx.vout[td_origin.m_internal_output_index], pk_locked_coins), error::wallet_internal_error, "Failed to get output public key for locked coins"); + // At this point, we need to clear the "locked coins" count, because otherwise we will be counting yield stakes twice in our balance + THROW_WALLET_EXCEPTION_IF(!m_locked_coins.erase(pk_locked_coins), error::wallet_internal_error, "Failed to remove protocol_tx entry from m_locked_coins"); + } } } } @@ -2691,7 +2698,7 @@ void wallet2::process_new_transaction(const crypto::hash &txid, const cryptonote if (tx.type == cryptonote::transaction_type::STAKE) { // Additionally, with YIELD TXs, we need to update our "balance staked" subtotal, because otherwise our balance is out by the staked coins until they mature! // SRCG: must remember to deduct the number of staked coins when they mature!! - LOG_ERROR("***** STAKED COINS : " << tx.amount_burnt << " *****"); + LOG_PRINT_L1("***** STAKED COINS : " << tx.amount_burnt << " *****"); m_locked_coins.insert({P_change, {0, tx.amount_burnt}}); }