Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions networks/cosmos/src/query/cosmos-query-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';


Expand Down Expand Up @@ -326,7 +325,10 @@ export class CosmosQueryClient implements ICosmosQueryClient {
}

// Account queries
async getBaseAccount(address: string): Promise<BaseAccount | null> {
async getBaseAccount(
address: string,
opts?: { readonly pubkeyDecoders?: PubkeyDecoderMap }
): Promise<BaseAccount | null> {
try {
// Create a plain RPC object so getAccount can mutate it
const rpc = {
Expand All @@ -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 {
Expand All @@ -364,4 +366,4 @@ export class CosmosQueryClient implements ICosmosQueryClient {
capabilities: this.protocolAdapter.getCapabilities()
};
}
}
}
8 changes: 6 additions & 2 deletions networks/cosmos/src/types/cosmos-client-interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';



Expand Down Expand Up @@ -72,7 +73,10 @@ export interface ICosmosQueryClient extends IQueryClient {
request(service: string, method: string, data: Uint8Array): Promise<Uint8Array>;

// Account queries
getBaseAccount(address: string): Promise<BaseAccount | null>;
getBaseAccount(
address: string,
opts?: { readonly pubkeyDecoders?: PubkeyDecoderMap }
): Promise<BaseAccount | null>;

// Protocol info
getProtocolInfo(): ProtocolInfo;
Expand All @@ -84,4 +88,4 @@ export interface ICosmosEventClient extends IEventClient {
subscribeToBlockHeaders(): AsyncIterable<BlockHeader>;
subscribeToTxs(query?: string): AsyncIterable<TxEvent>;
subscribeToValidatorSetUpdates(): AsyncIterable<BlockEvent>;
}
}
10 changes: 6 additions & 4 deletions networks/cosmos/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ export interface Account {
readonly sequence: number;
}

export interface AccountFromAnyOption {
readonly pubkeyDecoders?: Record<string, (pubkey: Any) => Pubkey>;
}
export type PubkeyDecoderMap = Record<string, (pubkey: Any) => Pubkey>;

export type AccountFromAnyOptions = {
readonly pubkeyDecoders?: PubkeyDecoderMap;
};

/**
* Extracts a BaseAccount from simple wrapper account types using binary parsing.
Expand Down Expand Up @@ -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": {
Expand Down
Loading