From 8021d698472392997485e2391140131b6e2a78ff Mon Sep 17 00:00:00 2001 From: Ardis Lu Date: Fri, 22 Mar 2024 23:23:31 -0700 Subject: [PATCH] Implement basic historical change lookup Public RPCs do not generally support eth_getLogs, so must use another --- index.html | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/index.html b/index.html index abcbd07..8b5004d 100644 --- a/index.html +++ b/index.html @@ -68,12 +68,12 @@ 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', @@ -82,6 +82,24 @@ 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', @@ -91,7 +109,19 @@ output.innerHTML = ''; for (const item of results) { - output.insertAdjacentHTML('beforeend', `

${item.id}: 0x${item.result.substring(26)}

`); + if (typeof item.result === 'string') { // Storage slot lookup + output.insertAdjacentHTML('beforeend', `

${item.id}: 0x${item.result.substring(26)}

`); + } + else { // Event lookup + for (const log of item.result) { + if (log.data === '0x') { // Upgraded event (new address is indexed) + output.insertAdjacentHTML('beforeend', `

${item.id} (block ${Number(log.blockNumber)}): 0x${log.topics[1].substring(26)}

`); + } + else { // Admin changed event (new address is not indexed) + output.insertAdjacentHTML('beforeend', `

${item.id} (block ${Number(log.blockNumber)}): 0x${log.data.slice(-40)}

`); + } + } + } } }); -- 2.47.3