From 33ad74fbcda33f2548d6021ec568257c3be56730 Mon Sep 17 00:00:00 2001 From: Victor Pontis Date: Sat, 25 Dec 2021 22:21:10 -0500 Subject: [PATCH] chore: add encoding param to getMultipleAccounts --- web3.js/src/connection.ts | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/web3.js/src/connection.ts b/web3.js/src/connection.ts index cd8f0a6c53..18ac600845 100644 --- a/web3.js/src/connection.ts +++ b/web3.js/src/connection.ts @@ -1711,6 +1711,16 @@ export type GetParsedProgramAccountsConfig = { filters?: GetProgramAccountsFilter[]; }; +/** + * Configuration object for getMultipleAccounts + */ +export type GetMultipleAccountsConfig = { + /** Optional commitment level */ + commitment?: Commitment; + /** Optional encoding for account data (default base64) */ + encoding?: 'base64' | 'jsonParsed'; +}; + /** * Information describing an account */ @@ -2479,14 +2489,27 @@ export class Connection { */ async getMultipleAccountsInfo( publicKeys: PublicKey[], - commitment?: Commitment, - ): Promise<(AccountInfo | null)[]> { + configOrCommitment?: GetMultipleAccountsConfig | Commitment, + ): Promise<(AccountInfo | null)[]> { const keys = publicKeys.map(key => key.toBase58()); - const args = this._buildArgs([keys], commitment, 'base64'); + + let commitment; + let encoding: 'base64' | 'jsonParsed' = 'base64'; + if (configOrCommitment) { + if (typeof configOrCommitment === 'string') { + commitment = configOrCommitment; + encoding = 'base64'; + } else { + commitment = configOrCommitment.commitment; + encoding = configOrCommitment.encoding || 'base64'; + } + } + + const args = this._buildArgs([keys], commitment, encoding); const unsafeRes = await this._rpcRequest('getMultipleAccounts', args); const res = create( unsafeRes, - jsonRpcResultAndContext(array(nullable(AccountInfoResult))), + jsonRpcResultAndContext(array(nullable(ParsedAccountInfoResult))), ); if ('error' in res) { throw new Error(