From aa31de5d44e12851a4ae8d80873aae2ca633542f Mon Sep 17 00:00:00 2001 From: Sandip Patel Date: Fri, 20 Sep 2019 17:51:43 +0530 Subject: [PATCH] Added get_asset_count API --- libraries/app/database_api.cpp | 10 ++++++++++ libraries/app/include/graphene/app/database_api.hpp | 7 +++++++ libraries/wallet/include/graphene/wallet/wallet.hpp | 7 +++++++ libraries/wallet/wallet.cpp | 5 +++++ 4 files changed, 29 insertions(+) diff --git a/libraries/app/database_api.cpp b/libraries/app/database_api.cpp index d75b1fcff..8f7f8007a 100644 --- a/libraries/app/database_api.cpp +++ b/libraries/app/database_api.cpp @@ -103,6 +103,7 @@ class database_api_impl : public std::enable_shared_from_this vector> get_assets(const vector& asset_ids)const; vector list_assets(const string& lower_bound_symbol, uint32_t limit)const; vector> lookup_asset_symbols(const vector& symbols_or_ids)const; + uint64_t get_asset_count()const; // Peerplays vector list_sports() const; @@ -1022,6 +1023,15 @@ vector> database_api_impl::lookup_asset_symbols(const vec return result; } +uint64_t database_api::get_asset_count()const +{ + return my->get_asset_count(); +} + +uint64_t database_api_impl::get_asset_count()const +{ + return _db.get_index_type().indices().size(); +} //////////////////// // Lottery Assets // //////////////////// diff --git a/libraries/app/include/graphene/app/database_api.hpp b/libraries/app/include/graphene/app/database_api.hpp index 6f90938d5..78a9ca1f9 100644 --- a/libraries/app/include/graphene/app/database_api.hpp +++ b/libraries/app/include/graphene/app/database_api.hpp @@ -342,6 +342,12 @@ class database_api * This function has semantics identical to @ref get_objects */ vector> lookup_asset_symbols(const vector& symbols_or_ids)const; + + /** + * @brief Get assets count + * @return The assets count + */ + uint64_t get_asset_count()const; //////////////////// // Lottery Assets // @@ -727,6 +733,7 @@ FC_API(graphene::app::database_api, (get_assets) (list_assets) (lookup_asset_symbols) + (get_asset_count) // Peerplays (list_sports) diff --git a/libraries/wallet/include/graphene/wallet/wallet.hpp b/libraries/wallet/include/graphene/wallet/wallet.hpp index 5618d26a1..6b0f4e907 100644 --- a/libraries/wallet/include/graphene/wallet/wallet.hpp +++ b/libraries/wallet/include/graphene/wallet/wallet.hpp @@ -348,6 +348,12 @@ class wallet_api * @returns the list of asset objects, ordered by symbol */ vector list_assets(const string& lowerbound, uint32_t limit)const; + + /** Returns assets count registered on the blockchain. + * + * @returns assets count + */ + uint64_t get_asset_count()const; vector get_lotteries( asset_id_type stop = asset_id_type(), @@ -1925,6 +1931,7 @@ FC_API( graphene::wallet::wallet_api, (list_accounts) (list_account_balances) (list_assets) + (get_asset_count) (import_key) (import_accounts) (import_account_keys) diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index 6acbacf0c..548a1882b 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -3429,6 +3429,11 @@ vector wallet_api::list_assets(const string& lowerbound, uint32_t return my->_remote_db->list_assets( lowerbound, limit ); } +uint64_t wallet_api::get_asset_count()const +{ + return my->_remote_db->get_asset_count(); +} + vector wallet_api::get_lotteries( asset_id_type stop, unsigned limit, asset_id_type start )const