From e8aad7f01da28b2acc327cd77dba1c3041486da4 Mon Sep 17 00:00:00 2001 From: Ardis Lu Date: Sun, 30 Apr 2023 23:43:20 -0700 Subject: [PATCH] Handle smart contracts with Swarm hash --- index.html | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) 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); + 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 = JSON.stringify(json); + result.textContent = output; }) -- 2.47.3