ppy marketplace 8 - Add pagination for list APIs
This commit is contained in:
parent
e8ec6ae0e5
commit
d1f64ca919
5 changed files with 214 additions and 47 deletions
|
|
@ -197,11 +197,15 @@ class database_api_impl : public std::enable_shared_from_this<database_api_impl>
|
|||
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;
|
||||
|
||||
// Marketplace
|
||||
vector<offer_object> list_offers(uint32_t limit) const;
|
||||
vector<offer_object> list_sell_offers(uint32_t limit) const;
|
||||
vector<offer_object> list_buy_offers(uint32_t limit) const;
|
||||
vector<offer_object> get_offers_by_issuer(const account_id_type issuer_account_id, uint32_t limit) const;
|
||||
vector<offer_object> get_offers_by_item(nft_id_type item, uint32_t limit)const;
|
||||
vector<offer_object> list_offers(const offer_id_type lower_id, uint32_t limit) const;
|
||||
vector<offer_object> list_sell_offers(const offer_id_type lower_id, uint32_t limit) const;
|
||||
vector<offer_object> list_buy_offers(const offer_id_type lower_id, uint32_t limit) const;
|
||||
vector<offer_history_object> list_offer_history(const offer_history_id_type lower_id, uint32_t limit) const;
|
||||
vector<offer_object> get_offers_by_issuer(const offer_id_type lower_id, const account_id_type issuer_account_id, uint32_t limit) const;
|
||||
vector<offer_object> get_offers_by_item(const offer_id_type lower_id, const nft_id_type item, uint32_t limit) const;
|
||||
vector<offer_history_object> get_offer_history_by_issuer(const offer_history_id_type lower_id, const account_id_type issuer_account_id, uint32_t limit) const;
|
||||
vector<offer_history_object> get_offer_history_by_item(const offer_history_id_type lower_id, const nft_id_type item, uint32_t limit) const;
|
||||
vector<offer_history_object> get_offer_history_by_bidder(const offer_history_id_type lower_id, const account_id_type bidder_account_id, uint32_t limit) const;
|
||||
|
||||
//private:
|
||||
const account_object* get_account_from_string( const std::string& name_or_id,
|
||||
|
|
@ -2489,19 +2493,19 @@ nft_object database_api_impl::nft_token_of_owner_by_index(const nft_metadata_id_
|
|||
}
|
||||
|
||||
// Marketplace
|
||||
vector<offer_object> database_api::list_offers(uint32_t limit) const
|
||||
vector<offer_object> database_api::list_offers(const offer_id_type lower_id, uint32_t limit) const
|
||||
{
|
||||
return my->list_offers(limit);
|
||||
return my->list_offers(lower_id, limit);
|
||||
}
|
||||
|
||||
vector<offer_object> database_api_impl::list_offers(uint32_t limit) const
|
||||
vector<offer_object> database_api_impl::list_offers(const offer_id_type lower_id, uint32_t limit) const
|
||||
{
|
||||
FC_ASSERT( limit <= 100 );
|
||||
const auto& offers_idx = _db.get_index_type<offer_index>().indices().get<by_id>();
|
||||
vector<offer_object> result;
|
||||
result.reserve(limit);
|
||||
|
||||
auto itr = offers_idx.begin();
|
||||
auto itr = offers_idx.lower_bound(lower_id);
|
||||
|
||||
while(limit-- && itr != offers_idx.end())
|
||||
result.emplace_back(*itr++);
|
||||
|
|
@ -2509,19 +2513,19 @@ vector<offer_object> database_api_impl::list_offers(uint32_t limit) const
|
|||
return result;
|
||||
}
|
||||
|
||||
vector<offer_object> database_api::list_sell_offers(uint32_t limit) const
|
||||
vector<offer_object> database_api::list_sell_offers(const offer_id_type lower_id, uint32_t limit) const
|
||||
{
|
||||
return my->list_sell_offers(limit);
|
||||
return my->list_sell_offers(lower_id, limit);
|
||||
}
|
||||
|
||||
vector<offer_object> database_api_impl::list_sell_offers(uint32_t limit) const
|
||||
vector<offer_object> database_api_impl::list_sell_offers(const offer_id_type lower_id, uint32_t limit) const
|
||||
{
|
||||
FC_ASSERT( limit <= 100 );
|
||||
const auto& offers_idx = _db.get_index_type<offer_index>().indices().get<by_id>();
|
||||
vector<offer_object> result;
|
||||
result.reserve(limit);
|
||||
|
||||
auto itr = offers_idx.begin();
|
||||
auto itr = offers_idx.lower_bound(lower_id);
|
||||
|
||||
while(limit && itr != offers_idx.end())
|
||||
{
|
||||
|
|
@ -2535,19 +2539,19 @@ vector<offer_object> database_api_impl::list_sell_offers(uint32_t limit) const
|
|||
return result;
|
||||
}
|
||||
|
||||
vector<offer_object> database_api::list_buy_offers(uint32_t limit) const
|
||||
vector<offer_object> database_api::list_buy_offers(const offer_id_type lower_id, uint32_t limit) const
|
||||
{
|
||||
return my->list_buy_offers(limit);
|
||||
return my->list_buy_offers(lower_id, limit);
|
||||
}
|
||||
|
||||
vector<offer_object> database_api_impl::list_buy_offers(uint32_t limit) const
|
||||
vector<offer_object> database_api_impl::list_buy_offers(const offer_id_type lower_id, uint32_t limit) const
|
||||
{
|
||||
FC_ASSERT( limit <= 100 );
|
||||
const auto& offers_idx = _db.get_index_type<offer_index>().indices().get<by_id>();
|
||||
vector<offer_object> result;
|
||||
result.reserve(limit);
|
||||
|
||||
auto itr = offers_idx.begin();
|
||||
auto itr = offers_idx.lower_bound(lower_id);
|
||||
|
||||
while(limit && itr != offers_idx.end())
|
||||
{
|
||||
|
|
@ -2561,18 +2565,39 @@ vector<offer_object> database_api_impl::list_buy_offers(uint32_t limit) const
|
|||
|
||||
return result;
|
||||
}
|
||||
vector<offer_object> database_api::get_offers_by_issuer(const account_id_type issuer_account_id, uint32_t limit) const
|
||||
|
||||
vector<offer_history_object> database_api::list_offer_history(const offer_history_id_type lower_id, uint32_t limit) const
|
||||
{
|
||||
return my->get_offers_by_issuer(issuer_account_id, limit);
|
||||
return my->list_offer_history(lower_id, limit);
|
||||
}
|
||||
|
||||
vector<offer_object> database_api_impl::get_offers_by_issuer(const account_id_type issuer_account_id, uint32_t limit) const
|
||||
vector<offer_history_object> database_api_impl::list_offer_history(const offer_history_id_type lower_id, uint32_t limit) const
|
||||
{
|
||||
FC_ASSERT( limit <= 100 );
|
||||
const auto& oh_idx = _db.get_index_type<offer_history_index>().indices().get<by_id>();
|
||||
vector<offer_history_object> result;
|
||||
result.reserve(limit);
|
||||
|
||||
auto itr = oh_idx.lower_bound(lower_id);
|
||||
|
||||
while(limit-- && itr != oh_idx.end())
|
||||
result.emplace_back(*itr++);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
vector<offer_object> database_api::get_offers_by_issuer(const offer_id_type lower_id, const account_id_type issuer_account_id, uint32_t limit) const
|
||||
{
|
||||
return my->get_offers_by_issuer(lower_id, issuer_account_id, limit);
|
||||
}
|
||||
|
||||
vector<offer_object> database_api_impl::get_offers_by_issuer(const offer_id_type lower_id, const account_id_type issuer_account_id, uint32_t limit) const
|
||||
{
|
||||
FC_ASSERT( limit <= 100 );
|
||||
const auto& offers_idx = _db.get_index_type<offer_index>().indices().get<by_id>();
|
||||
vector<offer_object> result;
|
||||
result.reserve(limit);
|
||||
auto itr = offers_idx.begin();
|
||||
auto itr = offers_idx.lower_bound(lower_id);
|
||||
while(limit && itr != offers_idx.end())
|
||||
{
|
||||
if(itr->issuer == issuer_account_id)
|
||||
|
|
@ -2585,19 +2610,19 @@ vector<offer_object> database_api_impl::get_offers_by_issuer(const account_id_ty
|
|||
return result;
|
||||
}
|
||||
|
||||
vector<offer_object> database_api::get_offers_by_item(nft_id_type item, uint32_t limit) const
|
||||
vector<offer_object> database_api::get_offers_by_item(const offer_id_type lower_id, const nft_id_type item, uint32_t limit) const
|
||||
{
|
||||
return my->get_offers_by_item(item, limit);
|
||||
return my->get_offers_by_item(lower_id, item, limit);
|
||||
}
|
||||
|
||||
vector<offer_object> database_api_impl::get_offers_by_item(nft_id_type item, uint32_t limit) const
|
||||
vector<offer_object> database_api_impl::get_offers_by_item(const offer_id_type lower_id, const nft_id_type item, uint32_t limit) const
|
||||
{
|
||||
FC_ASSERT( limit <= 100 );
|
||||
const auto& offers_idx = _db.get_index_type<offer_index>().indices().get<by_id>();
|
||||
vector<offer_object> result;
|
||||
result.reserve(limit);
|
||||
|
||||
auto itr = offers_idx.begin();
|
||||
auto itr = offers_idx.lower_bound(lower_id);
|
||||
while(limit && itr != offers_idx.end())
|
||||
{
|
||||
if(itr->item_ids.find(item) != itr->item_ids.end())
|
||||
|
|
@ -2610,6 +2635,85 @@ vector<offer_object> database_api_impl::get_offers_by_item(nft_id_type item, uin
|
|||
return result;
|
||||
}
|
||||
|
||||
vector<offer_history_object> database_api::get_offer_history_by_issuer(const offer_history_id_type lower_id, const account_id_type issuer_account_id, uint32_t limit) const
|
||||
{
|
||||
return my->get_offer_history_by_issuer(lower_id, issuer_account_id, limit);
|
||||
}
|
||||
|
||||
vector<offer_history_object> database_api::get_offer_history_by_item(const offer_history_id_type lower_id, const nft_id_type item, uint32_t limit) const
|
||||
{
|
||||
return my->get_offer_history_by_item(lower_id, item, limit);
|
||||
}
|
||||
|
||||
vector<offer_history_object> database_api::get_offer_history_by_bidder(const offer_history_id_type lower_id, const account_id_type bidder_account_id, uint32_t limit) const
|
||||
{
|
||||
return my->get_offer_history_by_bidder(lower_id, bidder_account_id, limit);
|
||||
}
|
||||
|
||||
vector<offer_history_object> database_api_impl::get_offer_history_by_issuer(const offer_history_id_type lower_id, const account_id_type issuer_account_id, uint32_t limit) const
|
||||
{
|
||||
FC_ASSERT( limit <= 100 );
|
||||
const auto& oh_idx = _db.get_index_type<offer_history_index>().indices().get<by_id>();
|
||||
vector<offer_history_object> result;
|
||||
result.reserve(limit);
|
||||
|
||||
auto itr = oh_idx.lower_bound(lower_id);
|
||||
|
||||
while(limit && itr != oh_idx.end())
|
||||
{
|
||||
if(itr->issuer == issuer_account_id)
|
||||
{
|
||||
result.emplace_back(*itr);
|
||||
limit--;
|
||||
}
|
||||
itr++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
vector<offer_history_object> database_api_impl::get_offer_history_by_item(const offer_history_id_type lower_id, const nft_id_type item, uint32_t limit) const
|
||||
{
|
||||
FC_ASSERT( limit <= 100 );
|
||||
const auto& oh_idx = _db.get_index_type<offer_history_index>().indices().get<by_id>();
|
||||
vector<offer_history_object> result;
|
||||
result.reserve(limit);
|
||||
|
||||
auto itr = oh_idx.lower_bound(lower_id);
|
||||
|
||||
while(limit && itr != oh_idx.end())
|
||||
{
|
||||
if(itr->item_ids.find(item) != itr->item_ids.end())
|
||||
{
|
||||
result.emplace_back(*itr);
|
||||
limit--;
|
||||
}
|
||||
itr++;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
vector<offer_history_object> database_api_impl::get_offer_history_by_bidder(const offer_history_id_type lower_id, const account_id_type bidder_account_id, uint32_t limit) const
|
||||
{
|
||||
FC_ASSERT( limit <= 100 );
|
||||
const auto& oh_idx = _db.get_index_type<offer_history_index>().indices().get<by_id>();
|
||||
vector<offer_history_object> result;
|
||||
result.reserve(limit);
|
||||
|
||||
auto itr = oh_idx.lower_bound(lower_id);
|
||||
|
||||
while(limit && itr != oh_idx.end())
|
||||
{
|
||||
if(itr->bidder && *itr->bidder == bidder_account_id)
|
||||
{
|
||||
result.emplace_back(*itr);
|
||||
limit--;
|
||||
}
|
||||
itr++;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// Private methods //
|
||||
|
|
|
|||
|
|
@ -792,12 +792,15 @@ class database_api
|
|||
//////////////////
|
||||
// MARKET PLACE //
|
||||
//////////////////
|
||||
vector<offer_object> list_offers(uint32_t limit) const;
|
||||
vector<offer_object> list_sell_offers(uint32_t limit) const;
|
||||
vector<offer_object> list_buy_offers(uint32_t limit) const;
|
||||
vector<offer_object> get_offers_by_issuer(const account_id_type issuer_account_id, uint32_t limit) const;
|
||||
vector<offer_object> get_offers_by_item(nft_id_type item, uint32_t limit) const;
|
||||
|
||||
vector<offer_object> list_offers(const offer_id_type lower_id, uint32_t limit) const;
|
||||
vector<offer_object> list_sell_offers(const offer_id_type lower_id, uint32_t limit) const;
|
||||
vector<offer_object> list_buy_offers(const offer_id_type lower_id, uint32_t limit) const;
|
||||
vector<offer_history_object> list_offer_history(const offer_history_id_type lower_id, uint32_t limit) const;
|
||||
vector<offer_object> get_offers_by_issuer(const offer_id_type lower_id, const account_id_type issuer_account_id, uint32_t limit) const;
|
||||
vector<offer_object> get_offers_by_item(const offer_id_type lower_id, const nft_id_type item, uint32_t limit) const;
|
||||
vector<offer_history_object> get_offer_history_by_issuer(const offer_history_id_type lower_id, const account_id_type issuer_account_id, uint32_t limit) const;
|
||||
vector<offer_history_object> get_offer_history_by_item(const offer_history_id_type lower_id, const nft_id_type item, uint32_t limit) const;
|
||||
vector<offer_history_object> get_offer_history_by_bidder(const offer_history_id_type lower_id, const account_id_type bidder_account_id, uint32_t limit) const;
|
||||
private:
|
||||
std::shared_ptr< database_api_impl > my;
|
||||
};
|
||||
|
|
@ -952,6 +955,10 @@ FC_API(graphene::app::database_api,
|
|||
(list_offers)
|
||||
(list_sell_offers)
|
||||
(list_buy_offers)
|
||||
(list_offer_history)
|
||||
(get_offers_by_issuer)
|
||||
(get_offers_by_item)
|
||||
(get_offer_history_by_issuer)
|
||||
(get_offer_history_by_item)
|
||||
(get_offer_history_by_bidder)
|
||||
)
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ namespace graphene
|
|||
bool operator()(const fc::time_point_sec &o1,
|
||||
const fc::time_point_sec &o2) const
|
||||
{
|
||||
return o1 > o2;
|
||||
return o1 < o2;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -2052,12 +2052,16 @@ class wallet_api
|
|||
asset bid_price,
|
||||
offer_id_type offer_id,
|
||||
bool broadcast);
|
||||
vector<offer_object> list_offers(uint32_t limit) const;
|
||||
vector<offer_object> list_sell_offers(uint32_t limit) const;
|
||||
vector<offer_object> list_buy_offers(uint32_t limit) const;
|
||||
vector<offer_object> list_offers(uint32_t limit, optional<offer_id_type> lower_id) const;
|
||||
vector<offer_object> list_sell_offers(uint32_t limit, optional<offer_id_type> lower_id) const;
|
||||
vector<offer_object> list_buy_offers(uint32_t limit, optional<offer_id_type> lower_id) const;
|
||||
vector<offer_history_object> list_offer_history(uint32_t limit, optional<offer_history_id_type> lower_id) const;
|
||||
vector<offer_object> get_offers_by_issuer(string issuer_account_id_or_name,
|
||||
uint32_t limit) const;
|
||||
vector<offer_object> get_offers_by_item(nft_id_type item, uint32_t limit) const;
|
||||
uint32_t limit, optional<offer_id_type> lower_id) const;
|
||||
vector<offer_object> get_offers_by_item(const nft_id_type item, uint32_t limit, optional<offer_id_type> lower_id) const;
|
||||
vector<offer_history_object> get_offer_history_by_issuer(string issuer_account_id_or_name, uint32_t limit, optional<offer_history_id_type> lower_id) const;
|
||||
vector<offer_history_object> get_offer_history_by_item(const nft_id_type item, uint32_t limit, optional<offer_history_id_type> lower_id) const;
|
||||
vector<offer_history_object> get_offer_history_by_bidder(string bidder_account_id_or_name, uint32_t limit, optional<offer_history_id_type> lower_id) const;
|
||||
|
||||
void dbg_make_uia(string creator, string symbol);
|
||||
void dbg_make_mia(string creator, string symbol);
|
||||
|
|
@ -2325,8 +2329,12 @@ FC_API( graphene::wallet::wallet_api,
|
|||
(list_offers)
|
||||
(list_sell_offers)
|
||||
(list_buy_offers)
|
||||
(list_offer_history)
|
||||
(get_offers_by_issuer)
|
||||
(get_offers_by_item)
|
||||
(get_offer_history_by_issuer)
|
||||
(get_offer_history_by_item)
|
||||
(get_offer_history_by_bidder)
|
||||
(get_upcoming_tournaments)
|
||||
(get_tournaments)
|
||||
(get_tournaments_by_state)
|
||||
|
|
|
|||
|
|
@ -6401,33 +6401,81 @@ signed_transaction wallet_api::create_bid(string bidder_account_id_or_name,
|
|||
return my->sign_transaction( trx, broadcast );
|
||||
}
|
||||
|
||||
vector<offer_object> wallet_api::list_offers(uint32_t limit) const
|
||||
vector<offer_object> wallet_api::list_offers(uint32_t limit, optional<offer_id_type> lower_id) const
|
||||
{
|
||||
return my->_remote_db->list_offers(limit);
|
||||
offer_id_type lb_id;
|
||||
if(lower_id)
|
||||
lb_id = *lower_id;
|
||||
return my->_remote_db->list_offers(lb_id, limit);
|
||||
}
|
||||
|
||||
vector<offer_object> wallet_api::list_sell_offers(uint32_t limit) const
|
||||
vector<offer_object> wallet_api::list_sell_offers(uint32_t limit, optional<offer_id_type> lower_id) const
|
||||
{
|
||||
return my->_remote_db->list_sell_offers(limit);
|
||||
offer_id_type lb_id;
|
||||
if(lower_id)
|
||||
lb_id = *lower_id;
|
||||
return my->_remote_db->list_sell_offers(lb_id, limit);
|
||||
}
|
||||
|
||||
vector<offer_object> wallet_api::list_buy_offers(uint32_t limit) const
|
||||
vector<offer_object> wallet_api::list_buy_offers(uint32_t limit, optional<offer_id_type> lower_id) const
|
||||
{
|
||||
return my->_remote_db->list_buy_offers(limit);
|
||||
offer_id_type lb_id;
|
||||
if(lower_id)
|
||||
lb_id = *lower_id;
|
||||
return my->_remote_db->list_buy_offers(lb_id, limit);
|
||||
}
|
||||
|
||||
vector<offer_history_object> wallet_api::list_offer_history(uint32_t limit, optional<offer_history_id_type> lower_id) const
|
||||
{
|
||||
offer_history_id_type lb_id;
|
||||
if(lower_id)
|
||||
lb_id = *lower_id;
|
||||
return my->_remote_db->list_offer_history(lb_id, limit);
|
||||
}
|
||||
|
||||
vector<offer_object> wallet_api::get_offers_by_issuer(string issuer_account_id_or_name,
|
||||
uint32_t limit) const
|
||||
uint32_t limit, optional<offer_id_type> lower_id) const
|
||||
{
|
||||
offer_id_type lb_id;
|
||||
if(lower_id)
|
||||
lb_id = *lower_id;
|
||||
account_object issuer_account = my->get_account(issuer_account_id_or_name);
|
||||
return my->_remote_db->get_offers_by_issuer(issuer_account.id, limit);
|
||||
return my->_remote_db->get_offers_by_issuer(lb_id, issuer_account.id, limit);
|
||||
}
|
||||
|
||||
vector<offer_object> wallet_api::get_offers_by_item(nft_id_type item, uint32_t limit) const
|
||||
vector<offer_object> wallet_api::get_offers_by_item(const nft_id_type item, uint32_t limit, optional<offer_id_type> lower_id) const
|
||||
{
|
||||
return my->_remote_db->get_offers_by_item(item, limit);
|
||||
offer_id_type lb_id;
|
||||
if(lower_id)
|
||||
lb_id = *lower_id;
|
||||
return my->_remote_db->get_offers_by_item(lb_id, item, limit);
|
||||
}
|
||||
|
||||
vector<offer_history_object> wallet_api::get_offer_history_by_issuer(string issuer_account_id_or_name, uint32_t limit, optional<offer_history_id_type> lower_id) const
|
||||
{
|
||||
offer_history_id_type lb_id;
|
||||
if(lower_id)
|
||||
lb_id = *lower_id;
|
||||
account_object issuer_account = my->get_account(issuer_account_id_or_name);
|
||||
return my->_remote_db->get_offer_history_by_issuer(lb_id, issuer_account.id, limit);
|
||||
}
|
||||
|
||||
vector<offer_history_object> wallet_api::get_offer_history_by_item(const nft_id_type item, uint32_t limit, optional<offer_history_id_type> lower_id) const
|
||||
{
|
||||
offer_history_id_type lb_id;
|
||||
if(lower_id)
|
||||
lb_id = *lower_id;
|
||||
return my->_remote_db->get_offer_history_by_item(lb_id, item, limit);
|
||||
}
|
||||
|
||||
vector<offer_history_object> wallet_api::get_offer_history_by_bidder(string bidder_account_id_or_name, uint32_t limit, optional<offer_history_id_type> lower_id) const
|
||||
{
|
||||
offer_history_id_type lb_id;
|
||||
if(lower_id)
|
||||
lb_id = *lower_id;
|
||||
account_object bidder_account = my->get_account(bidder_account_id_or_name);
|
||||
return my->_remote_db->get_offer_history_by_bidder(lb_id, bidder_account.id, limit);
|
||||
}
|
||||
// default ctor necessary for FC_REFLECT
|
||||
signed_block_with_info::signed_block_with_info()
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue