]> git.ardis.lu - erc-1967-inspector/commitdiff
Split slot and event lookups into separate queries
authorArdis Lu <ardisglu@gmail.com>
Sun, 24 Mar 2024 03:47:00 +0000 (20:47 -0700)
committerArdis Lu <ardisglu@gmail.com>
Sun, 24 Mar 2024 03:47:00 +0000 (20:47 -0700)
Fixes issue where some RPCs will abort the entire batch request because it doesn't support eth_getLogs

index.html

index 8b5004dcac879a48f54ffce98e7c5eab2e01b1b4..d11c47599efa67928294f1140ebd9d06e6c62e29 100644 (file)
       const rpc = e.target.elements['rpc'].value;
       const output = e.target.elements['output'];
 
-      const payload = [];
+      const slotPayload = [];
       const slots = {
         'Logic contract address': '0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc',
         'Beacon contract address': '0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50',
         'Admin address': '0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103'
       }
       for (const [key, value] of Object.entries(slots)) {
-        payload.push({
+        slotPayload.push({
           jsonrpc: '2.0',
           id: key,
           method: 'eth_getStorageAt',
           params: [contract, value, 'latest']
         });
       }
+
+      const eventPayload = [];
       const events = {
         'Upgraded': '0xbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b',
         'Beacon upgraded': '0x1cf3b03a6cf19fa2baba4df148e9dcabedea7f8a5c07840e207e5c089be95d3e',
         'Admin changed': '0x7e644d79422f17c01e4894b5f4f588d331ebfa28653d42ae832dc59e38c9798f'
       }
       for (const [key, value] of Object.entries(events)) {
-        payload.push({
+        eventPayload.push({
           jsonrpc: '2.0',
           id: key,
           method: 'eth_getLogs',
         });
       }
 
-      const results = await fetch(rpc, {
-        method: 'POST',
-        headers: { 'Content-Type': 'application/json' },
-        body: JSON.stringify(payload)
-      }).then(r => r.json());
+      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) {
This page took 0.039434 seconds and 4 git commands to generate.