From 8597f4d3f7e0f0225917930c8094e2bb0563ce4a Mon Sep 17 00:00:00 2001 From: karooolis Date: Sun, 27 Oct 2024 09:54:19 +0200 Subject: [PATCH] remove function signature, cleanup --- .../observe/TransactionsWatcher.tsx | 31 +++++++------------ .../worlds/[worldAddress]/observe/helpers.ts | 10 +----- .../observe/useObservedTransactions.ts | 1 - packages/explorer/src/observer/decorator.ts | 29 +++-------------- packages/explorer/src/observer/messages.ts | 1 - packages/explorer/src/observer/store.ts | 8 ++--- 6 files changed, 21 insertions(+), 59 deletions(-) diff --git a/packages/explorer/src/app/(explorer)/[chainName]/worlds/[worldAddress]/observe/TransactionsWatcher.tsx b/packages/explorer/src/app/(explorer)/[chainName]/worlds/[worldAddress]/observe/TransactionsWatcher.tsx index 3a158a6b2e..1b8a85e9dd 100644 --- a/packages/explorer/src/app/(explorer)/[chainName]/worlds/[worldAddress]/observe/TransactionsWatcher.tsx +++ b/packages/explorer/src/app/(explorer)/[chainName]/worlds/[worldAddress]/observe/TransactionsWatcher.tsx @@ -6,13 +6,11 @@ import { Transaction, TransactionReceipt, decodeFunctionData, - getAbiItem, getAddress, parseAbi, parseEventLogs, } from "viem"; import { UserOperation, entryPoint07Abi, entryPoint07Address } from "viem/account-abstraction"; -import { formatAbiItem } from "viem/utils"; import { useConfig, useWatchBlocks } from "wagmi"; import { getTransaction, simulateContract, waitForTransactionReceipt } from "wagmi/actions"; import { useStore } from "zustand"; @@ -61,6 +59,12 @@ export function TransactionsWatcher() { const { functionName: decodedFunctionName, args: decodedArgs } = decodedSmartAccountCall; const calls = getCalls(decodedFunctionName, decodedArgs, transaction); + const logs = parseEventLogs({ + abi: [...abi, userOperationEventAbi], + logs: receipt.logs, + }); + + console.log("calls", calls); setTransaction({ hash, @@ -68,24 +72,15 @@ export function TransactionsWatcher() { from: transaction.from, timestamp, transaction, - status: "pending", calls, - value: transaction.value, - }); - - const logs = parseEventLogs({ - abi: [...abi, userOperationEventAbi], - logs: receipt.logs, - }); - - updateTransaction(hash, { receipt, logs, + value: transaction.value, status: receipt.status, // TODO: correct status check error: undefined, // TODO: transactionError as BaseError, }); }, - [abi, setTransaction, updateTransaction], + [abi, setTransaction], ); const handleUserOperations = useCallback( @@ -106,10 +101,10 @@ export function TransactionsWatcher() { handleUserOperation({ hash, writeId, timestamp, receipt, transaction, userOperation }); } }, - [abi, observerWrites, handleUserOperation], + [abi, observerWrites, handleUserOperation, wagmiConfig], ); - const handleRegularTransaction = useCallback( + const handleAuthenticTransaction = useCallback( async ({ writeId, hash, @@ -145,7 +140,6 @@ export function TransactionsWatcher() { status: "pending", calls: { to: transaction.to, - functionSignature: formatAbiItem(getAbiItem({ abi, name: functionName, args })!), functionName, args, }, @@ -199,14 +193,13 @@ export function TransactionsWatcher() { if (!abi) return; const transaction = await getTransaction(wagmiConfig, { hash }); - if (transaction.to && getAddress(transaction.to) === getAddress(entryPoint07Address)) { handleUserOperations({ writeId, timestamp, transaction }); } else if (transaction.to && getAddress(transaction.to) === getAddress(worldAddress)) { - handleRegularTransaction({ hash, writeId, timestamp, transaction }); + handleAuthenticTransaction({ hash, writeId, timestamp, transaction }); } }, - [abi, wagmiConfig, worldAddress, handleUserOperations, handleRegularTransaction], + [abi, wagmiConfig, worldAddress, handleUserOperations, handleAuthenticTransaction], ); useEffect(() => { diff --git a/packages/explorer/src/app/(explorer)/[chainName]/worlds/[worldAddress]/observe/helpers.ts b/packages/explorer/src/app/(explorer)/[chainName]/worlds/[worldAddress]/observe/helpers.ts index 1d502f26e3..dfcf611e97 100644 --- a/packages/explorer/src/app/(explorer)/[chainName]/worlds/[worldAddress]/observe/helpers.ts +++ b/packages/explorer/src/app/(explorer)/[chainName]/worlds/[worldAddress]/observe/helpers.ts @@ -1,5 +1,4 @@ -import { Address, Hex, Transaction, decodeFunctionData, getAbiItem } from "viem"; -import { formatAbiItem } from "viem/utils"; +import { Address, Hex, Transaction, decodeFunctionData } from "viem"; import { doomWorldAbi } from "./abis"; export function getCalls(decodedFunctionName: string, decodedArgs: readonly unknown[], transaction: Transaction) { @@ -28,15 +27,8 @@ function getCall(target: Address, data: Hex, transaction: Transaction) { functionName = transaction.input.length > 10 ? transaction.input.slice(0, 10) : "unknown"; } - const functionAbiItem = getAbiItem({ - abi: doomWorldAbi, - name: functionName, - args, - } as never); - return { to: target, - functionSignature: functionAbiItem ? formatAbiItem(functionAbiItem) : "unknown", functionName, args, }; diff --git a/packages/explorer/src/app/(explorer)/[chainName]/worlds/[worldAddress]/observe/useObservedTransactions.ts b/packages/explorer/src/app/(explorer)/[chainName]/worlds/[worldAddress]/observe/useObservedTransactions.ts index e21bd59a75..fe3c7a69e9 100644 --- a/packages/explorer/src/app/(explorer)/[chainName]/worlds/[worldAddress]/observe/useObservedTransactions.ts +++ b/packages/explorer/src/app/(explorer)/[chainName]/worlds/[worldAddress]/observe/useObservedTransactions.ts @@ -30,7 +30,6 @@ export function useObservedTransactions() { for (const write of Object.values(observerWrites)) { // if (write.address.toLowerCase() !== worldAddress.toLowerCase()) continue; // TODO: filter entrypoint - const writeResult = write.events.find((event): event is Message<"write:result"> => event.type === "write:result"); const receiptEvent = write.events.find( (event): event is Message<"waitForTransactionReceipt:result"> | Message<"waitForUserOperationReceipt:result"> => diff --git a/packages/explorer/src/observer/decorator.ts b/packages/explorer/src/observer/decorator.ts index a3c8858fa2..ea32e1cba0 100644 --- a/packages/explorer/src/observer/decorator.ts +++ b/packages/explorer/src/observer/decorator.ts @@ -1,7 +1,7 @@ -import { Account, Chain, Client, Hex, Transport, WalletActions, getAbiItem } from "viem"; +import { Account, Chain, Client, Hex, Transport, WalletActions } from "viem"; import { BundlerActions, sendUserOperation, waitForUserOperationReceipt } from "viem/account-abstraction"; import { waitForTransactionReceipt, writeContract } from "viem/actions"; -import { formatAbiItem, getAction } from "viem/utils"; +import { getAction } from "viem/utils"; import { isDefined } from "@latticexyz/common/utils"; import { createBridge } from "./bridge"; import { ReceiptSummary } from "./common"; @@ -35,23 +35,10 @@ export function observer({ explorerUrl = "http://localhost:13690", waitForTransa if ("calls" in args && args.calls) { calls = args.calls .map((call) => { - if ( - call && - typeof call === "object" && - "abi" in call && - "functionName" in call && - "args" in call && - "to" in call - ) { - const functionAbiItem = getAbiItem({ - abi: call.abi, - name: call.functionName, - args: call.args, - } as never)!; - + // TODO: make this nicer + if (call && typeof call === "object" && "functionName" in call && "args" in call && "to" in call) { return { to: call.to, - functionSignature: formatAbiItem(functionAbiItem), // TODO: is it needed? functionName: call.functionName, args: call.args, } as UserOperationCall; @@ -92,20 +79,12 @@ export function observer({ explorerUrl = "http://localhost:13690", waitForTransa const writeId = `${client.uid}-${++writeCounter}`; const write = getAction(client, writeContract, "writeContract")(args); - // `writeContract` above will throw if this isn't present - const functionAbiItem = getAbiItem({ - abi: args.abi, - name: args.functionName, - args: args.args, - } as never)!; - emit("write", { writeId, from: client.account!.address, calls: [ { to: args.address, - functionSignature: formatAbiItem(functionAbiItem), functionName: args.functionName, args: (args.args ?? []) as never, }, diff --git a/packages/explorer/src/observer/messages.ts b/packages/explorer/src/observer/messages.ts index 5f01e90a0d..cb5570782c 100644 --- a/packages/explorer/src/observer/messages.ts +++ b/packages/explorer/src/observer/messages.ts @@ -5,7 +5,6 @@ import { ReceiptSummary } from "./common"; // TODO: fix type, move elsewhere export type UserOperationCall = { to: Address | null; - functionSignature: string; functionName: string; args: unknown; }; diff --git a/packages/explorer/src/observer/store.ts b/packages/explorer/src/observer/store.ts index 4a65e44e4e..981a397227 100644 --- a/packages/explorer/src/observer/store.ts +++ b/packages/explorer/src/observer/store.ts @@ -37,10 +37,10 @@ channel.addEventListener("message", ({ data }: MessageEvent) => { const write = data.type === "write" ? ({ ...data, events: [] } satisfies Write) : state.writes[data.writeId]; if (!write) return state; - return { - ...state, - writes: {}, - }; + // return { + // ...state, + // writes: {}, + // }; let hash = write.hash; if (data.type === "waitForTransactionReceipt") {