From: Ardis Lu Date: Mon, 1 May 2023 06:43:20 +0000 (-0700) Subject: Handle smart contracts with Swarm hash X-Git-Url: https://git.ardis.lu/?a=commitdiff_plain;h=e8aad7f01da28b2acc327cd77dba1c3041486da4;p=solc-metadata Handle smart contracts with Swarm hash --- diff --git a/index.html b/index.html index 0a76f0d..78feef0 100644 --- a/index.html +++ b/index.html @@ -117,10 +117,23 @@ const bytecode = await fetchBytecode(address, rpc); const cbor = extractCBOR(bytecode); const metadata = decodeCBOR(cbor); - const { cidV0, cidV1 } = calculateCID(metadata); - const json = await fetchJSONMetadata(cidV1, ipfs); - - result.textContent = JSON.stringify(json); + let output; + if (metadata.bzzr0 !== undefined) { + const hex = [...metadata.bzzr0].map(b => b.toString(16).padStart(2, '0')).join(''); + output = 'Unable to fetch metadata because the smart contract uses a Swarm hash. Swarm hash below:\n'; + output += `bzzr://${hex}`; + } + else if (metadata.bzzr1 !== undefined) { + const hex = [...metadata.bzzr0].map(b => b.toString(16).padStart(2, '0')).join(''); + output = 'Unable to fetch metadata because the smart contract uses a Swarm hash. Swarm hash below:\n'; + output += `bzz-raw://${hex}`; + } + else { + const { cidV0, cidV1 } = calculateCID(metadata); + output = JSON.stringify(await fetchJSONMetadata(cidV1, ipfs)); + } + + result.textContent = output; })