Browse Source

ts: use modern gma api (#1753)

Armani Ferrante 3 years ago
parent
commit
032525c212
1 changed files with 4 additions and 52 deletions
  1. 4 52
      ts/src/utils/rpc.ts

+ 4 - 52
ts/src/utils/rpc.ts

@@ -73,58 +73,10 @@ async function getMultipleAccountsCore(
   Array<null | { publicKey: PublicKey; account: AccountInfo<Buffer> }>
   Array<null | { publicKey: PublicKey; account: AccountInfo<Buffer> }>
 > {
 > {
   const commitment = commitmentOverride ?? connection.commitment;
   const commitment = commitmentOverride ?? connection.commitment;
-  const args: (
-    | string[]
-    | {
-        commitment: Commitment;
-      }
-  )[] = [publicKeys.map((k) => k.toBase58())];
-  if (commitment) {
-    args.push({ commitment });
-  }
-  // @ts-ignore
-  const res = await connection._rpcRequest("getMultipleAccounts", args);
-  if (res.error) {
-    throw new Error(
-      "failed to get info about accounts " +
-        publicKeys.map((k) => k.toBase58()).join(", ") +
-        ": " +
-        res.error.message
-    );
-  }
-  assert(typeof res.result !== "undefined");
-  const accounts: Array<null | {
-    executable: any;
-    owner: PublicKey;
-    lamports: any;
-    data: Buffer;
-  }> = [];
-  for (const account of res.result.value) {
-    let value: {
-      executable: any;
-      owner: PublicKey;
-      lamports: any;
-      data: Buffer;
-    } | null = null;
-    if (account === null) {
-      accounts.push(null);
-      continue;
-    }
-    if (res.result.value) {
-      const { executable, owner, lamports, data } = account;
-      assert(data[1] === "base64");
-      value = {
-        executable,
-        owner: new PublicKey(owner),
-        lamports,
-        data: Buffer.from(data[0], "base64"),
-      };
-    }
-    if (value === null) {
-      throw new Error("Invalid response");
-    }
-    accounts.push(value);
-  }
+  const accounts = await connection.getMultipleAccountsInfo(
+    publicKeys,
+    commitment
+  );
   return accounts.map((account, idx) => {
   return accounts.map((account, idx) => {
     if (account === null) {
     if (account === null) {
       return null;
       return null;