Skip to content

Commit d7ba36c

Browse files
authored
Merge pull request #188 from hyperweb-io/query-client-for-unisigner
fix type of accountFromAny
2 parents e8632a6 + 6f6af96 commit d7ba36c

File tree

3 files changed

+20
-12
lines changed

3 files changed

+20
-12
lines changed

networks/cosmos/src/query/cosmos-query-client.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,8 @@ import { ValidatorsParams } from '../types/requests/common/validators';
4848
import { BroadcastTxParams } from '../types/requests/common/tx';
4949
import { GenesisChunkedParams } from '../types/requests/common/genesis-chunked';
5050
import { ICosmosProtocolAdapter } from '../adapters/base';
51-
import { BaseAccount } from '@interchainjs/cosmos-types';
52-
import { getAccount } from '@interchainjs/cosmos-types';
53-
import { accountFromAny } from '../utils';
51+
import { BaseAccount, getAccount } from '@interchainjs/cosmos-types';
52+
import { accountFromAny, type PubkeyDecoderMap } from '../utils';
5453
import { encodePubkey } from '@interchainjs/pubkey';
5554

5655

@@ -326,7 +325,10 @@ export class CosmosQueryClient implements ICosmosQueryClient {
326325
}
327326

328327
// Account queries
329-
async getBaseAccount(address: string): Promise<BaseAccount | null> {
328+
async getBaseAccount(
329+
address: string,
330+
opts?: { readonly pubkeyDecoders?: PubkeyDecoderMap }
331+
): Promise<BaseAccount | null> {
330332
try {
331333
// Create a plain RPC object so getAccount can mutate it
332334
const rpc = {
@@ -341,7 +343,7 @@ export class CosmosQueryClient implements ICosmosQueryClient {
341343
}
342344

343345
// Use the new accountFromAny function to parse the account
344-
const account = accountFromAny(response.account);
346+
const account = accountFromAny(response.account, opts);
345347

346348
// Convert the standardized Account back to BaseAccount format
347349
return {
@@ -364,4 +366,4 @@ export class CosmosQueryClient implements ICosmosQueryClient {
364366
capabilities: this.protocolAdapter.getCapabilities()
365367
};
366368
}
367-
}
369+
}

networks/cosmos/src/types/cosmos-client-interfaces.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
import { BroadcastTxParams } from './requests/common/tx';
2626
import { ProtocolInfo } from './protocol';
2727
import { BaseAccount } from '@interchainjs/cosmos-types';
28+
import type { PubkeyDecoderMap } from '../utils';
2829

2930

3031

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

7475
// Account queries
75-
getBaseAccount(address: string): Promise<BaseAccount | null>;
76+
getBaseAccount(
77+
address: string,
78+
opts?: { readonly pubkeyDecoders?: PubkeyDecoderMap }
79+
): Promise<BaseAccount | null>;
7680

7781
// Protocol info
7882
getProtocolInfo(): ProtocolInfo;
@@ -84,4 +88,4 @@ export interface ICosmosEventClient extends IEventClient {
8488
subscribeToBlockHeaders(): AsyncIterable<BlockHeader>;
8589
subscribeToTxs(query?: string): AsyncIterable<TxEvent>;
8690
subscribeToValidatorSetUpdates(): AsyncIterable<BlockEvent>;
87-
}
91+
}

networks/cosmos/src/utils/index.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,11 @@ export interface Account {
3232
readonly sequence: number;
3333
}
3434

35-
export interface AccountFromAnyOption {
36-
readonly pubkeyDecoders?: Record<string, (pubkey: Any) => Pubkey>;
37-
}
35+
export type PubkeyDecoderMap = Record<string, (pubkey: Any) => Pubkey>;
36+
37+
export type AccountFromAnyOptions = {
38+
readonly pubkeyDecoders?: PubkeyDecoderMap;
39+
};
3840

3941
/**
4042
* Extracts a BaseAccount from simple wrapper account types using binary parsing.
@@ -90,7 +92,7 @@ function extractBaseAccountFromWrapper(value: Uint8Array): BaseAccount | null {
9092
* @returns A standardized Account object
9193
* @throws Error if the account type is not supported
9294
*/
93-
export function accountFromAny(accountAny: Any, opts?: AccountFromAnyOption): Account {
95+
export function accountFromAny(accountAny: Any, opts?: AccountFromAnyOptions): Account {
9496
const pubkeyDecoders = opts?.pubkeyDecoders;
9597
switch (accountAny.typeUrl) {
9698
case "/cosmos.auth.v1beta1.BaseAccount": {

0 commit comments

Comments
 (0)