From 43197fe85c572f04d4c431b3595d405080dd5077 Mon Sep 17 00:00:00 2001 From: Ardis Lu Date: Sun, 1 Sep 2024 18:08:45 -0700 Subject: [PATCH] Simplify JSON-RPC batch --- index.html | 54 ++++++++++++++++-------------------------------------- 1 file changed, 16 insertions(+), 38 deletions(-) diff --git a/index.html b/index.html index 93f5b1d..cf3a60f 100644 --- a/index.html +++ b/index.html @@ -176,49 +176,27 @@ const repeatSVG = 'Repeated owner'; async function getOwners(safe, rpc) { + const requests = { + ownersResult: '0xa0e67e2b', // getOwners() + thresholdResult: '0xe75235b8', // getThreshold() + requiredResult: '0xdc8452cd' // required() + } + const payload = []; + for (const [id, data] of Object.entries(requests)) { + payload.push({ + jsonrpc: '2.0', + id, + method: 'eth_call', + params: [{ to: safe, data }, 'safe'] + }); + } const response = await fetch(rpc, { method: 'POST', headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify([ - { - jsonrpc: '2.0', - id: 'ownersResult', - method: 'eth_call', - params: [ - { - to: safe, - data: '0xa0e67e2b' // getOwners() - }, - 'safe' - ] - }, - { - jsonrpc: '2.0', - id: 'thresholdResult', - method: 'eth_call', - params: [ - { - to: safe, - data: '0xe75235b8' // getThreshold() - }, - 'safe' - ] - }, - { - jsonrpc: '2.0', - id: 'requiredResult', - method: 'eth_call', - params: [ - { - to: safe, - data: '0xdc8452cd' // required() - }, - 'safe' - ] - } - ]) + body: JSON.stringify(payload) }).then(r => r.json()); const { ownersResult, thresholdResult, requiredResult } = response.reduce((a, c) => ({ ...a, [c.id]: c.result }), {}); + if (ownersResult === undefined) { // Smart contract reverted return { owners: [], -- 2.47.3