-
Notifications
You must be signed in to change notification settings - Fork 104
Feature/tx backfill fallback #933
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6e74291
feat: add transaction backfill fallback for queue ID lookups
eabdelmoneim acb89e2
feat: add DELETE /admin/backfill endpoint to clear backfill table
eabdelmoneim 53d5532
docs: add comments explaining AMEX backfill logic
eabdelmoneim a8a64bd
fix: validate backfill hash format before use
eabdelmoneim 2cd06eb
feat: extend backfill fallback to support /transaction/status endpoint
eabdelmoneim cd678e0
docs: add AMEX backfill comments to /transaction/status routes
eabdelmoneim a9646f8
fix: use discriminated union for backfill schema and remove duplicate…
eabdelmoneim File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| import { type Static, Type } from "@sinclair/typebox"; | ||
| import type { FastifyInstance } from "fastify"; | ||
| import { StatusCodes } from "http-status-codes"; | ||
| import { TransactionDB } from "../../../shared/db/transactions/db"; | ||
| import { standardResponseSchema } from "../../schemas/shared-api-schemas"; | ||
|
|
||
| // SPECIAL LOGIC FOR AMEX | ||
| // Two admin routes to backfill transaction data: | ||
| // - loadBackfillRoute: Load queueId to status/transactionHash mappings | ||
| // - clearBackfillRoute: Clear all backfill entries | ||
| // See https://github.com/thirdweb-dev/solutions-customer-scripts/blob/main/amex/scripts/load-backfill-via-api.ts | ||
|
|
||
| const MinedEntrySchema = Type.Object({ | ||
| queueId: Type.String({ description: "Queue ID (UUID)" }), | ||
| status: Type.Literal("mined"), | ||
| transactionHash: Type.String({ description: "Transaction hash (0x...)" }), | ||
| }); | ||
|
|
||
| const ErroredEntrySchema = Type.Object({ | ||
| queueId: Type.String({ description: "Queue ID (UUID)" }), | ||
| status: Type.Literal("errored"), | ||
| }); | ||
|
|
||
| const loadRequestBodySchema = Type.Object({ | ||
| entries: Type.Array( | ||
| Type.Union([MinedEntrySchema, ErroredEntrySchema], { | ||
| description: "Entry with status 'mined' requires transactionHash; status 'errored' does not", | ||
| }), | ||
| { | ||
| description: "Array of queueId to status/transactionHash mappings", | ||
| maxItems: 10000, | ||
| }, | ||
| ), | ||
| }); | ||
|
|
||
| const loadResponseBodySchema = Type.Object({ | ||
| result: Type.Object({ | ||
| inserted: Type.Integer({ description: "Number of entries inserted" }), | ||
| skipped: Type.Integer({ | ||
| description: "Number of entries skipped (already exist)", | ||
| }), | ||
| }), | ||
| }); | ||
|
|
||
| const clearResponseBodySchema = Type.Object({ | ||
| result: Type.Object({ | ||
| deleted: Type.Integer({ description: "Number of entries deleted" }), | ||
| }), | ||
| }); | ||
|
|
||
| export async function loadBackfillRoute(fastify: FastifyInstance) { | ||
| fastify.route<{ | ||
| Body: Static<typeof loadRequestBodySchema>; | ||
| Reply: Static<typeof loadResponseBodySchema>; | ||
| }>({ | ||
| method: "POST", | ||
| url: "/admin/backfill", | ||
| schema: { | ||
| summary: "Load backfill entries", | ||
| description: | ||
| "Load queueId to transactionHash mappings into the backfill table. Uses SETNX to never overwrite existing entries.", | ||
| tags: ["Admin"], | ||
| operationId: "loadBackfill", | ||
| body: loadRequestBodySchema, | ||
| response: { | ||
| ...standardResponseSchema, | ||
| [StatusCodes.OK]: loadResponseBodySchema, | ||
| }, | ||
| hide: true, | ||
| }, | ||
| handler: async (request, reply) => { | ||
| const { entries } = request.body; | ||
|
|
||
| const { inserted, skipped } = | ||
| await TransactionDB.bulkSetBackfill(entries); | ||
|
|
||
| reply.status(StatusCodes.OK).send({ | ||
| result: { inserted, skipped }, | ||
| }); | ||
| }, | ||
| }); | ||
| } | ||
|
|
||
| export async function clearBackfillRoute(fastify: FastifyInstance) { | ||
| fastify.route<{ | ||
| Reply: Static<typeof clearResponseBodySchema>; | ||
| }>({ | ||
| method: "DELETE", | ||
| url: "/admin/backfill", | ||
| schema: { | ||
| summary: "Clear backfill table", | ||
| description: | ||
| "Delete all entries from the backfill table. This action cannot be undone.", | ||
| tags: ["Admin"], | ||
| operationId: "clearBackfill", | ||
| response: { | ||
| ...standardResponseSchema, | ||
| [StatusCodes.OK]: clearResponseBodySchema, | ||
| }, | ||
| hide: true, | ||
| }, | ||
| handler: async (_request, reply) => { | ||
| const deleted = await TransactionDB.clearBackfill(); | ||
|
|
||
| reply.status(StatusCodes.OK).send({ | ||
| result: { deleted }, | ||
| }); | ||
| }, | ||
| }); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.