From cff860d04bb01773d04c355784161085ab551da1 Mon Sep 17 00:00:00 2001 From: Ardis Lu Date: Sat, 23 Mar 2024 20:47:00 -0700 Subject: [PATCH] Split slot and event lookups into separate queries Fixes issue where some RPCs will abort the entire batch request because it doesn't support eth_getLogs --- index.html | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/index.html b/index.html index 8b5004d..d11c475 100644 --- a/index.html +++ b/index.html @@ -68,27 +68,29 @@ 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', @@ -101,11 +103,18 @@ }); } - 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) { -- 2.47.3