From 1c52911757e9b9cbb86cbfce37c6dcaa1ef03c02 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Mon, 28 Nov 2022 22:10:50 +0100 Subject: [PATCH] added asset_id for UI_to_wallet api, added preloading whitelist for wallet before balance request --- src/wallet/view_iface.h | 2 ++ src/wallet/wallet2.cpp | 5 +++-- src/wallet/wallet2.h | 6 +++--- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/wallet/view_iface.h b/src/wallet/view_iface.h index 85bb353e..70d60bfe 100644 --- a/src/wallet/view_iface.h +++ b/src/wallet/view_iface.h @@ -35,10 +35,12 @@ namespace view { std::string address; std::string amount; + crypto::hash asset_id; BEGIN_KV_SERIALIZE_MAP() KV_SERIALIZE(address) KV_SERIALIZE(amount) + KV_SERIALIZE_POD_AS_HEX_STRING(asset_id) END_KV_SERIALIZE_MAP() }; diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 40fcc45f..163fdb24 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -3144,6 +3144,7 @@ bool wallet2::balance(std::unordered_map& balances, uint64_t& mined) const { + load_whitelisted_tokens_if_not_loaded(); std::unordered_map balances_map; this->balance(balances_map, mined); for (const auto& item : balances_map) @@ -3221,7 +3222,7 @@ bool wallet2::delete_custom_asset_id(const crypto::hash& asset_id) return true; } //---------------------------------------------------------------------------------------------------- -bool wallet2::load_whitelisted_tokens() +bool wallet2::load_whitelisted_tokens() const { m_whitelisted_assets.clear(); std::string body; @@ -3236,7 +3237,7 @@ bool wallet2::load_whitelisted_tokens() return true; } //---------------------------------------------------------------------------------------------------- -bool wallet2::load_whitelisted_tokens_if_not_loaded() +bool wallet2::load_whitelisted_tokens_if_not_loaded() const { if (m_whitelisted_assets.size()) { diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index 4fb11e6f..8a458de4 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -901,8 +901,8 @@ namespace tools bool add_custom_asset_id(const crypto::hash& asset_id); bool delete_custom_asset_id(const crypto::hash& asset_id); - bool load_whitelisted_tokens_if_not_loaded(); - bool load_whitelisted_tokens(); + bool load_whitelisted_tokens_if_not_loaded() const; + bool load_whitelisted_tokens()const; /* create_htlc_proposal: if htlc_hash == null_hash, then this wallet is originator of the atomic process, and @@ -1101,7 +1101,7 @@ private: std::unordered_map m_tx_keys; std::unordered_map m_own_asset_descriptors; std::unordered_map m_custom_assets; //assets that manually added by user - std::unordered_map m_whitelisted_assets; //assets that manually added by user + mutable std::unordered_map m_whitelisted_assets; //assets that whitelisted std::multimap m_htlcs; //map [expired_if_more_then] -> height of expiration