]> git.ardis.lu - solc-metadata/commitdiff
Handle smart contracts with Swarm hash
authorArdis Lu <ardisglu@gmail.com>
Mon, 1 May 2023 06:43:20 +0000 (23:43 -0700)
committerArdis Lu <ardisglu@gmail.com>
Mon, 1 May 2023 06:43:20 +0000 (23:43 -0700)
index.html

index 0a76f0da0550da8f1ad5f320e4fee39379e80187..78feef0c0ad3509a65ab0db20ed414efe3435acf 100644 (file)
       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;
     })
   </script>
 </body>
This page took 0.035712 seconds and 4 git commands to generate.