From 98c0f0306db3ff96d96f42580338a9161bb5fc60 Mon Sep 17 00:00:00 2001 From: Ardis Lu Date: Tue, 2 Apr 2024 21:56:56 -0700 Subject: [PATCH] Decouple slot and event lookups Free public endpoints usually block event lookups, resulting in indefinite blocking even though slot lookup is complete. --- index.html | 56 +++++++++++++++++++++++++++++------------------------- 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/index.html b/index.html index ba57363..b10abdf 100644 --- a/index.html +++ b/index.html @@ -115,35 +115,39 @@ }); } - 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', `

${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)}

`); + + // 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', `

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

`) })); + + // 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', `

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

`); + 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