Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(explorer): decoded callFrom transactions #3364

Merged
merged 5 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/mighty-lions-move.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@latticexyz/explorer": patch
---

Transactions in `Observe` tab now display decoded `callFrom` function calls.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { cn } from "../../../../../../utils";
import { Confirmations } from "./Confirmations";
import { TimingRowExpanded } from "./TimingRowExpanded";
import { columns } from "./TransactionsTable";
import { ObservedTransaction } from "./useObservedTransactions";
import { ObservedTransaction } from "./useMergedTransactions";

function TransactionTableRowDataCell({
label,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { BlockExplorerLink } from "./BlockExplorerLink";
import { TimeAgo } from "./TimeAgo";
import { TimingRowHeader } from "./TimingRowHeader";
import { TransactionTableRow } from "./TransactionTableRow";
import { ObservedTransaction, useObservedTransactions } from "./useObservedTransactions";
import { ObservedTransaction, useMergedTransactions } from "./useMergedTransactions";

const columnHelper = createColumnHelper<ObservedTransaction>();
export const columns = [
Expand Down Expand Up @@ -101,7 +101,7 @@ export const columns = [
];

export function TransactionsTable() {
const transactions = useObservedTransactions();
const transactions = useMergedTransactions();
const [expanded, setExpanded] = useState<ExpandedState>({});

const table = useReactTable({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export function TransactionsWatcher() {
setTransaction({
hash,
writeId: writeId ?? hash,
from: transaction.from,
from: calls[0]?.from ?? transaction.from,
timestamp,
transaction,
calls,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { store as worldStore } from "../store";

export type DecodedUserOperationCall = {
to?: Address;
from?: Address;
functionName: string;
args?: readonly unknown[];
value?: bigint;
Expand All @@ -28,7 +29,7 @@ export type ObservedTransaction = {
error?: BaseError;
};

export function useObservedTransactions() {
export function useMergedTransactions() {
const { worldAddress } = useParams<{ worldAddress: string }>();
const transactions = useStore(worldStore, (state) => state.transactions);
const observerWrites = useStore(observerStore, (state) => state.writes);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Abi, Address, Hex, decodeFunctionData } from "viem";
import { DecodedUserOperationCall } from "../useObservedTransactions";
import { DecodedUserOperationCall } from "../useMergedTransactions";

export function getDecodedUserOperationCalls({
abi,
Expand Down Expand Up @@ -36,16 +36,27 @@ function getDecodedUserOperationCall({
}): DecodedUserOperationCall {
let functionName: string | undefined;
let args: readonly unknown[] | undefined;
let from: Address | undefined;

try {
const functionData = decodeFunctionData({ abi, data: data });
functionName = functionData.functionName;
args = functionData.args;

if (functionName === "callFrom") {
const [delegator, , data] = args as [Address, Hex, Hex];
const decodedCallData = decodeFunctionData({ abi, data });
functionName = decodedCallData.functionName;
args = decodedCallData.args;
from = delegator;
}
} catch (error) {
functionName = data.length > 10 ? data.slice(0, 10) : "unknown";
}

return {
to: target,
from,
functionName,
args,
value,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createStore } from "zustand";
import { ObservedTransaction } from "./observe/useObservedTransactions";
import { ObservedTransaction } from "./observe/useMergedTransactions";

export type State = {
transactions: ObservedTransaction[];
Expand Down
2 changes: 0 additions & 2 deletions packages/explorer/src/observer/decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ export function observer({ explorerUrl = "http://localhost:13690", waitForTransa

emit("write", {
writeId,
from: client.account!.address,
karooolis marked this conversation as resolved.
Show resolved Hide resolved
calls,
});
Promise.allSettled([write]).then(([result]) => {
Expand Down Expand Up @@ -78,7 +77,6 @@ export function observer({ explorerUrl = "http://localhost:13690", waitForTransa

emit("write", {
writeId,
from: client.account!.address,
calls: [
{
to: args.address,
Expand Down
5 changes: 2 additions & 3 deletions packages/explorer/src/observer/messages.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Address, Hash } from "viem";
import { Hash } from "viem";
import { UserOperationReceipt } from "viem/account-abstraction";
import { DecodedUserOperationCall } from "../app/(explorer)/[chainName]/worlds/[worldAddress]/observe/useObservedTransactions";
import { DecodedUserOperationCall } from "../app/(explorer)/[chainName]/worlds/[worldAddress]/observe/useMergedTransactions";
import { ReceiptSummary } from "./common";

export type Messages = {
Expand All @@ -11,7 +11,6 @@ export type Messages = {
};
write: {
writeId: string;
from: Address;
calls: DecodedUserOperationCall[];
value?: bigint;
};
Expand Down
4 changes: 2 additions & 2 deletions packages/explorer/src/observer/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { Address, Hash } from "viem";
import { createStore } from "zustand/vanilla";
import { DecodedUserOperationCall } from "../app/(explorer)/[chainName]/worlds/[worldAddress]/observe/useObservedTransactions";
import { DecodedUserOperationCall } from "../app/(explorer)/[chainName]/worlds/[worldAddress]/observe/useMergedTransactions";
import { isPromiseFulfilled } from "../utils";
import { relayChannelName } from "./common";
import { debug } from "./debug";
Expand All @@ -12,8 +12,8 @@ export type Write = {
writeId: string;
type: MessageType;
hash?: Hash;
from?: Address;
userOpHash?: Hash;
from: Address;
time: number;
calls: DecodedUserOperationCall[];
events: Message<Exclude<MessageType, "ping">>[];
Expand Down
Loading