|
@@ -8,6 +8,7 @@ import {
|
|
|
TransactionSignature,
|
|
|
Transaction,
|
|
|
TransactionInstruction,
|
|
|
+ Commitment,
|
|
|
} from "@solana/web3.js";
|
|
|
import { chunks } from "../utils/common.js";
|
|
|
import { Address, translateAddress } from "../program/common.js";
|
|
@@ -44,29 +45,44 @@ const GET_MULTIPLE_ACCOUNTS_LIMIT: number = 99;
|
|
|
|
|
|
export async function getMultipleAccounts(
|
|
|
connection: Connection,
|
|
|
- publicKeys: PublicKey[]
|
|
|
+ publicKeys: PublicKey[],
|
|
|
+ commitment?: Commitment
|
|
|
): Promise<
|
|
|
Array<null | { publicKey: PublicKey; account: AccountInfo<Buffer> }>
|
|
|
> {
|
|
|
if (publicKeys.length <= GET_MULTIPLE_ACCOUNTS_LIMIT) {
|
|
|
- return await getMultipleAccountsCore(connection, publicKeys);
|
|
|
+ return await getMultipleAccountsCore(connection, publicKeys, commitment);
|
|
|
} else {
|
|
|
const batches = chunks(publicKeys, GET_MULTIPLE_ACCOUNTS_LIMIT);
|
|
|
const results = await Promise.all<
|
|
|
Array<null | { publicKey: PublicKey; account: AccountInfo<Buffer> }>
|
|
|
- >(batches.map((batch) => getMultipleAccountsCore(connection, batch)));
|
|
|
+ >(
|
|
|
+ batches.map((batch) =>
|
|
|
+ getMultipleAccountsCore(connection, batch, commitment)
|
|
|
+ )
|
|
|
+ );
|
|
|
return results.flat();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
async function getMultipleAccountsCore(
|
|
|
connection: Connection,
|
|
|
- publicKeys: PublicKey[]
|
|
|
+ publicKeys: PublicKey[],
|
|
|
+ commitmentOverride?: Commitment
|
|
|
): Promise<
|
|
|
Array<null | { publicKey: PublicKey; account: AccountInfo<Buffer> }>
|
|
|
> {
|
|
|
- const args = [publicKeys.map((k) => k.toBase58()), { commitment: "recent" }];
|
|
|
- // @ts-ignore
|
|
|
+ const commitment = commitmentOverride ?? connection.commitment;
|
|
|
+ const args: (
|
|
|
+ | string[]
|
|
|
+ | {
|
|
|
+ commitment: Commitment;
|
|
|
+ }
|
|
|
+ )[] = [publicKeys.map((k) => k.toBase58())];
|
|
|
+ if (commitment) {
|
|
|
+ args.push({ commitment });
|
|
|
+ }
|
|
|
+ // @ts-expect-error
|
|
|
const res = await connection._rpcRequest("getMultipleAccounts", args);
|
|
|
if (res.error) {
|
|
|
throw new Error(
|