Skip to content

Commit 86305f3

Browse files
authored
chore: Clean up TransactionStatus enum (#454)
* chore: Clean up TransactionStatus enum * fix: dont rely on processedAt * remove debug line * cr feedback * fix build
1 parent caf6a46 commit 86305f3

24 files changed

+94
-146
lines changed

src/db/transactions/cleanTxs.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ export const cleanTxs = (
1313
id: undefined,
1414
queuedAt: tx.queuedAt.toISOString(),
1515
sentAt: tx.sentAt?.toISOString() || null,
16-
processedAt: tx.processedAt?.toISOString() || null,
1716
minedAt: tx.minedAt?.toISOString() || null,
1817
cancelledAt: tx.cancelledAt?.toISOString() || null,
1918
status: !!tx.errorMessage
@@ -26,8 +25,6 @@ export const cleanTxs = (
2625
? "sent"
2726
: !!tx.sentAt && tx.retryCount > 0
2827
? "retried"
29-
: !!tx.processedAt
30-
? "processed"
3128
: "queued",
3229
};
3330
});

src/db/transactions/getAllTxs.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Static } from "@sinclair/typebox";
33
import { ContractExtension } from "../../schema/extension";
44
import { PrismaTransaction } from "../../schema/prisma";
55
import {
6-
TransactionStatusEnum,
6+
TransactionStatus,
77
transactionResponseSchema,
88
} from "../../server/schemas/transaction";
99
import { getPrismaWithPostgresTx } from "../client";
@@ -13,7 +13,7 @@ interface GetAllTxsParams {
1313
pgtx?: PrismaTransaction;
1414
page: number;
1515
limit: number;
16-
filter?: TransactionStatusEnum;
16+
filter?: TransactionStatus;
1717
extensions?: ContractExtension[];
1818
}
1919

