Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: endpoint to get event logs by address #40

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
169 changes: 103 additions & 66 deletions packages/api/src/api/account/account.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,15 @@ describe("AccountController", () => {

describe("getAccountTransactions", () => {
it("calls block service to get latest block number", async () => {
await controller.getAccountTransactions(address, {
page: 2,
offset: 20,
maxLimit: 10000,
sort: SortingOrder.Asc,
});
await controller.getAccountTransactions(
address,
{
page: 2,
offset: 20,
maxLimit: 10000,
},
{ sort: SortingOrder.Asc }
);
expect(blockServiceMock.getLastBlockNumber).toBeCalledTimes(1);
});

Expand All @@ -165,8 +168,8 @@ describe("AccountController", () => {
page: 2,
offset: 20,
maxLimit: 10000,
sort: SortingOrder.Asc,
},
{ sort: SortingOrder.Asc },
11,
12
);
Expand All @@ -182,12 +185,15 @@ describe("AccountController", () => {
});

it("returns not ok response when no transactions found", async () => {
const response = await controller.getAccountTransactions(address, {
page: 2,
offset: 20,
maxLimit: 10000,
sort: SortingOrder.Asc,
});
const response = await controller.getAccountTransactions(
address,
{
page: 2,
offset: 20,
maxLimit: 10000,
},
{ sort: SortingOrder.Asc }
);
expect(response).toEqual({
status: ResponseStatus.NOTOK,
message: ResponseMessage.NO_TRANSACTIONS_FOUND,
Expand All @@ -198,12 +204,15 @@ describe("AccountController", () => {
it("returns transactions list when transactions are found by address", async () => {
jest.spyOn(transactionServiceMock, "findByAddress").mockResolvedValue([addressTransaction as AddressTransaction]);

const response = await controller.getAccountTransactions(address, {
page: 2,
offset: 20,
maxLimit: 10000,
sort: SortingOrder.Asc,
});
const response = await controller.getAccountTransactions(
address,
{
page: 2,
offset: 20,
maxLimit: 10000,
},
{ sort: SortingOrder.Asc }
);
expect(response).toEqual({
status: ResponseStatus.OK,
message: ResponseMessage.OK,
Expand Down Expand Up @@ -250,8 +259,8 @@ describe("AccountController", () => {
page: 2,
offset: 20,
maxLimit: 10000,
sort: SortingOrder.Asc,
},
{ sort: SortingOrder.Asc },
11,
12
);
Expand All @@ -269,12 +278,16 @@ describe("AccountController", () => {
});

it("returns not ok response when no transactions found", async () => {
const response = await controller.getAccountInternalTransactions(address, null, {
page: 2,
offset: 20,
maxLimit: 10000,
sort: SortingOrder.Asc,
});
const response = await controller.getAccountInternalTransactions(
address,
null,
{
page: 2,
offset: 20,
maxLimit: 10000,
},
{ sort: SortingOrder.Asc }
);
expect(response).toEqual({
status: ResponseStatus.NOTOK,
message: ResponseMessage.NO_TRANSACTIONS_FOUND,
Expand All @@ -285,12 +298,16 @@ describe("AccountController", () => {
it("returns internal transactions list when transactions are found", async () => {
jest.spyOn(transferServiceMock, "findInternalTransfers").mockResolvedValue([ecr20Transfer as Transfer]);

const response = await controller.getAccountInternalTransactions(address, null, {
page: 2,
offset: 20,
maxLimit: 10000,
sort: SortingOrder.Asc,
});
const response = await controller.getAccountInternalTransactions(
address,
null,
{
page: 2,
offset: 20,
maxLimit: 10000,
},
{ sort: SortingOrder.Asc }
);
expect(response).toEqual({
status: ResponseStatus.OK,
message: ResponseMessage.OK,
Expand Down Expand Up @@ -320,12 +337,16 @@ describe("AccountController", () => {

describe("getAccountTokenTransfers", () => {
it("calls block service to get latest block number", async () => {
await controller.getAccountTokenTransfers(address, null, {
page: 2,
offset: 20,
maxLimit: 10000,
sort: SortingOrder.Asc,
});
await controller.getAccountTokenTransfers(
address,
null,
{
page: 2,
offset: 20,
maxLimit: 10000,
},
{ sort: SortingOrder.Asc }
);
expect(blockServiceMock.getLastBlockNumber).toBeCalledTimes(1);
});

Expand All @@ -337,8 +358,8 @@ describe("AccountController", () => {
page: 2,
offset: 20,
maxLimit: 10000,
sort: SortingOrder.Asc,
},
{ sort: SortingOrder.Asc },
11,
12
);
Expand All @@ -357,12 +378,16 @@ describe("AccountController", () => {
});

it("returns not ok response when no transfers found", async () => {
const response = await controller.getAccountTokenTransfers(address, "tokenAddress", {
page: 2,
offset: 20,
maxLimit: 10000,
sort: SortingOrder.Asc,
});
const response = await controller.getAccountTokenTransfers(
address,
"tokenAddress",
{
page: 2,
offset: 20,
maxLimit: 10000,
},
{ sort: SortingOrder.Asc }
);
expect(response).toEqual({
status: ResponseStatus.NOTOK,
message: ResponseMessage.NO_TRANSACTIONS_FOUND,
Expand All @@ -380,8 +405,8 @@ describe("AccountController", () => {
page: 2,
offset: 20,
maxLimit: 10000,
sort: SortingOrder.Asc,
}
},
{ sort: SortingOrder.Asc }
);
expect(response).toEqual({
status: ResponseStatus.OK,
Expand Down Expand Up @@ -417,12 +442,16 @@ describe("AccountController", () => {

describe("getAccountNFTTransfers", () => {
it("calls block service to get latest block number", async () => {
await controller.getAccountNFTTransfers(address, null, {
page: 2,
offset: 20,
maxLimit: 10000,
sort: SortingOrder.Asc,
});
await controller.getAccountNFTTransfers(
address,
null,
{
page: 2,
offset: 20,
maxLimit: 10000,
},
{ sort: SortingOrder.Asc }
);
expect(blockServiceMock.getLastBlockNumber).toBeCalledTimes(1);
});

Expand All @@ -434,8 +463,8 @@ describe("AccountController", () => {
page: 2,
offset: 20,
maxLimit: 10000,
sort: SortingOrder.Asc,
},
{ sort: SortingOrder.Asc },
11,
12
);
Expand All @@ -454,12 +483,16 @@ describe("AccountController", () => {
});

it("returns not ok response when no transfers found", async () => {
const response = await controller.getAccountNFTTransfers(address, "tokenAddress", {
page: 2,
offset: 20,
maxLimit: 10000,
sort: SortingOrder.Asc,
});
const response = await controller.getAccountNFTTransfers(
address,
"tokenAddress",
{
page: 2,
offset: 20,
maxLimit: 10000,
},
{ sort: SortingOrder.Asc }
);
expect(response).toEqual({
status: ResponseStatus.NOTOK,
message: ResponseMessage.NO_TRANSACTIONS_FOUND,
Expand All @@ -470,12 +503,16 @@ describe("AccountController", () => {
it("returns transfers list when transfers are found", async () => {
jest.spyOn(transferServiceMock, "findTokenTransfers").mockResolvedValue([erc721Transfer]);

const response = await controller.getAccountNFTTransfers(address, "0xc7e0220d02d549c4846A6EC31D89C3B670Ebe36A", {
page: 2,
offset: 20,
maxLimit: 10000,
sort: SortingOrder.Asc,
});
const response = await controller.getAccountNFTTransfers(
address,
"0xc7e0220d02d549c4846A6EC31D89C3B670Ebe36A",
{
page: 2,
offset: 20,
maxLimit: 10000,
},
{ sort: SortingOrder.Asc }
);
expect(response).toEqual({
status: ResponseStatus.OK,
message: ResponseMessage.OK,
Expand Down
9 changes: 9 additions & 0 deletions packages/api/src/api/account/account.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { TransactionService } from "../../transaction/transaction.service";
import { TransferService } from "../../transfer/transfer.service";
import { BalanceService } from "../../balance/balance.service";
import { PagingOptionsWithMaxItemsLimitDto } from "../dtos/common/pagingOptionsWithMaxItemsLimit.dto";
import { SortingOptionsDto } from "../dtos/common/sortingOptions.dto";
import { ParseLimitedIntPipe } from "../../common/pipes/parseLimitedInt.pipe";
import { ParseAddressPipe } from "../../common/pipes/parseAddress.pipe";
import { ParseTransactionHashPipe } from "../../common/pipes/parseTransactionHash.pipe";
Expand Down Expand Up @@ -50,6 +51,7 @@ export class AccountController {
public async getAccountTransactions(
@Query("address", new ParseAddressPipe()) address: string,
@Query() pagingOptions: PagingOptionsWithMaxItemsLimitDto,
@Query() sortingOptions: SortingOptionsDto,
@Query("startblock", new ParseLimitedIntPipe({ min: 0, isOptional: true })) startBlock?: number,
@Query("endblock", new ParseLimitedIntPipe({ min: 0, isOptional: true })) endBlock?: number
): Promise<AccountTransactionsResponseDto> {
Expand All @@ -59,6 +61,7 @@ export class AccountController {
startBlock,
endBlock,
...pagingOptions,
...sortingOptions,
}),
]);
const transactionsList = transactions.map((transaction) => mapTransactionListItem(transaction, lastBlockNumber));
Expand All @@ -79,6 +82,7 @@ export class AccountController {
)
transactionHash: string,
@Query() pagingOptions: PagingOptionsWithMaxItemsLimitDto,
@Query() sortingOptions: SortingOptionsDto,
@Query("startblock", new ParseLimitedIntPipe({ min: 0, isOptional: true })) startBlock?: number,
@Query("endblock", new ParseLimitedIntPipe({ min: 0, isOptional: true })) endBlock?: number
): Promise<AccountInternalTransactionsResponseDto> {
Expand All @@ -88,6 +92,7 @@ export class AccountController {
startBlock,
endBlock,
...pagingOptions,
...sortingOptions,
});
const internalTransactionsList = transfers.map((transfer) => mapInternalTransactionListItem(transfer));
return {
Expand All @@ -107,6 +112,7 @@ export class AccountController {
)
contractAddress: string,
@Query() pagingOptions: PagingOptionsWithMaxItemsLimitDto,
@Query() sortingOptions: SortingOptionsDto,
@Query("startblock", new ParseLimitedIntPipe({ min: 0, isOptional: true })) startBlock?: number,
@Query("endblock", new ParseLimitedIntPipe({ min: 0, isOptional: true })) endBlock?: number
): Promise<AccountTokenTransfersResponseDto> {
Expand All @@ -119,6 +125,7 @@ export class AccountController {
startBlock,
endBlock,
...pagingOptions,
...sortingOptions,
}),
]);
const transfersList = transfers.map((transfer) => mapTransferListItem(transfer, lastBlockNumber));
Expand All @@ -139,6 +146,7 @@ export class AccountController {
)
contractAddress: string,
@Query() pagingOptions: PagingOptionsWithMaxItemsLimitDto,
@Query() sortingOptions: SortingOptionsDto,
@Query("startblock", new ParseLimitedIntPipe({ min: 0, isOptional: true })) startBlock?: number,
@Query("endblock", new ParseLimitedIntPipe({ min: 0, isOptional: true })) endBlock?: number
): Promise<AccountNFTTransfersResponseDto> {
Expand All @@ -151,6 +159,7 @@ export class AccountController {
startBlock,
endBlock,
...pagingOptions,
...sortingOptions,
}),
]);
const transfersList = transfers.map((transfer) => mapTransferListItem(transfer, lastBlockNumber));
Expand Down
Loading
Loading