Skip to content
This repository was archived by the owner on Jul 15, 2026. It is now read-only.

Commit f95001d

Browse files
committed
spike
1 parent e536aa4 commit f95001d

3 files changed

Lines changed: 39 additions & 27 deletions

File tree

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@ import { type NextRequest, NextResponse } from "next/server";
22
import { type BundleEvent, getBundleHistory } from "@/lib/s3";
33

44
export interface BundleHistoryResponse {
5-
uuid: string;
5+
hash: string;
66
history: BundleEvent[];
77
}
88

99
export async function GET(
1010
_request: NextRequest,
11-
{ params }: { params: Promise<{ uuid: string }> },
11+
{ params }: { params: Promise<{ hash: string }> },
1212
) {
1313
try {
14-
const { uuid } = await params;
14+
const { hash } = await params;
1515

16-
const bundle = await getBundleHistory(uuid);
16+
const bundle = await getBundleHistory(hash);
1717
if (!bundle) {
1818
return NextResponse.json({ error: "Bundle not found" }, { status: 404 });
1919
}
@@ -24,7 +24,7 @@ export async function GET(
2424
);
2525

2626
const response: BundleHistoryResponse = {
27-
uuid,
27+
hash,
2828
history: bundle.history,
2929
};
3030

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
import Link from "next/link";
44
import { useEffect, useState } from "react";
5-
import type { BundleHistoryResponse } from "@/app/api/bundle/[uuid]/route";
5+
import type { BundleHistoryResponse } from "@/app/api/bundle/[hash]/route";
66
import type { BundleTransaction, MeterBundleResponse } from "@/lib/s3";
77

88
const WEI_PER_GWEI = 10n ** 9n;
99
const WEI_PER_ETH = 10n ** 18n;
1010
const BLOCK_EXPLORER_URL = process.env.NEXT_PUBLIC_BLOCK_EXPLORER_URL;
1111

1212
interface PageProps {
13-
params: Promise<{ uuid: string }>;
13+
params: Promise<{ hash: string }>;
1414
}
1515

1616
function formatBigInt(value: bigint, decimals: number, scale: bigint): string {
@@ -474,21 +474,21 @@ function SectionTitle({ children }: { children: React.ReactNode }) {
474474
}
475475

476476
export default function BundlePage({ params }: PageProps) {
477-
const [uuid, setUuid] = useState<string>("");
477+
const [hash, setHash] = useState<string>("");
478478
const [data, setData] = useState<BundleHistoryResponse | null>(null);
479479
const [loading, setLoading] = useState(true);
480480
const [error, setError] = useState<string | null>(null);
481481

482482
useEffect(() => {
483-
params.then((p) => setUuid(p.uuid));
483+
params.then((p) => setHash(p.hash));
484484
}, [params]);
485485

486486
useEffect(() => {
487-
if (!uuid) return;
487+
if (!hash) return;
488488

489489
const fetchData = async () => {
490490
try {
491-
const response = await fetch(`/api/bundle/${uuid}`);
491+
const response = await fetch(`/api/bundle/${hash}`);
492492
if (!response.ok) {
493493
setError(
494494
response.status === 404
@@ -511,9 +511,9 @@ export default function BundlePage({ params }: PageProps) {
511511
fetchData();
512512
const interval = setInterval(fetchData, 5000);
513513
return () => clearInterval(interval);
514-
}, [uuid]);
514+
}, [hash]);
515515

516-
if (!uuid || (loading && !data)) {
516+
if (!hash || (loading && !data)) {
517517
return (
518518
<div className="min-h-screen bg-gray-50 flex items-center justify-center">
519519
<div className="flex items-center gap-3">
@@ -564,9 +564,9 @@ export default function BundlePage({ params }: PageProps) {
564564
</div>
565565
<div className="flex items-center gap-2 text-sm">
566566
<code className="font-mono text-gray-600 bg-gray-100 px-2 py-1 rounded text-xs">
567-
{uuid}
567+
{hash}
568568
</code>
569-
<CopyButton text={uuid} />
569+
<CopyButton text={hash} />
570570
</div>
571571
</div>
572572
</header>

src/lib/s3.ts

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -163,24 +163,36 @@ export interface BundleHistory {
163163
}
164164

165165
export async function getBundleHistory(
166-
bundleId: string,
166+
bundleKey: string,
167167
): Promise<BundleHistory | null> {
168-
const key = `bundles/${bundleId}`;
169-
const content = await getObjectContent(key);
168+
const prefix = `bundles/${bundleKey}/`;
169+
const listCommand = new ListObjectsV2Command({
170+
Bucket: BUCKET_NAME,
171+
Prefix: prefix,
172+
});
170173

171-
if (!content) {
174+
const listResponse = await s3Client.send(listCommand);
175+
const keys = listResponse.Contents?.map((obj) => obj.Key).filter(
176+
Boolean,
177+
) as string[];
178+
179+
if (!keys || keys.length === 0) {
172180
return null;
173181
}
174182

175-
try {
176-
return JSON.parse(content) as BundleHistory;
177-
} catch (error) {
178-
console.error(
179-
`Failed to parse bundle history for bundle ${bundleId}:`,
180-
error,
181-
);
182-
return null;
183+
const history: BundleEvent[] = [];
184+
for (const key of keys) {
185+
const content = await getObjectContent(key);
186+
if (content) {
187+
try {
188+
history.push(JSON.parse(content) as BundleEvent);
189+
} catch (error) {
190+
console.error(`Failed to parse event at ${key}:`, error);
191+
}
192+
}
183193
}
194+
195+
return { history };
184196
}
185197

186198
export interface BlockTransaction {

0 commit comments

Comments
 (0)