@@ -40,15 +40,15 @@ export const getAllTxs = async ({
4040
// | "errorMessage"
4141
// | undefined;
4242

43-
// if (filter === TransactionStatusEnum.Queued) {
43+
// if (filter === TransactionStatus.Queued) {
4444
// filterBy = "queuedAt";
45-
// } else if (filter === TransactionStatusEnum.Submitted) {
45+
// } else if (filter === TransactionStatus.Sent) {
4646
// filterBy = "sentAt";
47-
// } else if (filter === TransactionStatusEnum.Processed) {
47+
// } else if (filter === TransactionStatus.Processed) {
4848
// filterBy = "processedAt";
49-
// } else if (filter === TransactionStatusEnum.Mined) {
49+
// } else if (filter === TransactionStatus.Mined) {
5050
// filterBy = "minedAt";
51-
// } else if (filter === TransactionStatusEnum.Errored) {
51+
// } else if (filter === TransactionStatus.Errored) {
5252
// filterBy = "errorMessage";
5353
// }
5454

src/db/transactions/getQueueStatus.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@ export const getQueueStatus = async ({
1010
const queued = await prisma.transactions.count({
1111
where: {
1212
fromAddress: walletAddress?.toLowerCase(),
13-
processedAt: null,
13+
sentAt: null,
1414
errorMessage: null,
15+
cancelledAt: null,
1516
},
1617
});
1718

1819
const pending = await prisma.transactions.count({
1920
where: {
2021
fromAddress: walletAddress?.toLowerCase(),
21-
sentAt: {
22-
not: null,
23-
},
22+
sentAt: { not: null },
2423
minedAt: null,
2524
errorMessage: null,
25+
cancelledAt: null,
2626
},
2727
});
2828

src/db/transactions/getQueuedTxs.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ export const getQueuedTxs = async ({ pgtx }: GetQueuedTxsParams = {}): Promise<
2020
FROM
2121
"transactions"
2222
WHERE
23-
"processedAt" IS NULL
24-
AND "sentAt" IS NULL
23+
"sentAt" IS NULL
2524
AND "minedAt" IS NULL
2625
AND "cancelledAt" IS NULL
2726
ORDER BY

src/db/transactions/getSentTxs.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ export const getSentTxs = async ({ pgtx }: GetSentTxsParams = {}): Promise<
1515

1616
return prisma.$queryRaw<Transactions[]>`
1717
SELECT * FROM "transactions"
18-
WHERE "processedAt" IS NOT NULL
19-
AND "sentAt" IS NOT NULL
18+
WHERE "sentAt" IS NOT NULL
2019
AND "transactionHash" IS NOT NULL
2120
AND "accountAddress" IS NULL
2221
AND "minedAt" IS NULL

src/db/transactions/getSentUserOps.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ export const getSentUserOps = async ({
1515

1616
return prisma.$queryRaw<Transactions[]>`
1717
SELECT * FROM "transactions"
18-
WHERE "processedAt" IS NOT NULL
19-
AND "sentAt" IS NOT NULL
18+
WHERE "sentAt" IS NOT NULL
2019
AND "accountAddress" IS NOT NULL
2120
AND "userOpHash" IS NOT NULL
2221
AND "minedAt" IS NULL

src/db/transactions/getTxToRetry.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ SELECT
2121
FROM
2222
"transactions"
2323
WHERE
24-
"processedAt" IS NOT NULL
25-
AND "sentAt" IS NOT NULL
24+
"sentAt" IS NOT NULL
2625
AND "accountAddress" IS NULL
2726
AND "minedAt" IS NULL
2827
AND "errorMessage" IS NULL

src/db/transactions/queueTxRaw.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { Prisma, Transactions } from "@prisma/client";
22
import { v4 as uuid } from "uuid";
33
import { PrismaTransaction } from "../../schema/prisma";
4-
import { TransactionStatusEnum } from "../../server/schemas/transaction";
4+
import { TransactionStatus } from "../../server/schemas/transaction";
55
import { simulateTx } from "../../server/utils/simulateTx";
66
import { UsageEventTxActionEnum, reportUsage } from "../../utils/usage";
77
import { sendWebhooks } from "../../utils/webhook";
@@ -88,7 +88,7 @@ export const queueTxRaw = async ({
8888
sendWebhooks([
8989
{
9090
queueId: txRow.id,
91-
status: TransactionStatusEnum.Queued,
91+
status: TransactionStatus.Queued,
9292
},
9393
]).catch((err) => {});
9494

src/db/transactions/updateTx.ts

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { BigNumber, ethers } from "ethers";
22
import { PrismaTransaction } from "../../schema/prisma";
3-
import { TransactionStatusEnum } from "../../server/schemas/transaction";
3+
import { TransactionStatus } from "../../server/schemas/transaction";
44
import { getPrismaWithPostgresTx } from "../client";
55

66
interface UpdateTxParams {
@@ -11,30 +11,27 @@ interface UpdateTxParams {
1111

1212
type UpdateTxData =
1313
| {
14-
status: TransactionStatusEnum.Cancelled;
14+
status: TransactionStatus.Cancelled;
1515
}
1616
| {
17-
status: TransactionStatusEnum.Processed;
18-
}
19-
| {
20-
status: TransactionStatusEnum.Errored;
17+
status: TransactionStatus.Errored;
2118
errorMessage: string;
2219
}
2320
| {
24-
status: TransactionStatusEnum.Submitted;
21+
status: TransactionStatus.Sent;
2522
sentAt: Date;
2623
transactionHash: string;
2724
res: ethers.providers.TransactionRequest;
2825
sentAtBlockNumber: number;
2926
retryCount?: number;
3027
}
3128
| {
32-
status: TransactionStatusEnum.UserOpSent;
29+
status: TransactionStatus.UserOpSent;
3330
sentAt: Date;
3431
userOpHash: string;
3532
}
3633
| {
37-
status: TransactionStatusEnum.Mined;
34+
status: TransactionStatus.Mined;
3835
gasPrice?: string;
3936
blockNumber?: number;
4037
minedAt: Date;
@@ -50,7 +47,7 @@ type UpdateTxData =
5047
export const updateTx = async ({ pgtx, queueId, data }: UpdateTxParams) => {
5148
const prisma = getPrismaWithPostgresTx(pgtx);
5249
switch (data.status) {
53-
case TransactionStatusEnum.Cancelled:
50+
case TransactionStatus.Cancelled:
5451
await prisma.transactions.update({
5552
where: {
5653
id: queueId,
@@ -60,17 +57,7 @@ export const updateTx = async ({ pgtx, queueId, data }: UpdateTxParams) => {
6057
},
6158
});
6259
break;
63-
case TransactionStatusEnum.Processed:
64-
await prisma.transactions.update({
65-
where: {
66-
id: queueId,
67-
},
68-
data: {
69-
processedAt: new Date(),
70-
},
71-
});
72-
break;
73-
case TransactionStatusEnum.Errored:
60+
case TransactionStatus.Errored:
7461
await prisma.transactions.update({
7562
where: {
7663
id: queueId,
@@ -80,7 +67,7 @@ export const updateTx = async ({ pgtx, queueId, data }: UpdateTxParams) => {
8067
},
8168
});
8269
break;
83-
case TransactionStatusEnum.Submitted:
70+
case TransactionStatus.Sent:
8471
await prisma.transactions.update({
8572
where: {
8673
id: queueId,
@@ -100,7 +87,7 @@ export const updateTx = async ({ pgtx, queueId, data }: UpdateTxParams) => {
10087
},
10188
});
10289
break;
103-
case TransactionStatusEnum.UserOpSent:
90+
case TransactionStatus.UserOpSent:
10491
await prisma.transactions.update({
10592
where: {
10693
id: queueId,
@@ -111,7 +98,7 @@ export const updateTx = async ({ pgtx, queueId, data }: UpdateTxParams) => {
11198
},
11299
});
113100
break;
114-
case TransactionStatusEnum.Mined:
101+
case TransactionStatus.Mined:
115102
await prisma.transactions.update({
116103
where: {
117104
id: queueId,

src/prisma/schema.prisma

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ model Transactions {
142142
deployedContractType String? @map("deployedContractType")
143143
// Timestamps
144144
queuedAt DateTime @default(now()) @map("queuedAt")
145+
// @deprecated
145146
processedAt DateTime? @map("processedAt")
146147
sentAt DateTime? @map("sentAt")
147148
minedAt DateTime? @map("minedAt")

src/schema/webhooks.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ export enum WebhooksEventTypes {
33
SENT_TX = "sent_transaction",
44
MINED_TX = "mined_transaction",
55
ERRORED_TX = "errored_transaction",
6-
RETRIED_TX = "retried_transaction",
76
CANCELLED_TX = "cancelled_transaction",
87
ALL_TX = "all_transactions",
98
BACKEND_WALLET_BALANCE = "backend_wallet_balance",

src/server/routes/transaction/getAll.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const requestQuerySchema = Type.Object({
2121
default: "10",
2222
}),
2323
// filter: Type.Optional(
24-
// Type.Union([Type.Enum(TransactionStatusEnum), Type.Literal("all")], {
24+
// Type.Union([Type.Enum(TransactionStatus), Type.Literal("all")], {
2525
// description:
2626
// "This parameter allows to define specific criteria to filter the data by. For example, filtering by processed, submitted or error",
2727
// examples: ["all", "submitted", "processed", "errored", "mined", "queued"],
@@ -58,7 +58,6 @@ responseBodySchema.example = {
5858
transactionHash:
5959
"0xf11ca950299c9e72b8d6cac8a03623c6e5a43af1d1b0d45b3fd804c129b573f8",
6060
queuedAt: "2023-09-29T18:17:36.929Z",
61-
processedAt: "2023-09-29T18:17:37.011Z",
6261
sentAt: "2023-09-29T18:17:40.832Z",
6362
minedAt: "2023-09-29T18:17:44.000Z",
6463
cancelledAt: null,

src/server/routes/transaction/getAllDeployedContracts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const requestQuerySchema = Type.Object({
2121
default: "10",
2222
}),
2323
// filter: Type.Optional(
24-
// Type.Union([Type.Enum(TransactionStatusEnum), Type.Literal("all")], {
24+
// Type.Union([Type.Enum(TransactionStatus), Type.Literal("all")], {
2525
// description:
2626
// "This parameter allows to define specific criteria to filter the data by. For example, filtering by processed, submitted or error",
2727
// examples: ["all", "submitted", "processed", "errored", "mined", "queued"],

src/server/routes/transaction/syncRetry.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { parseTxError } from "../../../utils/errors";
1010
import { UsageEventTxActionEnum, reportUsage } from "../../../utils/usage";
1111
import { createCustomError } from "../../middleware/error";
1212
import { standardResponseSchema } from "../../schemas/sharedApiSchemas";
13-
import { TransactionStatusEnum } from "../../schemas/transaction";
13+
import { TransactionStatus } from "../../schemas/transaction";
1414

1515
// INPUT
1616
const requestBodySchema = Type.Object({
@@ -141,7 +141,7 @@ export async function syncRetryTransaction(fastify: FastifyInstance) {
141141
await updateTx({
142142
queueId: tx.id,
143143
data: {
144-
status: TransactionStatusEnum.Submitted,
144+
status: TransactionStatus.Sent,
145145
transactionHash,
146146
res: txRequest,
147147
sentAt: new Date(),

src/server/routes/webhooks/create.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,6 @@ BodySchema.examples = [
4343
name: "QueuedTx",
4444
eventType: WebhooksEventTypes.QUEUED_TX,
4545
},
46-
{
47-
url: "https://example.com/retiredTx",
48-
name: "RetriedTx",
49-
eventType: WebhooksEventTypes.RETRIED_TX,
50-
},
5146
{
5247
url: "https://example.com/sentTx",
5348
name: "Sent Transaction Event",

src/server/schemas/transaction/index.ts

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,6 @@ export const transactionResponseSchema = Type.Object({
9191
}),
9292
Type.Null(),
9393
]),
94-
processedAt: Type.Union([
95-
Type.String({
96-
description: "When the transaction is handled by a worker",
97-
}),
98-
Type.Null(),
99-
]),
10094
sentAt: Type.Union([
10195
Type.String({
10296
description: "When the transaction is submitted to mempool",
@@ -190,16 +184,19 @@ export const transactionResponseSchema = Type.Object({
190184
onChainTxStatus: Type.Union([Type.Number(), Type.Null()]),
191185
});
192186

193-
export enum TransactionStatusEnum {
194-
Processed = "processed",
187+
export enum TransactionStatus {
188+
// Tx was received and waiting to be processed.
195189
Queued = "queued",
196-
// TODO: Switch to sent
197-
Submitted = "sent",
190+
// Tx was submitted to mempool.
191+
Sent = "sent",
192+
// Tx (userOp for smart account) was submitted to mempool.
198193
UserOpSent = "user-op-sent",
194+
// Tx failed before submitting to mempool.
199195
Errored = "errored",
196+
// Tx was successfully mined onchain. Note: The tx may have "reverted" onchain.
200197
Mined = "mined",
198+
// Tx was cancelled and will not be re-attempted.
201199
Cancelled = "cancelled",
202-
Retried = "retried",
203200
}
204201

205202
export interface TransactionSchema {

0 commit comments

Comments
 (0)