Skip to content

Commit

Permalink
Add filter to hide empty offers or empty auctions
Browse files Browse the repository at this point in the history
  • Loading branch information
fabian-emilius committed Oct 12, 2021
1 parent ff27039 commit 11d3dd2
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
23 changes: 22 additions & 1 deletion src/api/namespaces/atomicassets/routes/offers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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());

Expand Down Expand Up @@ -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,
Expand Down
7 changes: 7 additions & 0 deletions src/api/namespaces/atomicmarket/routes/auctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions src/api/namespaces/atomicmarket/routes/sales.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(`
Expand Down
7 changes: 7 additions & 0 deletions src/api/namespaces/atomicmarket/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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(
`(
Expand Down

0 comments on commit 11d3dd2

Please sign in to comment.