diff --git a/networks/cosmos/src/query/cosmos-query-client.ts b/networks/cosmos/src/query/cosmos-query-client.ts index 1d5f92cd..b8462d07 100644 --- a/networks/cosmos/src/query/cosmos-query-client.ts +++ b/networks/cosmos/src/query/cosmos-query-client.ts @@ -48,9 +48,8 @@ import { ValidatorsParams } from '../types/requests/common/validators'; import { BroadcastTxParams } from '../types/requests/common/tx'; import { GenesisChunkedParams } from '../types/requests/common/genesis-chunked'; import { ICosmosProtocolAdapter } from '../adapters/base'; -import { BaseAccount } from '@interchainjs/cosmos-types'; -import { getAccount } from '@interchainjs/cosmos-types'; -import { accountFromAny } from '../utils'; +import { BaseAccount, getAccount } from '@interchainjs/cosmos-types'; +import { accountFromAny, type PubkeyDecoderMap } from '../utils'; import { encodePubkey } from '@interchainjs/pubkey'; @@ -326,7 +325,10 @@ export class CosmosQueryClient implements ICosmosQueryClient { } // Account queries - async getBaseAccount(address: string): Promise { + async getBaseAccount( + address: string, + opts?: { readonly pubkeyDecoders?: PubkeyDecoderMap } + ): Promise { try { // Create a plain RPC object so getAccount can mutate it const rpc = { @@ -341,7 +343,7 @@ export class CosmosQueryClient implements ICosmosQueryClient { } // Use the new accountFromAny function to parse the account - const account = accountFromAny(response.account); + const account = accountFromAny(response.account, opts); // Convert the standardized Account back to BaseAccount format return { @@ -364,4 +366,4 @@ export class CosmosQueryClient implements ICosmosQueryClient { capabilities: this.protocolAdapter.getCapabilities() }; } -} \ No newline at end of file +} diff --git a/networks/cosmos/src/types/cosmos-client-interfaces.ts b/networks/cosmos/src/types/cosmos-client-interfaces.ts index 4eadef8f..d80c4f88 100644 --- a/networks/cosmos/src/types/cosmos-client-interfaces.ts +++ b/networks/cosmos/src/types/cosmos-client-interfaces.ts @@ -25,6 +25,7 @@ import { import { BroadcastTxParams } from './requests/common/tx'; import { ProtocolInfo } from './protocol'; import { BaseAccount } from '@interchainjs/cosmos-types'; +import type { PubkeyDecoderMap } from '../utils'; @@ -72,7 +73,10 @@ export interface ICosmosQueryClient extends IQueryClient { request(service: string, method: string, data: Uint8Array): Promise; // Account queries - getBaseAccount(address: string): Promise; + getBaseAccount( + address: string, + opts?: { readonly pubkeyDecoders?: PubkeyDecoderMap } + ): Promise; // Protocol info getProtocolInfo(): ProtocolInfo; @@ -84,4 +88,4 @@ export interface ICosmosEventClient extends IEventClient { subscribeToBlockHeaders(): AsyncIterable; subscribeToTxs(query?: string): AsyncIterable; subscribeToValidatorSetUpdates(): AsyncIterable; -} \ No newline at end of file +} diff --git a/networks/cosmos/src/utils/index.ts b/networks/cosmos/src/utils/index.ts index 5b57d531..def662c6 100644 --- a/networks/cosmos/src/utils/index.ts +++ b/networks/cosmos/src/utils/index.ts @@ -32,9 +32,11 @@ export interface Account { readonly sequence: number; } -export interface AccountFromAnyOption { - readonly pubkeyDecoders?: Record Pubkey>; -} +export type PubkeyDecoderMap = Record Pubkey>; + +export type AccountFromAnyOptions = { + readonly pubkeyDecoders?: PubkeyDecoderMap; +}; /** * Extracts a BaseAccount from simple wrapper account types using binary parsing. @@ -90,7 +92,7 @@ function extractBaseAccountFromWrapper(value: Uint8Array): BaseAccount | null { * @returns A standardized Account object * @throws Error if the account type is not supported */ -export function accountFromAny(accountAny: Any, opts?: AccountFromAnyOption): Account { +export function accountFromAny(accountAny: Any, opts?: AccountFromAnyOptions): Account { const pubkeyDecoders = opts?.pubkeyDecoders; switch (accountAny.typeUrl) { case "/cosmos.auth.v1beta1.BaseAccount": {