From 11d3dd27b9600dc6ef56d4700d3ed2781572414f Mon Sep 17 00:00:00 2001 From: Fabian Emilius Date: Tue, 12 Oct 2021 23:26:45 +0200 Subject: [PATCH] Add filter to hide empty offers or empty auctions --- package.json | 2 +- .../namespaces/atomicassets/routes/offers.ts | 23 ++++++++++++++++++- .../atomicmarket/routes/auctions.ts | 7 ++++++ .../namespaces/atomicmarket/routes/sales.ts | 6 ++--- src/api/namespaces/atomicmarket/utils.ts | 7 ++++++ 5 files changed, 40 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index dcf53813..7a6dfe7e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "eosio-contract-api", - "version": "1.2.12", + "version": "1.2.13", "description": "EOSIO Contract API", "author": "pink.network", "license": "AGPL-3.0", diff --git a/src/api/namespaces/atomicassets/routes/offers.ts b/src/api/namespaces/atomicassets/routes/offers.ts index 5e5d4108..23148416 100644 --- a/src/api/namespaces/atomicassets/routes/offers.ts +++ b/src/api/namespaces/atomicassets/routes/offers.ts @@ -62,7 +62,9 @@ export class OfferApi { collection_whitelist: {type: 'string', min: 1}, is_recipient_contract: {type: 'bool'}, - hide_contracts: {type: 'bool'} + + hide_contracts: {type: 'bool'}, + hide_empty_offers: {type: 'bool'} }); const query = new QueryBuilder('SELECT contract, offer_id FROM atomicassets_offers offer'); @@ -101,6 +103,18 @@ export class OfferApi { ); } + if (args.hide_empty_offers) { + query.addCondition( + 'EXISTS(SELECT * FROM atomicassets_offers_assets asset ' + + 'WHERE asset.contract = offer.contract AND asset.offer_id = offer.offer_id AND asset.owner = offer.sender)' + ); + + query.addCondition( + 'EXISTS(SELECT * FROM atomicassets_offers_assets asset ' + + 'WHERE asset.contract = offer.contract AND asset.offer_id = offer.offer_id AND asset.owner = offer.recipient)' + ); + } + if (hasAssetFilter(req, ['asset_id'])) { const assetQuery = new QueryBuilder('SELECT * FROM atomicassets_offers_assets offer_asset, atomicassets_assets asset', query.buildValues()); @@ -418,6 +432,13 @@ export class OfferApi { required: false, schema: {type: 'boolean'} }, + { + name: 'hide_empty_offers', + in: 'query', + description: 'dont show offers where one side is empty', + required: false, + schema: {type: 'boolean'} + }, ...primaryBoundaryParameters, ...dateBoundaryParameters, ...greylistFilterParameters, diff --git a/src/api/namespaces/atomicmarket/routes/auctions.ts b/src/api/namespaces/atomicmarket/routes/auctions.ts index 02a4b322..5036bd87 100644 --- a/src/api/namespaces/atomicmarket/routes/auctions.ts +++ b/src/api/namespaces/atomicmarket/routes/auctions.ts @@ -195,6 +195,13 @@ export function auctionsEndpoints(core: AtomicMarketNamespace, server: HTTPServe required: false, schema: {type: 'string'} }, + { + name: 'hide_empty_auctions', + in: 'query', + description: 'Hide auctions with no bids', + required: false, + schema: {type: 'boolean'} + }, ...listingFilterParameters, ...baseAssetFilterParameters, ...extendedAssetFilterParameters, diff --git a/src/api/namespaces/atomicmarket/routes/sales.ts b/src/api/namespaces/atomicmarket/routes/sales.ts index fc794be0..c55b170e 100644 --- a/src/api/namespaces/atomicmarket/routes/sales.ts +++ b/src/api/namespaces/atomicmarket/routes/sales.ts @@ -15,7 +15,7 @@ import { } from '../../../docs'; import { buildBoundaryFilter, filterQueryArgs } from '../../utils'; import { listingFilterParameters } from '../openapi'; -import { buildAssetFilter, buildGreylistFilter } from '../../atomicassets/utils'; +import { buildAssetFilter, buildGreylistFilter, hasAssetFilter } from '../../atomicassets/utils'; import { applyActionGreylistFilters, createSocketApiNamespace, @@ -135,8 +135,8 @@ export function salesEndpoints(core: AtomicMarketNamespace, server: HTTPServer, return res.json({success: false, message: 'symbol parameter is required'}); } - if (!args.collection_name && !args.collection_whitelist) { - return res.json({success: false, message: 'You need to specify a collection name'}); + if (!hasAssetFilter(req) && !args.collection_whitelist) { + return res.json({success: false, message: 'You need to specify an asset filter!'}); } const query = new QueryBuilder(` diff --git a/src/api/namespaces/atomicmarket/utils.ts b/src/api/namespaces/atomicmarket/utils.ts index 649cabd1..db2fb876 100644 --- a/src/api/namespaces/atomicmarket/utils.ts +++ b/src/api/namespaces/atomicmarket/utils.ts @@ -198,6 +198,8 @@ export function buildAuctionFilter(req: express.Request, query: QueryBuilder): v participant: {type: 'string', min: 1}, bidder: {type: 'string', min: 1}, + + hide_empty_auctions: {type: 'bool'}, }); buildListingFilter(req, query); @@ -233,6 +235,11 @@ export function buildAuctionFilter(req: express.Request, query: QueryBuilder): v ); } + if (args.hide_empty_auctions) { + query.addCondition('EXISTS(SELECT * FROM atomicmarket_auctions_bids bid ' + + 'WHERE bid.market_contract = listing.market_contract AND bid.auction_id = listing.auction_id)'); + } + if (args.max_assets) { query.addCondition( `(