]> git.ardis.lu - erc-1967-inspector/commitdiff
Decouple slot and event lookups
authorArdis Lu <ardisglu@gmail.com>
Wed, 3 Apr 2024 04:56:56 +0000 (21:56 -0700)
committerArdis Lu <ardisglu@gmail.com>
Wed, 3 Apr 2024 04:56:56 +0000 (21:56 -0700)
Free public endpoints usually block event lookups, resulting in indefinite blocking even though slot lookup is complete.

index.html

index ba57363d51e919476585fbf1f800a73b77668301..b10abdf813899f4ce868efd2c9144f77df6d5a32 100644 (file)
         });
       }
 
-      const results = (await Promise.all([
-        fetch(rpc, {
-          method: 'POST',
-          headers: { 'Content-Type': 'application/json' },
-          body: JSON.stringify(slotPayload)
-        }).then(r => r.json()),
-        fetch(rpc, {
-          method: 'POST',
-          headers: { 'Content-Type': 'application/json' },
-          body: JSON.stringify(eventPayload)
-        }).then(r => r.json())
-      ])).flat().filter(r => r?.result !== undefined);
-
       output.innerHTML = '';
-      for (const item of results) {
-        if (typeof item.result === 'string') { // Storage slot lookup
-          output.insertAdjacentHTML('beforeend', `<p>${item.id}: 0x${item.result.substring(26)}</p>`);
-        }
-        else { // Event lookup
-          for (const log of item.result) {
-            if (log.data === '0x') { // Upgraded event (new address is indexed)
-              output.insertAdjacentHTML('beforeend', `<p>${item.id} (block ${Number(log.blockNumber)}): 0x${log.topics[1].substring(26)}</p>`);
+
+      // Storage slot lookup
+      fetch(rpc, {
+        method: 'POST',
+        headers: { 'Content-Type': 'application/json' },
+        body: JSON.stringify(slotPayload)
+      })
+        .then(r => r.json())
+        .then(r => r.forEach(i => { Number(i.result) === 0 || output.insertAdjacentHTML('beforeend', `<p>${i.id}: 0x${i.result.substring(26)}</p>`) }));
+
+      // Event lookup
+      fetch(rpc, {
+        method: 'POST',
+        headers: { 'Content-Type': 'application/json' },
+        body: JSON.stringify(eventPayload)
+      })
+        .then(r => r.json())
+        .then(r => {
+          r.forEach(item => {
+            if (item?.result === undefined) {
+              return;
             }
-            else { // Admin changed event (new address is not indexed)
-              output.insertAdjacentHTML('beforeend', `<p>${item.id} (block ${Number(log.blockNumber)}): 0x${log.data.slice(-40)}</p>`);
+            for (const log of item.result) {
+              if (log.data === '0x') { // Upgraded event (new address is indexed)
+                output.insertAdjacentHTML('beforeend', `<p>${item.id} (block ${Number(log.blockNumber)}): 0x${log.topics[1].substring(26)}</p>`);
+              }
+              else { // Admin changed event (new address is not indexed)
+                output.insertAdjacentHTML('beforeend', `<p>${item.id} (block ${Number(log.blockNumber)}): 0x${log.data.slice(-40)}</p>`);
+              }
             }
-          }
-        }
-      }
+          });
+        });
     });
   </script>
 </body>
This page took 0.041437 seconds and 4 git commands to generate.