Skip to content

Commit

Permalink
API-70: senderShard + receiverShard filters
Browse files Browse the repository at this point in the history
  • Loading branch information
bogdan-rosianu committed Nov 14, 2024
1 parent 8621be4 commit 396ba41
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/endpoints/pool/entities/pool.filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@ export class PoolFilter {

sender?: string;
receiver?: string;
senderShard?: number;
receiverShard?: number;
type?: TransactionType;
}
13 changes: 11 additions & 2 deletions src/endpoints/pool/pool.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,25 @@ export class PoolController {
@ApiQuery({ name: 'size', description: 'Number of items to retrieve', required: false })
@ApiQuery({ name: 'sender', description: 'Search in transaction pool by a specific sender', required: false })
@ApiQuery({ name: 'receiver', description: 'Search in transaction pool by a specific receiver', required: false })
@ApiQuery({ name: 'senderShard', description: 'The shard of the sender', required: false })
@ApiQuery({ name: 'receiverShard', description: 'The shard of the receiver', required: false })
@ApiQuery({ name: 'type', description: 'Search in transaction pool by type', required: false })
async getTransactionPool(
@Query('from', new DefaultValuePipe(0), ParseIntPipe) from: number,
@Query('size', new DefaultValuePipe(25), ParseIntPipe) size: number,
@Query('sender', ParseAddressAndMetachainPipe) sender?: string,
@Query('receiver', ParseAddressPipe) receiver?: string,
@Query('senderShard', ParseIntPipe) senderShard?: number,
@Query('receiverShard', ParseIntPipe) receiverShard?: number,
@Query('type', new ParseEnumPipe(TransactionType)) type?: TransactionType,
): Promise<TransactionInPool[]> {
return await this.poolService.getPool(new QueryPagination({ from, size }), new PoolFilter({ sender: sender, receiver: receiver, type: type }));
return await this.poolService.getPool(new QueryPagination({ from, size }), new PoolFilter({
sender: sender,
receiver: receiver,
senderShard: senderShard,
receiverShard: receiverShard,
type: type,
}));
}

@Get("/pool/count")
Expand Down Expand Up @@ -70,5 +80,4 @@ export class PoolController {

return transaction;
}

}
4 changes: 3 additions & 1 deletion src/endpoints/pool/pool.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ export class PoolService {
return (
(!filters.sender || transaction.sender === filters.sender) &&
(!filters.receiver || transaction.receiver === filters.receiver) &&
(!filters.type || transaction.type === filters.type)
(!filters.type || transaction.type === filters.type) &&
(filters.senderShard === undefined || transaction.senderShard === filters.senderShard) &&
(filters.receiverShard === undefined || transaction.receiverShard === filters.receiverShard)
);
});
}
Expand Down

0 comments on commit 396ba41

Please sign in to comment.