Skip to content
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
28 changes: 21 additions & 7 deletions src/server/routes/contract/events/get-all-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@ import { thirdwebClient } from "../../../../shared/utils/sdk";
import { getChain } from "../../../../shared/utils/chain";
import { getChainIdFromChain } from "../../../utils/chain";
import { getContract, getContractEvents } from "thirdweb";
import { maybeBigInt } from "../../../../shared/utils/primitive-types";
import { toContractEventV4Schema } from "../../../schemas/event";
import {
type ContractEventV5,
toContractEventV4Schema,
} from "../../../schemas/event";
import { createCustomError } from "../../../middleware/error";
import { prettifyError } from "../../../../shared/utils/error";

const requestSchema = contractParamSchema;

Expand Down Expand Up @@ -93,11 +97,21 @@ export async function getAllEvents(fastify: FastifyInstance) {
chain: await getChain(chainId),
});

const eventsV5 = await getContractEvents({
contract: contract,
fromBlock: maybeBigInt(fromBlock?.toString()),
toBlock: maybeBigInt(toBlock?.toString()),
});
let eventsV5: ContractEventV5[];
try {
eventsV5 = await getContractEvents({
contract: contract,
fromBlock:
typeof fromBlock === "number" ? BigInt(fromBlock) : fromBlock,
toBlock: typeof toBlock === "number" ? BigInt(toBlock) : toBlock,
});
} catch (e) {
throw createCustomError(
`Failed to get events: ${prettifyError(e)}`,
StatusCodes.BAD_REQUEST,
"BAD_REQUEST",
);
}

reply.status(StatusCodes.OK).send({
result: eventsV5.map(toContractEventV4Schema).sort((a, b) => {
Expand Down
27 changes: 17 additions & 10 deletions src/server/schemas/contract/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,25 @@ export const rolesResponseSchema = Type.Object({
signer: Type.Array(Type.String()),
});

export const blockNumberOrTagSchema = Type.Union([
Type.Integer({ minimum: 0 }),
Type.Literal("latest"),
Type.Literal("earliest"),
Type.Literal("pending"),
Type.Literal("safe"),
Type.Literal("finalized"),
]);

export const eventsQuerystringSchema = Type.Object(
{
fromBlock: Type.Optional(
Type.Union([Type.Integer({ minimum: 0 }), Type.String()], {
default: "0",
}),
),
toBlock: Type.Optional(
Type.Union([Type.Integer({ minimum: 0 }), Type.String()], {
default: "latest",
}),
),
fromBlock: Type.Optional({
...blockNumberOrTagSchema,
default: "0",
}),
toBlock: Type.Optional({
...blockNumberOrTagSchema,
default: "latest",
}),
order: Type.Optional(
Type.Union([Type.Literal("asc"), Type.Literal("desc")], {
default: "desc",
Expand Down
1 change: 0 additions & 1 deletion src/shared/utils/transaction/insert-transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
WalletDetailsError,
type ParsedWalletDetails,
} from "../../../shared/db/wallets/get-wallet-details";
import { doesChainSupportService } from "../../lib/chain/chain-capabilities";
import { createCustomError } from "../../../server/middleware/error";
import { SendTransactionQueue } from "../../../worker/queues/send-transaction-queue";
import { getChecksumAddress } from "../primitive-types";
Expand Down
Loading