Skip to content

Commit 51e15d4

Browse files
committed
allow cancelling userops
1 parent 086bad6 commit 51e15d4

File tree

1 file changed

+29
-25
lines changed

1 file changed

+29
-25
lines changed

src/server/routes/transaction/cancel.ts

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -82,33 +82,34 @@ export async function cancelTransaction(fastify: FastifyInstance) {
8282

8383
const message = "Transaction successfully cancelled.";
8484
let cancelledTransaction: CancelledTransaction | null = null;
85-
if (!transaction.isUserOp) {
86-
if (transaction.status === "queued") {
87-
// Remove all retries from the SEND_TRANSACTION queue.
88-
const config = await getConfig();
89-
for (
90-
let resendCount = 0;
91-
resendCount < config.maxRetriesPerTx;
92-
resendCount++
93-
) {
94-
await SendTransactionQueue.remove({ queueId, resendCount });
95-
}
85+
if (transaction.status === "queued") {
86+
// Remove all retries from the SEND_TRANSACTION queue.
87+
const config = await getConfig();
88+
for (
89+
let resendCount = 0;
90+
resendCount < config.maxRetriesPerTx;
91+
resendCount++
92+
) {
93+
await SendTransactionQueue.remove({ queueId, resendCount });
94+
}
9695

97-
cancelledTransaction = {
98-
...transaction,
99-
status: "cancelled",
100-
cancelledAt: new Date(),
96+
cancelledTransaction = {
97+
...transaction,
98+
status: "cancelled",
99+
cancelledAt: new Date(),
101100

102-
// Dummy data since the transaction was never sent.
103-
sentAt: new Date(),
104-
sentAtBlock: await getBlockNumberish(transaction.chainId),
101+
// Dummy data since the transaction was never sent.
102+
sentAt: new Date(),
103+
sentAtBlock: await getBlockNumberish(transaction.chainId),
105104

106-
isUserOp: false,
107-
gas: 0n,
108-
nonce: -1,
109-
sentTransactionHashes: [],
110-
};
111-
} else if (transaction.status === "sent") {
105+
// isUserOp: false,
106+
gas: 0n,
107+
...(transaction.isUserOp
108+
? { userOpHash: "0x", nonce: "cancelled", isUserOp: true }
109+
: { nonce: -1, sentTransactionHashes: [], isUserOp: false }),
110+
};
111+
} else if (transaction.status === "sent") {
112+
if (!transaction.isUserOp) {
112113
// Cancel a sent transaction with the same nonce.
113114
const { chainId, from, nonce } = transaction;
114115
const transactionHash = await sendCancellationTransaction({
@@ -143,7 +144,10 @@ export async function cancelTransaction(fastify: FastifyInstance) {
143144
queueId,
144145
status: "success",
145146
message,
146-
transactionHash: cancelledTransaction.sentTransactionHashes.at(-1),
147+
transactionHash:
148+
"sentTransactionHashes" in cancelledTransaction
149+
? cancelledTransaction.sentTransactionHashes.at(-1)
150+
: cancelledTransaction.userOpHash,
147151
},
148152
});
149153
},

0 commit comments

Comments
 (0)