Skip to content

Commit

Permalink
Add layered error handling to worker (#333)
Browse files Browse the repository at this point in the history
* Add layered error handling to worker

* Update

* Update
  • Loading branch information
adam-maj authored Dec 5, 2023
1 parent 48a2345 commit b70454e
Show file tree
Hide file tree
Showing 2 changed files with 276 additions and 239 deletions.
15 changes: 13 additions & 2 deletions src/db/transactions/queueTx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { BigNumber } from "ethers";
import type { ContractExtension } from "../../schema/extension";
import { PrismaTransaction } from "../../schema/prisma";
import { getPrismaWithPostgresTx } from "../client";
import { getWalletDetails } from "../wallets/getWalletDetails";

interface QueueTxParams {
pgtx?: PrismaTransaction;
Expand Down Expand Up @@ -40,6 +41,16 @@ export const queueTx = async ({

const prisma = getPrismaWithPostgresTx(pgtx);

const fromAddress = (await tx.getSignerAddress()).toLowerCase();
const walletDetails = await getWalletDetails({
pgtx,
address: fromAddress,
});

if (!walletDetails) {
throw new Error(`No configured wallet found with address ${fromAddress}`);
}

// TODO: We need a much safer way of detecting if the transaction should be a user operation
const isUserOp = !!(tx.getSigner as ERC4337EthersSigner).erc4337provider;
const txTableData = {
Expand All @@ -61,7 +72,7 @@ export const queueTx = async ({
signerAddress: await (
tx.getSigner as ERC4337EthersSigner
).originalSigner.getAddress(),
accountAddress: (await tx.getSignerAddress()).toLowerCase(),
accountAddress: fromAddress,
// Fields needed to send user operation
target: tx.getTarget().toLowerCase(),
},
Expand All @@ -73,7 +84,7 @@ export const queueTx = async ({
data: {
...txTableData,
// Fields needed to send transaction
fromAddress: (await tx.getSignerAddress()).toLowerCase(),
fromAddress,
toAddress: tx.getTarget().toLowerCase(),
},
});
Expand Down
Loading

0 comments on commit b70454e

Please sign in to comment.