]> git.ardis.lu - safe-owners/commitdiff
Simplify JSON-RPC batch
authorArdis Lu <ardisglu@gmail.com>
Mon, 2 Sep 2024 01:08:45 +0000 (18:08 -0700)
committerArdis Lu <ardisglu@gmail.com>
Mon, 2 Sep 2024 01:08:45 +0000 (18:08 -0700)
index.html

index 93f5b1d581d90747c2ce0f27c5bf908f3ca023c9..cf3a60f2e3bea0e716e28e58ce0d0a633b619244 100644 (file)
     const repeatSVG = '<svg role="img" aria-labelledby="repeat" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><title id="circular">Repeated owner</title><path d="m17 2 4 4-4 4"/><path d="M3 11v-1a4 4 0 0 1 4-4h14"/><path d="m7 22-4-4 4-4"/><path d="M21 13v1a4 4 0 0 1-4 4H3"/><path d="M11 10h1v4"/></svg>';
 
     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: [],
This page took 0.036203 seconds and 4 git commands to generate.