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")

0 commit comments

Comments
 (0)