From 1c76d0d325fd60f4824205352cff3d0dd0bbff10 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Fri, 16 Sep 2022 18:35:36 +0200 Subject: [PATCH] added balance() and rpc api implementations for multi_assets versions --- src/wallet/wallet2.cpp | 8 ++++---- src/wallet/wallet2.h | 2 +- src/wallet/wallet_rpc_server.cpp | 4 ++-- tests/core_tests/chaingen_main.cpp | 11 ++++++++--- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 386d2dfc..83e62a3d 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -3009,7 +3009,7 @@ uint64_t wallet2::balance(uint64_t& unlocked, uint64_t& awaiting_in, uint64_t& a awaiting_in = 0; awaiting_out = 0; mined = 0; - std::unordered_map balances; + std::unordered_map balances; balance(balances, mined); auto it = balances.find(currency::null_hash); if (it != balances.end()) @@ -3022,7 +3022,7 @@ uint64_t wallet2::balance(uint64_t& unlocked, uint64_t& awaiting_in, uint64_t& a return total; } //---------------------------------------------------------------------------------------------------- -bool wallet2::balance(std::unordered_map& balances, uint64_t& mined) const +bool wallet2::balance(std::unordered_map& balances, uint64_t& mined) const { mined = 0; @@ -3030,7 +3030,7 @@ bool wallet2::balance(std::unordered_map { if (td.is_spendable() || (td.is_reserved_for_escrow() && !td.is_spent())) { - asset_balance_entry_base& e = balances[td.get_asset_id()]; + wallet_public::asset_balance_entry_base& e = balances[td.get_asset_id()]; e.total += td.amount(); if (is_transfer_unlocked(td)) e.unlocked += td.amount(); @@ -3041,7 +3041,7 @@ bool wallet2::balance(std::unordered_map for(auto& utx : m_unconfirmed_txs) { - asset_balance_entry_base& e = balances[utx.asset_id]; + wallet_public::asset_balance_entry_base& e = balances[utx.second.asset_id]; if (utx.second.is_income) { e.total += utx.second.amount; diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index ccfc636a..277336a2 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -597,7 +597,7 @@ namespace tools std::shared_ptr get_core_proxy(); uint64_t balance() const; uint64_t balance(uint64_t& unloked, uint64_t& awaiting_in, uint64_t& awaiting_out, uint64_t& mined) const; - bool balance(std::unordered_map& balances, uint64_t& mined) const; + bool balance(std::unordered_map& balances, uint64_t& mined) const; uint64_t balance(uint64_t& unloked) const; uint64_t unlocked_balance() const; diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp index 20f6bcc8..9ecf1008 100644 --- a/src/wallet/wallet_rpc_server.cpp +++ b/src/wallet/wallet_rpc_server.cpp @@ -189,7 +189,7 @@ namespace tools res.balance = m_wallet.balance(); res.unlocked_balance = m_wallet.unlocked_balance(); uint64_t mined = 0; - std::unordered_map balances; + std::unordered_map balances; m_wallet.balance(balances, mined); auto it = balances.find(currency::null_hash); if (it != balances.end()) @@ -200,7 +200,7 @@ namespace tools for (auto el : balances) { res.balances.push_back(wallet_public::asset_balance_entry()); - res.balances.back() = el.second; + static_cast(res.balances.back()) = el.second; res.balances.back().asset_id = el.first; } } diff --git a/tests/core_tests/chaingen_main.cpp b/tests/core_tests/chaingen_main.cpp index 8c3dc903..f5feb5c9 100644 --- a/tests/core_tests/chaingen_main.cpp +++ b/tests/core_tests/chaingen_main.cpp @@ -28,6 +28,7 @@ namespace const command_line::arg_descriptor arg_test_transactions ("test-transactions", ""); const command_line::arg_descriptor arg_run_single_test ("run-single-test", "" ); const command_line::arg_descriptor arg_enable_debug_asserts ("enable-debug-asserts", "" ); + const command_line::arg_descriptor arg_stop_on_fail ("stop-on-fail", ""); boost::program_options::variables_map g_vm; } @@ -671,13 +672,14 @@ int main(int argc, char* argv[]) command_line::add_arg(desc_options, arg_test_transactions); command_line::add_arg(desc_options, arg_run_single_test); command_line::add_arg(desc_options, arg_enable_debug_asserts); + command_line::add_arg(desc_options, arg_stop_on_fail); command_line::add_arg(desc_options, command_line::arg_data_dir, std::string(".")); command_line::add_arg(desc_options, command_line::arg_stop_after_height); command_line::add_arg(desc_options, command_line::arg_disable_ntp); currency::core::init_options(desc_options); tools::db::db_backend_selector::init_options(desc_options); - + bool stop_on_first_fail = false; bool r = command_line::handle_error_helper(desc_options, [&]() { po::store(po::parse_command_line(argc, argv, desc_options), g_vm); @@ -693,6 +695,11 @@ int main(int argc, char* argv[]) return 0; } + if (command_line::has_arg(g_vm, arg_stop_on_fail)) + { + stop_on_first_fail = command_line::get_arg(g_vm, arg_stop_on_fail); + } + size_t tests_count = 0; size_t serious_failures_count = 0; std::set failed_tests; @@ -756,8 +763,6 @@ int main(int argc, char* argv[]) #undef MARK_TEST_AS_POSTPONED - bool stop_on_first_fail = false; - // TODO // GENERATE_AND_PLAY(wallet_spend_form_auditable_and_track);