Skip to content

Commit 2a6192d

Browse files
Merge pull request #46 from walnuthq/44-re-simulating-transaction-not-functional
Tx hash is not mandatory in for the events
2 parents 6b5450f + 8a32e40 commit 2a6192d

File tree

4 files changed

+126
-22
lines changed

4 files changed

+126
-22
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { NextRequest, NextResponse } from 'next/server';
2+
import { soldbListEvents } from '@/app/api/v1/soldb';
3+
import { getRpcUrlForChainOptimized } from '@/lib/public-network-utils';
4+
import { getServerSession } from '@/lib/auth-server';
5+
6+
export const POST = async (request: NextRequest) => {
7+
try {
8+
const { txHash, chainId } = await request.json();
9+
10+
if (!txHash) {
11+
return NextResponse.json({ error: 'Transaction hash is required' }, { status: 400 });
12+
}
13+
14+
if (!chainId) {
15+
return NextResponse.json({ error: 'Chain ID is required' }, { status: 400 });
16+
}
17+
18+
const authSession = await getServerSession();
19+
const rpcUrl = getRpcUrlForChainOptimized(chainId, authSession?.session || null);
20+
21+
const events = await soldbListEvents({
22+
txHash,
23+
rpcUrl,
24+
ethdebugDirs: [], // Add ethdebugDirs if needed
25+
cwd: process.env.PWD
26+
});
27+
28+
return NextResponse.json({ events });
29+
} catch (err: any) {
30+
console.error('Error fetching events:', err);
31+
return NextResponse.json(
32+
{
33+
error: 'Failed to fetch events',
34+
details: err?.message || 'Unknown error'
35+
},
36+
{ status: 500 }
37+
);
38+
}
39+
};

src/app/api/v1/soldb.ts

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,4 +159,81 @@ const soldb = async ({
159159
}
160160
};
161161

162+
export const soldbListEvents = async ({
163+
txHash,
164+
rpcUrl,
165+
ethdebugDirs,
166+
cwd
167+
}: {
168+
txHash: string;
169+
rpcUrl: string;
170+
ethdebugDirs?: string[];
171+
cwd?: string;
172+
}): Promise<any> => {
173+
const args = ['list-events', txHash, '--json-events'];
174+
175+
if (rpcUrl) {
176+
args.push('--rpc', rpcUrl);
177+
}
178+
179+
if (ethdebugDirs && ethdebugDirs.length > 0) {
180+
ethdebugDirs.forEach((dir) => {
181+
args.push('--ethdebug-dir', dir);
182+
});
183+
}
184+
185+
console.log('Executing soldb command:', ['soldb', ...args].join(' '));
186+
if (cwd) {
187+
console.log('Working directory:', cwd);
188+
}
189+
190+
try {
191+
const { stdout } = await execFile('soldb', args, {
192+
cwd: cwd || process.cwd(),
193+
maxBuffer: 50 * 1024 * 1024 // 50MB buffer
194+
});
195+
return JSON.parse(stdout);
196+
} catch (err: any) {
197+
const sanitizedMessage = sanitizeErrorMessage(err.message || String(err));
198+
console.error('soldb list-events error:', sanitizedMessage);
199+
200+
if (isSoldbNotInstalledError(err)) {
201+
throw wrapError(err, undefined, null);
202+
}
203+
204+
if (isTimeoutError(err)) {
205+
throw new SoldbTimeoutError(undefined, null);
206+
}
207+
208+
if (isConnectionError(err)) {
209+
throw new RpcConnectionError(undefined, err, null);
210+
}
211+
212+
let errorMessage = 'Failed to fetch events';
213+
if (err.stdout) {
214+
errorMessage = err.stdout.trim();
215+
} else if (err.message) {
216+
errorMessage = err.message;
217+
}
218+
219+
try {
220+
const jsonResponse = JSON.parse(errorMessage);
221+
if (jsonResponse.soldbFailed || jsonResponse.error?.message) {
222+
const parts = [];
223+
if (jsonResponse.soldbFailed) {
224+
parts.push(jsonResponse.soldbFailed);
225+
}
226+
if (jsonResponse.error?.message) {
227+
parts.push(jsonResponse.error.message);
228+
}
229+
errorMessage = parts.join(' - ');
230+
}
231+
} catch {
232+
// If not JSON, use the original message
233+
}
234+
235+
throw new SoldbExecutionError(errorMessage, undefined, undefined, null);
236+
}
237+
};
238+
162239
export default soldb;

src/components/call-trace/root.tsx

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -53,26 +53,14 @@ export function CallTraceRoot({
5353
l1DataFlamegraph={l1DataFlamegraph}
5454
debuggerPayload={debuggerPayload}
5555
>
56-
{txHash && (
57-
<EventsContextProvider txHash={txHash} chainId={chainId} rpcUrl={rpcUrl} shouldLoad={true}>
58-
{debuggerPayload && (
59-
<DebuggerContextProvider debuggerPayload={debuggerPayload}>
60-
<CallTraceRootContent txHash={txHash} />
61-
</DebuggerContextProvider>
62-
)}
63-
{!debuggerPayload && <CallTraceRootContent txHash={txHash} />}
64-
</EventsContextProvider>
65-
)}
66-
{!txHash && (
67-
<>
68-
{debuggerPayload && (
69-
<DebuggerContextProvider debuggerPayload={debuggerPayload}>
70-
<CallTraceRootContent txHash={txHash} />
71-
</DebuggerContextProvider>
72-
)}
73-
{!debuggerPayload && <CallTraceRootContent txHash={txHash} />}
74-
</>
75-
)}
56+
<EventsContextProvider txHash={txHash} chainId={chainId} rpcUrl={rpcUrl} shouldLoad={true}>
57+
{debuggerPayload && (
58+
<DebuggerContextProvider debuggerPayload={debuggerPayload}>
59+
<CallTraceRootContent txHash={txHash} />
60+
</DebuggerContextProvider>
61+
)}
62+
{!debuggerPayload && <CallTraceRootContent txHash={txHash} />}
63+
</EventsContextProvider>
7664
</CallTraceContextProvider>
7765
);
7866
}
@@ -220,7 +208,7 @@ function CallTraceRootContent({ txHash }: { txHash?: string }) {
220208
<ScrollBar orientation="horizontal" />
221209
</ScrollArea>
222210
) : (
223-
<div className="px-4 py-2 text-sm">Transaction hash not available</div>
211+
<div className="px-4 py-2 text-sm">Data unavailable</div>
224212
)}
225213
</div>
226214
</TabsContent>

src/lib/context/events-context-provider.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export const useEvents = () => {
2828

2929
interface EventsContextProviderProps {
3030
children: React.ReactNode;
31-
txHash: string;
31+
txHash?: string;
3232
chainId?: string;
3333
rpcUrl?: string;
3434
shouldLoad?: boolean;

0 commit comments

Comments
 (0)