Created
November 11, 2025 13:44
-
-
Save SgtPooki/03e0f3bf3a5f63bc4eb2b02fc342acf2 to your computer and use it in GitHub Desktop.
view piece metadata for a log, e.g. on a page like https://calibration.filfox.info/en/tx/0x4ac4b4e4a97f53777fdc3ed260778ed1b782f09da11d45ff4d05e13b0af9410f?t=3
This file contains hidden or 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
| ;(async () => { | |
| const { ethers } = await import('https://cdn.jsdelivr.net/npm/[email protected]/dist/ethers.min.js') | |
| const abi = [ | |
| 'event PieceAdded(uint256 indexed dataSetId,uint256 indexed pieceId,tuple(bytes raw) pieceCid,string[] metadataKeys,string[] metadataValues)', | |
| ] | |
| const iface = new ethers.Interface(abi) | |
| const event = iface.getEvent('PieceAdded') | |
| const getFieldNode = (container, label) => { | |
| for (const dt of container.querySelectorAll('dt')) { | |
| if (dt.textContent.trim() === label) return dt.nextElementSibling ?? null | |
| } | |
| return null | |
| } | |
| const logContainers = [...document.querySelectorAll('div.border-background.py-1.pr-4.border-t')] | |
| const pieceAddedContainers = logContainers.filter((container) => { | |
| const nameNode = getFieldNode(container, 'Name') | |
| return nameNode?.textContent.trim().startsWith('PieceAdded(') | |
| }) | |
| if (pieceAddedContainers.length === 0) { | |
| console.warn('No PieceAdded logs found on this page.') | |
| return | |
| } | |
| for (const container of pieceAddedContainers) { | |
| const topicsNode = getFieldNode(container, 'Topics') | |
| const topicRows = topicsNode ? [...topicsNode.querySelectorAll('div.flex.items-center')] : [] | |
| const topics = topicRows | |
| .map((row) => row.textContent.match(/0x[a-fA-F0-9]+/g)?.pop() ?? null) | |
| .filter((value) => value != null) | |
| const dataNode = getFieldNode(container, 'Data') | |
| const data = dataNode?.querySelector('pre')?.textContent.trim() | |
| if (!data || topics.length < 3) { | |
| console.warn('Skipping log: missing topics or data', container) | |
| continue | |
| } | |
| const decoded = iface.decodeEventLog(event, data, topics) | |
| const metadata = Object.fromEntries( | |
| decoded.metadataKeys.map((key, idx) => [key, decoded.metadataValues[idx] ?? null]) | |
| ) | |
| console.log('--- PieceAdded log ---') | |
| console.log('dataSetId:', decoded.dataSetId.toString()) | |
| console.log('pieceId:', decoded.pieceId.toString()) | |
| console.log('metadata:', metadata) | |
| } | |
| })() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment