1
0
Fork 0
forked from lthn/blockchain

chaingen, wallet: improved wallet transfers listing and balance checking when an asset is specified

This commit is contained in:
sowle 2025-03-06 14:21:59 +01:00
parent c5c206ea13
commit 79e3c6eaf1
No known key found for this signature in database
GPG key ID: C07A24B2D89D49FC
3 changed files with 16 additions and 7 deletions

View file

@ -3710,6 +3710,8 @@ uint64_t wallet2::balance(uint64_t& unlocked, uint64_t& awaiting_in, uint64_t& a
awaiting_in = it->second.awaiting_in;
awaiting_out = it->second.awaiting_out;
}
if (asset_id != native_coin_asset_id)
mined = 0;
return total;
}
//----------------------------------------------------------------------------------------------------
@ -5836,8 +5838,10 @@ struct local_transfers_struct
END_KV_SERIALIZE_MAP()
};
void wallet2::dump_trunsfers(std::stringstream& ss, bool verbose) const
void wallet2::dump_trunsfers(std::stringstream& ss, bool verbose, const crypto::public_key& asset_id) const
{
bool filter_by_asset_id = asset_id != currency::null_pkey;
if (verbose)
{
@ -5846,6 +5850,8 @@ void wallet2::dump_trunsfers(std::stringstream& ss, bool verbose) const
{
uint64_t i = tr.first;
const transfer_details& td = tr.second;
if (filter_by_asset_id && td.get_asset_id() != asset_id)
continue;
ss << "{ \"i\": " << i << "," << ENDL;
ss << "\"entry\": " << epee::serialization::store_t_to_json(td) << "}," << ENDL;
}
@ -5858,6 +5864,8 @@ void wallet2::dump_trunsfers(std::stringstream& ss, bool verbose) const
{
uint64_t i = tr.first;
const transfer_details& td = tr.second;
if (filter_by_asset_id && td.get_asset_id() != asset_id)
continue;
ss << std::right <<
std::setw(5) << i << " " <<
std::setw(21) << print_money(td.amount()) << " " <<
@ -5873,10 +5881,10 @@ void wallet2::dump_trunsfers(std::stringstream& ss, bool verbose) const
}
}
//----------------------------------------------------------------------------------------------------
std::string wallet2::dump_trunsfers(bool verbose) const
std::string wallet2::dump_trunsfers(bool verbose, const crypto::public_key& asset_id) const
{
std::stringstream ss;
dump_trunsfers(ss, verbose);
dump_trunsfers(ss, verbose, asset_id);
return ss.str();
}
//----------------------------------------------------------------------------------------------------

View file

@ -681,8 +681,9 @@ namespace tools
void accept_cancel_contract(const crypto::hash& contract_id, currency::transaction* p_cancellation_acceptance_tx = nullptr);
void scan_tx_to_key_inputs(std::vector<uint64_t>& found_transfers, const currency::transaction& tx);
void dump_trunsfers(std::stringstream& ss, bool verbose = true) const;
std::string dump_trunsfers(bool verbose = false) const;
// asset_id = null_pkey means no filtering by asset id
void dump_trunsfers(std::stringstream& ss, bool verbose = true, const crypto::public_key& asset_id = currency::null_pkey) const;
std::string dump_trunsfers(bool verbose = false, const crypto::public_key& asset_id = currency::null_pkey) const;
void dump_key_images(std::stringstream& ss);
void get_multisig_transfers(multisig_transfer_container& ms_transfers);
const multisig_transfer_container& get_multisig_transfers() const { return m_multisig_transfers; }

View file

@ -1,4 +1,4 @@
// Copyright (c) 2014-2024 Zano Project
// Copyright (c) 2014-2025 Zano Project
// Copyright (c) 2014-2018 The Louisdor Project
// Copyright (c) 2012-2013 The Cryptonote developers
// Distributed under the MIT/X11 software license, see the accompanying
@ -2153,7 +2153,7 @@ bool check_balance_via_wallet(const tools::wallet2& w, const char* account_name,
if (!r)
{
LOG_PRINT(account_name << "'s transfers: " << ENDL << w.dump_trunsfers(), LOG_LEVEL_0);
LOG_PRINT(account_name << "'s transfers for asset_id " << asset_id << ": " << ENDL << w.dump_trunsfers(false, asset_id), LOG_LEVEL_0);
}
return r;