Skip to content

Commit

Permalink
added filter to fetch transfers where an address is relayer
Browse files Browse the repository at this point in the history
  • Loading branch information
bogdan-rosianu committed Jan 10, 2025
1 parent 50f2d0b commit 7dace6c
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 7 deletions.
16 changes: 11 additions & 5 deletions src/common/indexer/elastic/elastic.indexer.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,17 +316,23 @@ export class ElasticIndexerHelper {
if (filter.withRefunds) {
mustNotQueries = [];
}

const shouldConditions = [
QueryType.Match('sender', filter.address),
QueryType.Match('receiver', filter.address),
QueryType.Match('receivers', filter.address),
];
if (filter.withTxsRelayedByAddress) {
shouldConditions.push(QueryType.Match('relayer', filter.address));
}

elasticQuery = elasticQuery.withCondition(QueryConditionOptions.should, QueryType.Must([
QueryType.Match('type', 'unsigned'),
QueryType.Should(smartContractResultConditions),
], mustNotQueries))
.withCondition(QueryConditionOptions.should, QueryType.Must([
QueryType.Should([QueryType.Match('type', 'normal')]),
QueryType.Should([
QueryType.Match('sender', filter.address),
QueryType.Match('receiver', filter.address),
QueryType.Match('receivers', filter.address),
]),
QueryType.Should(shouldConditions),
]));
}

Expand Down
3 changes: 3 additions & 0 deletions src/common/indexer/entities/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,7 @@ export interface Transaction {
scResults: any[];
version: number;
relayerAddr: string;
relayer: string;
relayerSignature: string;
isRelayed: boolean;
}
5 changes: 4 additions & 1 deletion src/endpoints/accounts/account.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1018,6 +1018,7 @@ export class AccountController {
@ApiQuery({ name: 'withOperations', description: 'Return operations for transfers. When "withOperations" parameter is applied, complexity estimation is 200', required: false })
@ApiQuery({ name: 'withActionTransferValue', description: 'Returns value in USD and EGLD for transferred tokens within the action attribute', required: false })
@ApiQuery({ name: 'withRefunds', description: 'Include refund transactions', required: false })
@ApiQuery({ name: 'withTxsRelayedByAddress', description: 'Include transactions that were relayed by the address', required: false })
async getAccountTransfers(
@Param('address', ParseAddressPipe) address: string,
@Query('from', new DefaultValuePipe(0), ParseIntPipe) from: number,
Expand Down Expand Up @@ -1045,6 +1046,7 @@ export class AccountController {
@Query('withOperations', ParseBoolPipe) withOperations?: boolean,
@Query('withActionTransferValue', ParseBoolPipe) withActionTransferValue?: boolean,
@Query('withRefunds', ParseBoolPipe) withRefunds?: boolean,
@Query('withTxsRelayedByAddress', ParseBoolPipe) withTxsRelayedByAddress?: boolean,
): Promise<Transaction[]> {
const options = TransactionQueryOptions.applyDefaultOptions(
size, { withScamInfo, withUsername, withBlockInfo, withOperations, withLogs, withActionTransferValue });
Expand All @@ -1067,6 +1069,7 @@ export class AccountController {
relayer,
round,
withRefunds,
withTxsRelayedByAddress,
}),
new QueryPagination({ from, size }),
options,
Expand All @@ -1075,7 +1078,7 @@ export class AccountController {
}

@Get("/accounts/:address/transfers/count")
@ApiOperation({ summary: 'Account transfer count', description: 'Return total count of tranfers triggerred by a user account (type = Transaction), as well as transfers triggerred by smart contracts (type = SmartContractResult)' })
@ApiOperation({ summary: 'Account transfer count', description: 'Return total count of transfers triggerred by a user account (type = Transaction), as well as transfers triggerred by smart contracts (type = SmartContractResult)' })
@ApiOkResponse({ type: Number })
@ApiQuery({ name: 'sender', description: 'Address of the transfer sender', required: false })
@ApiQuery({ name: 'receiver', description: 'Search by multiple receiver addresses, comma-separated', required: false })
Expand Down
1 change: 1 addition & 0 deletions src/endpoints/transactions/entities/transaction.filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export class TransactionFilter {
round?: number;
withRefunds?: boolean;
withRelayedScresults?: boolean;
withTxsRelayedByAddress?: boolean;

constructor(init?: Partial<TransactionFilter>) {
Object.assign(this, init);
Expand Down
7 changes: 6 additions & 1 deletion src/endpoints/transfers/transfer.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,12 @@ export class TransferService {
for (const elasticOperation of elasticOperations) {
const transaction = ApiUtils.mergeObjects(new TransactionDetailed(), elasticOperation);
transaction.type = elasticOperation.type === 'normal' ? TransactionType.Transaction : TransactionType.SmartContractResult;
transaction.relayer = elasticOperation.relayerAddr;
if (elasticOperation.relayer) {
transaction.relayer = elasticOperation.relayer;
transaction.isRelayed = true;
} else {
transaction.relayer = elasticOperation.relayerAddr;
}

if (transaction.type === TransactionType.SmartContractResult) {
delete transaction.gasLimit;
Expand Down

0 comments on commit 7dace6c

Please sign in to comment.