Merge branch 'feature/nft' into feature/marketplace

This commit is contained in:
Srdjan Obucina 2020-07-16 14:15:15 +02:00
commit f1e9a79d0b
2 changed files with 50 additions and 2 deletions

View file

@ -195,6 +195,8 @@ class database_api_impl : public std::enable_shared_from_this<database_api_impl>
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_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_tokens_by_owner(const account_id_type owner) const;
// Marketplace
vector<offer_object> list_offers(const offer_id_type lower_id, uint32_t limit) const;
@ -2492,6 +2494,37 @@ nft_object database_api_impl::nft_token_of_owner_by_index(const nft_metadata_id_
return {};
}
vector<nft_object> database_api::nft_get_all_tokens() const
{
return my->nft_get_all_tokens();
}
vector<nft_object> database_api_impl::nft_get_all_tokens() const
{
const auto &idx_nft = _db.get_index_type<nft_index>().indices().get<by_id>();
vector<nft_object> result;
for (auto itr = idx_nft.begin(); itr != idx_nft.end(); ++itr) {
result.push_back(*itr);
}
return result;
}
vector<nft_object> database_api::nft_get_tokens_by_owner(const account_id_type owner) const
{
return my->nft_get_tokens_by_owner(owner);
}
vector<nft_object> database_api_impl::nft_get_tokens_by_owner(const account_id_type owner) const
{
const auto &idx_nft = _db.get_index_type<nft_index>().indices().get<by_owner>();
auto idx_nft_range = idx_nft.equal_range(owner);
vector<nft_object> result;
for (auto itr = idx_nft_range.first; itr != idx_nft_range.second; ++itr) {
result.push_back(*itr);
}
return result;
}
// Marketplace
vector<offer_object> database_api::list_offers(const offer_id_type lower_id, uint32_t limit) const
{

View file

@ -781,14 +781,27 @@ class database_api
nft_object nft_token_by_index(const nft_metadata_id_type nft_metadata_id, const uint64_t token_idx) const;
/**
* @brief Returns NFT URI
* @brief Returns NFT by owner and index
* @param nft_metadata_id NFT metadata ID
* @param owner NFT owner
* @param token_idx NFT index in the list of tokens
* @return NFT URI
* @return NFT object
*/
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;
/**
* @brief Returns list of all available NTF's
* @return List of all available NFT's
*/
vector<nft_object> nft_get_all_tokens() const;
/**
* @brief Returns NFT's owned by owner
* @param owner NFT owner
* @return List of NFT owned by owner
*/
vector<nft_object> nft_get_tokens_by_owner(const account_id_type owner) const;
//////////////////
// MARKET PLACE //
//////////////////
@ -950,6 +963,8 @@ FC_API(graphene::app::database_api,
(nft_get_total_supply)
(nft_token_by_index)
(nft_token_of_owner_by_index)
(nft_get_all_tokens)
(nft_get_tokens_by_owner)
// Marketplace
(list_offers)