-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #370 from Blobscan/feat/web/starknet-blobs-decoding
feat: decode Starknet blobs
- Loading branch information
Showing
52 changed files
with
1,339 additions
and
172 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@blobscan/web": minor | ||
--- | ||
|
||
Added starknet decoded blob view |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@blobscan/web": patch | ||
--- | ||
|
||
Fixed dropdown list |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@blobscan/blob-decoder": patch | ||
"@blobscan/web": patch | ||
--- | ||
|
||
Handled blob decoding errors |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@blobscan/web": minor | ||
--- | ||
|
||
Added rollup tag to blob details page |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@blobscan/blob-decoder": minor | ||
--- | ||
|
||
Added starknet blob decoder |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
function maskSensitiveData(sensitiveData) { | ||
return sensitiveData?.replace(/./g, "*"); | ||
} | ||
|
||
export function printBanner() { | ||
console.log(" ____ _ _"); | ||
console.log("| __ )| | ___ | |__ ___ ___ __ _ _ __"); | ||
console.log("| _ \\| |/ _ \\| '_ \\/ __|/ __/ _` | '_ \\"); | ||
console.log("| |_) | | (_) | |_) \\__ \\ (_| (_| | | | |"); | ||
console.log("|____/|_|\\___/|_.__/|___/\\___\\__,_|_| |_|"); | ||
console.log("Blobscan Web App (EIP-4844 blob explorer) - blobscan.com"); | ||
console.log("=======================================================\n"); | ||
console.log( | ||
`Configuration: network=${process.env.NEXT_PUBLIC_NETWORK_NAME} explorer=${ | ||
process.env.NEXT_PUBLIC_EXPLORER_BASE_URL | ||
} beaconExplorer=${ | ||
process.env.NEXT_PUBLIC_BEACON_BASE_URL | ||
} feedbackEnabled=${!!process.env | ||
.FEEDBACK_WEBHOOK_URL} tracesEnabled=${!!process.env | ||
.TRACES_ENABLED} sentryEnabled=${!!process.env | ||
.NEXT_PUBLIC_SENTRY_DSN_WEB}` | ||
); | ||
console.log( | ||
`Blob storage manager configuration: chainId=${process.env.CHAIN_ID}, file_system=${process.env.FILE_SYSTEM_STORAGE_ENABLED} postgres=${process.env.POSTGRES_STORAGE_ENABLED}, gcs=${process.env.GOOGLE_STORAGE_ENABLED}, swarm=${process.env.SWARM_STORAGE_ENABLED}` | ||
); | ||
|
||
if (process.env.GOOGLE_STORAGE_ENABLED) { | ||
console.log( | ||
`GCS configuration: bucketName=${ | ||
process.env.GOOGLE_STORAGE_BUCKET_NAME | ||
}, projectId=${maskSensitiveData( | ||
process.env.GOOGLE_STORAGE_PROJECT_ID | ||
)}, apiEndpoint=${process.env.GOOGLE_STORAGE_API_ENDPOINT}` | ||
); | ||
} | ||
|
||
if (process.env.SWARM_STORAGE_ENABLED) { | ||
console.log( | ||
`Swarm configuration: beeEndpoint=${process.env.BEE_ENDPOINT}, debugEndpoint=${process.env.BEE_DEBUG_ENDPOINT}` | ||
); | ||
} | ||
|
||
if (process.env.FILE_SYSTEM_STORAGE_ENABLED) { | ||
console.log( | ||
`File system configuration: blobDirPath=${process.env.FILE_SYSTEM_STORAGE_PATH}` | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { decodeBlob, isValidDecoder } from "@blobscan/blob-decoder"; | ||
|
||
type BlobDecoderEvent = { | ||
blobData?: string; | ||
decoder?: string; | ||
}; | ||
|
||
addEventListener("message", (event: MessageEvent<BlobDecoderEvent>) => { | ||
try { | ||
const { decoder, blobData } = event.data; | ||
|
||
if (!decoder) { | ||
throw new Error("No decoder provided"); | ||
} | ||
|
||
if (!blobData) { | ||
throw new Error("No blob data provided"); | ||
} | ||
|
||
if (isValidDecoder(decoder)) { | ||
decodeBlob(blobData, decoder).then((result) => { | ||
postMessage({ decodedBlob: result }); | ||
}); | ||
} else { | ||
throw new Error(`${decoder} decoder is not supported`); | ||
} | ||
} catch (err) { | ||
postMessage({ error: (err as Error).message }); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import type { FC } from "react"; | ||
import { ExclamationCircleIcon } from "@heroicons/react/24/outline"; | ||
|
||
export type ErrorMessageProps = { | ||
error: string | Error; | ||
}; | ||
|
||
export const ErrorMessage: FC<ErrorMessageProps> = function ({ error }) { | ||
return ( | ||
<div className="flex h-32 w-full items-center justify-center gap-2 text-sm text-error-600 dark:text-error-300"> | ||
<ExclamationCircleIcon className="h-6 w-6" /> | ||
<div>{error instanceof Error ? error.message : error}</div> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import type { FC } from "react"; | ||
import Skeleton from "react-loading-skeleton"; | ||
|
||
import "react-loading-skeleton/dist/skeleton.css"; | ||
import { ExpandableContent } from "../../ExpandableContent"; | ||
import type { BlobViewProps } from "../index"; | ||
|
||
export type RawBlobViewProps = BlobViewProps<string>; | ||
|
||
export const RawBlobView: FC<RawBlobViewProps> = function ({ data }) { | ||
return ( | ||
<div className="break-words p-3 text-left text-sm leading-7"> | ||
{data !== undefined ? ( | ||
<ExpandableContent>{data}</ExpandableContent> | ||
) : ( | ||
<Skeleton count={10} /> | ||
)} | ||
</div> | ||
); | ||
}; |
163 changes: 163 additions & 0 deletions
163
apps/web/src/components/BlobViewer/Views/StarknetBlobView.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
import { useState, useEffect, useRef } from "react"; | ||
import type { FC } from "react"; | ||
|
||
import type { DecodedStarknetBlob } from "@blobscan/blob-decoder"; | ||
|
||
import { Table } from "~/components/Table"; | ||
import { Toggle } from "~/components/Toggle"; | ||
import { ErrorMessage } from "../ErrorMessage"; | ||
import type { BlobViewProps } from "../index"; | ||
|
||
export type StarknetBlobViewProps = BlobViewProps<DecodedStarknetBlob>; | ||
|
||
function hexToBigInt(hex: string): string { | ||
return BigInt(hex).toString(10); | ||
} | ||
export const StarknetBlobView: FC<StarknetBlobViewProps> = function ({ | ||
data: stateDiffsProps, | ||
}) { | ||
const originalStateDiffsRef = useRef<DecodedStarknetBlob>(); | ||
const [stateDiffs, setStateDiffs] = useState< | ||
DecodedStarknetBlob | undefined | null | ||
>(stateDiffsProps); | ||
const [originalDataToggle, setOriginalDataToggle] = useState<boolean>(false); | ||
|
||
useEffect(() => { | ||
if (originalDataToggle) { | ||
let cachedOriginalStateDiffs = originalStateDiffsRef.current; | ||
if (!cachedOriginalStateDiffs) { | ||
cachedOriginalStateDiffs = stateDiffsProps?.map( | ||
({ | ||
contractAddress, | ||
newClassHash, | ||
nonce, | ||
numberOfStorageUpdates, | ||
storageUpdates, | ||
}) => ({ | ||
contractAddress: hexToBigInt(contractAddress), | ||
newClassHash: hexToBigInt(newClassHash), | ||
nonce, | ||
numberOfStorageUpdates, | ||
storageUpdates: storageUpdates.map(({ key, value }) => ({ | ||
key: hexToBigInt(key), | ||
value: hexToBigInt(value), | ||
})), | ||
}) | ||
); | ||
|
||
originalStateDiffsRef.current = cachedOriginalStateDiffs; | ||
} | ||
|
||
setStateDiffs(cachedOriginalStateDiffs); | ||
} else { | ||
setStateDiffs(stateDiffsProps); | ||
} | ||
}, [originalDataToggle, stateDiffsProps, originalStateDiffsRef]); | ||
|
||
if (!stateDiffs) { | ||
return <ErrorMessage error="No starknet state diffs found" />; | ||
} | ||
|
||
return ( | ||
<Table | ||
expandableRowsMode | ||
headers={[ | ||
{ | ||
cells: [ | ||
{ | ||
item: ( | ||
<div className="relative w-full"> | ||
Starknet State Diffs ({stateDiffs.length}){" "} | ||
<div className="absolute right-10 top-1"> | ||
<div className="flex items-center justify-center gap-2"> | ||
<Toggle | ||
onToggle={() => | ||
setOriginalDataToggle((prevToggle) => !prevToggle) | ||
} | ||
/>{" "} | ||
<div className="text-xs text-contentSecondary-light dark:text-contentSecondary-dark"> | ||
Original Data | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
), | ||
alignment: "center", | ||
}, | ||
], | ||
spanFullRow: true, | ||
}, | ||
{ | ||
cells: [ | ||
{ | ||
item: "Contract Address", | ||
}, | ||
{ | ||
item: "New Class Hash", | ||
}, | ||
{ | ||
item: "Nonce", | ||
}, | ||
], | ||
}, | ||
]} | ||
rows={stateDiffs.map( | ||
({ contractAddress, newClassHash, nonce, storageUpdates }) => ({ | ||
cells: [ | ||
{ | ||
item: contractAddress, | ||
}, | ||
{ | ||
item: newClassHash, | ||
}, | ||
{ | ||
item: nonce, | ||
}, | ||
], | ||
expandItem: ( | ||
<Table | ||
className="max-h-[420px]" | ||
size="xs" | ||
alignment="center" | ||
variant="simple" | ||
headers={[ | ||
{ | ||
cells: [ | ||
{ | ||
item: `Storage Updades (${storageUpdates.length})`, | ||
spanFullRow: true, | ||
}, | ||
], | ||
className: "border-none", | ||
}, | ||
{ | ||
cells: [ | ||
{ | ||
item: "Key", | ||
}, | ||
{ | ||
item: "Value", | ||
}, | ||
], | ||
className: "dark:border-border-dark/20", | ||
sticky: true, | ||
}, | ||
]} | ||
rows={storageUpdates.map(({ key, value }) => ({ | ||
cells: [ | ||
{ | ||
item: key, | ||
}, | ||
{ | ||
item: value, | ||
}, | ||
], | ||
className: "dark:border-border-dark/10", | ||
}))} | ||
/> | ||
), | ||
}) | ||
)} | ||
/> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from "./RawBlobView"; | ||
export * from "./StarknetBlobView"; |
Oops, something went wrong.