chore: add encoding param to getMultipleAccounts
This commit is contained in:
committed by
Michael Vines
parent
6895eb7ef6
commit
33ad74fbcd
@ -1711,6 +1711,16 @@ export type GetParsedProgramAccountsConfig = {
|
|||||||
filters?: GetProgramAccountsFilter[];
|
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
|
* Information describing an account
|
||||||
*/
|
*/
|
||||||
@ -2479,14 +2489,27 @@ export class Connection {
|
|||||||
*/
|
*/
|
||||||
async getMultipleAccountsInfo(
|
async getMultipleAccountsInfo(
|
||||||
publicKeys: PublicKey[],
|
publicKeys: PublicKey[],
|
||||||
commitment?: Commitment,
|
configOrCommitment?: GetMultipleAccountsConfig | Commitment,
|
||||||
): Promise<(AccountInfo<Buffer> | null)[]> {
|
): Promise<(AccountInfo<Buffer | ParsedAccountData> | null)[]> {
|
||||||
const keys = publicKeys.map(key => key.toBase58());
|
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 unsafeRes = await this._rpcRequest('getMultipleAccounts', args);
|
||||||
const res = create(
|
const res = create(
|
||||||
unsafeRes,
|
unsafeRes,
|
||||||
jsonRpcResultAndContext(array(nullable(AccountInfoResult))),
|
jsonRpcResultAndContext(array(nullable(ParsedAccountInfoResult))),
|
||||||
);
|
);
|
||||||
if ('error' in res) {
|
if ('error' in res) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
|
Reference in New Issue
Block a user