Limit NFT object count returned

This commit is contained in:
timur 2022-12-14 08:33:11 -04:00
parent 1bf5c82101
commit b228e5bea5
4 changed files with 21 additions and 11 deletions

View file

@ -269,7 +269,7 @@ public:
uint64_t nft_get_total_supply(const nft_metadata_id_type nft_metadata_id) const; uint64_t nft_get_total_supply(const nft_metadata_id_type nft_metadata_id) const;
nft_object nft_token_by_index(const nft_metadata_id_type nft_metadata_id, const uint64_t token_idx) const; nft_object nft_token_by_index(const nft_metadata_id_type nft_metadata_id, const uint64_t token_idx) const;
nft_object nft_token_of_owner_by_index(const nft_metadata_id_type nft_metadata_id, const account_id_type owner, const uint64_t token_idx) const; nft_object nft_token_of_owner_by_index(const nft_metadata_id_type nft_metadata_id, const account_id_type owner, const uint64_t token_idx) const;
vector<nft_object> nft_get_all_tokens() const; vector<nft_object> nft_get_all_tokens(const nft_id_type lower_id, uint32_t limit) const;
vector<nft_object> nft_get_tokens_by_owner(const account_id_type owner) const; vector<nft_object> nft_get_tokens_by_owner(const account_id_type owner) const;
// Marketplace // Marketplace
@ -291,6 +291,7 @@ public:
uint32_t api_limit_get_limit_orders_by_account = 101; uint32_t api_limit_get_limit_orders_by_account = 101;
uint32_t api_limit_get_order_book = 50; uint32_t api_limit_get_order_book = 50;
uint32_t api_limit_all_offers_count = 100; uint32_t api_limit_all_offers_count = 100;
uint32_t api_limit_nft_tokens = 100;
uint32_t api_limit_lookup_accounts = 1000; uint32_t api_limit_lookup_accounts = 1000;
uint32_t api_limit_lookup_witness_accounts = 1000; uint32_t api_limit_lookup_witness_accounts = 1000;
uint32_t api_limit_lookup_committee_member_accounts = 1000; uint32_t api_limit_lookup_committee_member_accounts = 1000;
@ -3102,16 +3103,20 @@ nft_object database_api_impl::nft_token_of_owner_by_index(const nft_metadata_id_
return {}; return {};
} }
vector<nft_object> database_api::nft_get_all_tokens() const { vector<nft_object> database_api::nft_get_all_tokens(const nft_id_type lower_id, uint32_t limit) const {
return my->nft_get_all_tokens(); return my->nft_get_all_tokens(lower_id, limit);
} }
vector<nft_object> database_api_impl::nft_get_all_tokens() const { vector<nft_object> database_api_impl::nft_get_all_tokens(const nft_id_type lower_id, uint32_t limit) const {
FC_ASSERT(limit <= api_limit_nft_tokens,
"Number of querying nft tokens can not be greater than ${configured_limit}",
("configured_limit", api_limit_nft_tokens));
const auto &idx_nft = _db.get_index_type<nft_index>().indices().get<by_id>(); const auto &idx_nft = _db.get_index_type<nft_index>().indices().get<by_id>();
vector<nft_object> result; vector<nft_object> result;
for (auto itr = idx_nft.begin(); itr != idx_nft.end(); ++itr) { result.reserve(limit);
result.push_back(*itr); auto itr = idx_nft.lower_bound(lower_id);
} while (limit-- && itr != idx_nft.end())
result.emplace_back(*itr++);
return result; return result;
} }

View file

@ -1027,7 +1027,7 @@ public:
* @brief Returns list of all available NTF's * @brief Returns list of all available NTF's
* @return List of all available NFT's * @return List of all available NFT's
*/ */
vector<nft_object> nft_get_all_tokens() const; vector<nft_object> nft_get_all_tokens(const nft_id_type lower_id, uint32_t limit) const;
/** /**
* @brief Returns NFT's owned by owner * @brief Returns NFT's owned by owner

View file

@ -2571,9 +2571,11 @@ class wallet_api
/** /**
* @brief Returns all tokens * @brief Returns all tokens
* @param limit the maximum number of NFT objects to return (max: 100)
* @param lowerbound the symbol of the first NFT object to include in the list.
* @return Returns vector of NFT objects, empty vector if none * @return Returns vector of NFT objects, empty vector if none
*/ */
vector<nft_object> nft_get_all_tokens() const; vector<nft_object> nft_get_all_tokens(uint32_t limit, optional<nft_id_type> lower_id) const;
signed_transaction nft_lottery_buy_ticket( nft_metadata_id_type lottery, account_id_type buyer, uint64_t tickets_to_buy, bool broadcast ); signed_transaction nft_lottery_buy_ticket( nft_metadata_id_type lottery, account_id_type buyer, uint64_t tickets_to_buy, bool broadcast );
signed_transaction create_offer(set<nft_id_type> item_ids, signed_transaction create_offer(set<nft_id_type> item_ids,

View file

@ -7027,9 +7027,12 @@ bool wallet_api::nft_is_approved_for_all(string owner_account_id_or_name, string
return my->_remote_db->nft_is_approved_for_all(owner_account.id, operator_account.id); return my->_remote_db->nft_is_approved_for_all(owner_account.id, operator_account.id);
} }
vector<nft_object> wallet_api::nft_get_all_tokens() const vector<nft_object> wallet_api::nft_get_all_tokens(uint32_t limit, optional<nft_id_type> lower_id) const
{ {
return my->_remote_db->nft_get_all_tokens(); nft_id_type lb_id;
if(lower_id)
lb_id = *lower_id;
return my->_remote_db->nft_get_all_tokens(lb_id, limit);
} }
signed_transaction wallet_api::nft_lottery_buy_ticket( nft_metadata_id_type lottery, account_id_type buyer, uint64_t tickets_to_buy, bool broadcast ) signed_transaction wallet_api::nft_lottery_buy_ticket( nft_metadata_id_type lottery, account_id_type buyer, uint64_t tickets_to_buy, bool broadcast )