-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix display decoded data for Optimism blobs (#608)
* fix timestamp * chore: Add a trailing '...' to the parent L2 block hash * chore: add full block hash * fix(web): format block timestamp in tx page * Update packages/api/src/routers/block/getByPartialHash.ts Co-authored-by: elessar.eth <[email protected]> * chore: move getFullBlockHash to utils * refactor(api): adds parseDecodedFields * refactor(web): remove unused file from tsconfig.json * chore: update snapshots * test: update snapshots * refactor(api): add logging for failed block hash retrieval in parseOptimismDecodedData * Update packages/api/src/blob-parse/optimism.ts * refactor: rename to autocompleteBlockHash * refactor(api): update autocompleteBlockHash to handle multiple results and add logging * chore: adds changeset * chore: update changeset * Update packages/api/src/utils/autocompleteBlockHash.ts --------- Co-authored-by: elessar.eth <[email protected]> Co-authored-by: Pablo Castellano <[email protected]>
- Loading branch information
1 parent
5272928
commit 4226258
Showing
8 changed files
with
372 additions
and
91 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": patch | ||
--- | ||
|
||
Improved decoding display for Optimism blobs; removed truncated Parent L2 block hash link, fixed L1 origin block redirection, and corrected timestamp. |
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,36 @@ | ||
import { z } from "zod"; | ||
|
||
import { | ||
parseOptimismDecodedData, | ||
OptimismDecodedDataSchema, | ||
} from "./optimism"; | ||
|
||
const OptimismSchema = z.object({ | ||
type: z.literal("optimism"), | ||
payload: OptimismDecodedDataSchema, | ||
}); | ||
|
||
const UnknownSchema = z.object({ | ||
type: z.literal("unknown"), | ||
payload: z.string(), | ||
}); | ||
|
||
export const decodedFields = z.union([OptimismSchema, UnknownSchema]); | ||
|
||
type DecodedFields = z.infer<typeof decodedFields>; | ||
|
||
export async function parseDecodedFields(data: string): Promise<DecodedFields> { | ||
const optimismDecodedData = await parseOptimismDecodedData(data); | ||
|
||
if (optimismDecodedData) { | ||
return { | ||
type: "optimism", | ||
payload: optimismDecodedData, | ||
}; | ||
} | ||
|
||
return { | ||
type: "unknown", | ||
payload: data, | ||
}; | ||
} |
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,29 @@ | ||
import { prisma } from "@blobscan/db"; | ||
import { logger } from "@blobscan/logger"; | ||
|
||
/* Autocomplete a block hash from a truncated version of it. | ||
@param partialHash - The first bytes of a block hash. | ||
@returns The block hash, if there is a single ocurrence, or null. | ||
*/ | ||
export async function autocompleteBlockHash(partialHash: string) { | ||
const blocks = await prisma.block.findMany({ | ||
where: { | ||
hash: { | ||
startsWith: partialHash, | ||
}, | ||
}, | ||
select: { | ||
hash: true, | ||
}, | ||
}); | ||
|
||
if (blocks[0] === undefined) { | ||
return null; | ||
} | ||
|
||
if (blocks.length > 1) { | ||
logger.error(`Multiple blocks found for hash ${partialHash}`); | ||
} | ||
|
||
return blocks[0].hash; | ||
} |
Oops, something went wrong.