]> git.ardis.lu - erc-1967-inspector/commitdiff
Implement basic historical change lookup
authorArdis Lu <ardisglu@gmail.com>
Sat, 23 Mar 2024 06:23:31 +0000 (23:23 -0700)
committerArdis Lu <ardisglu@gmail.com>
Sat, 23 Mar 2024 06:23:31 +0000 (23:23 -0700)
Public RPCs do not generally support eth_getLogs, so must use another

index.html

index abcbd07a2c38a27c43e2f7a9ed53256bd684ea64..8b5004dcac879a48f54ffce98e7c5eab2e01b1b4 100644 (file)
       const rpc = e.target.elements['rpc'].value;
       const output = e.target.elements['output'];
 
+      const payload = [];
       const slots = {
         'Logic contract address': '0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc',
         'Beacon contract address': '0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50',
         'Admin address': '0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103'
       }
-      const payload = [];
       for (const [key, value] of Object.entries(slots)) {
         payload.push({
           jsonrpc: '2.0',
           params: [contract, value, 'latest']
         });
       }
+      const events = {
+        'Upgraded': '0xbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b',
+        'Beacon upgraded': '0x1cf3b03a6cf19fa2baba4df148e9dcabedea7f8a5c07840e207e5c089be95d3e',
+        'Admin changed': '0x7e644d79422f17c01e4894b5f4f588d331ebfa28653d42ae832dc59e38c9798f'
+      }
+      for (const [key, value] of Object.entries(events)) {
+        payload.push({
+          jsonrpc: '2.0',
+          id: key,
+          method: 'eth_getLogs',
+          params: [{
+            fromBlock: 'earliest',
+            toBlock: 'latest',
+            address: contract,
+            topics: [value]
+          }]
+        });
+      }
 
       const results = await fetch(rpc, {
         method: 'POST',
 
       output.innerHTML = '';
       for (const item of results) {
-        output.insertAdjacentHTML('beforeend', `<p>${item.id}: 0x${item.result.substring(26)}</p>`);
+        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>`);
+            }
+            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>
This page took 0.049202 seconds and 4 git commands to generate.