Skip to content

Commit f01717a

Browse files
authored
allow cancelling userops (#918)
* allow cancelling userops * userophash needs to be valid for schema
1 parent 086bad6 commit f01717a

File tree

1 file changed

+34
-25
lines changed

1 file changed

+34
-25
lines changed

src/server/routes/transaction/cancel.ts

Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -82,33 +82,39 @@ 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+
? {
109+
userOpHash:
110+
"0x0000000000000000000000000000000000000000000000000000000000000000",
111+
nonce: "cancelled",
112+
isUserOp: true,
113+
}
114+
: { nonce: -1, sentTransactionHashes: [], isUserOp: false }),
115+
};
116+
} else if (transaction.status === "sent") {
117+
if (!transaction.isUserOp) {
112118
// Cancel a sent transaction with the same nonce.
113119
const { chainId, from, nonce } = transaction;
114120
const transactionHash = await sendCancellationTransaction({
@@ -143,7 +149,10 @@ export async function cancelTransaction(fastify: FastifyInstance) {
143149
queueId,
144150
status: "success",
145151
message,
146-
transactionHash: cancelledTransaction.sentTransactionHashes.at(-1),
152+
transactionHash:
153+
"sentTransactionHashes" in cancelledTransaction
154+
? cancelledTransaction.sentTransactionHashes.at(-1)
155+
: cancelledTransaction.userOpHash,
147156
},
148157
});
149158
},

0 commit comments

Comments
 (0)