@@ -3,6 +3,7 @@ import { Uint53 } from "@cosmjs/math";
33import {
44 Account ,
55 accountFromAny ,
6+ AccountParser ,
67 AuthExtension ,
78 BankExtension ,
89 Block ,
@@ -81,35 +82,43 @@ export interface PrivateCosmWasmClient {
8182 | undefined ;
8283}
8384
85+ export interface CosmWasmClientOptions {
86+ readonly accountParser ?: AccountParser ;
87+ }
88+
8489export class CosmWasmClient {
8590 private readonly cometClient : CometClient | undefined ;
8691 private readonly queryClient :
8792 | ( QueryClient & AuthExtension & BankExtension & TxExtension & WasmExtension )
8893 | undefined ;
8994 private readonly codesCache = new Map < number , CodeDetails > ( ) ;
9095 private chainId : string | undefined ;
96+ private readonly accountParser : AccountParser ;
9197
9298 /**
9399 * Creates an instance by connecting to the given CometBFT RPC endpoint.
94100 *
95101 * This uses auto-detection to decide between a CometBFT 1.x, CometBFT 0.38 and Tendermint 0.37 client.
96102 * To set the Comet client explicitly, use `create`.
97103 */
98- public static async connect ( endpoint : string | HttpEndpoint ) : Promise < CosmWasmClient > {
104+ public static async connect (
105+ endpoint : string | HttpEndpoint ,
106+ options : CosmWasmClientOptions = { } ,
107+ ) : Promise < CosmWasmClient > {
99108 const cometClient = await connectComet ( endpoint ) ;
100- return CosmWasmClient . create ( cometClient ) ;
109+ return CosmWasmClient . create ( cometClient , options ) ;
101110 }
102111
103112 /**
104113 * Creates an instance from a manually created Comet client.
105114 * Use this to use `Comet38Client` or `Tendermint37Client` instead of
106115 * auto-detection.
107116 */
108- public static create ( cometClient : CometClient ) : CosmWasmClient {
109- return new CosmWasmClient ( cometClient ) ;
117+ public static create ( cometClient : CometClient , options : CosmWasmClientOptions = { } ) : CosmWasmClient {
118+ return new CosmWasmClient ( cometClient , options ) ;
110119 }
111120
112- protected constructor ( cometClient : CometClient | undefined ) {
121+ protected constructor ( cometClient : CometClient | undefined , options : CosmWasmClientOptions = { } ) {
113122 if ( cometClient ) {
114123 this . cometClient = cometClient ;
115124 this . queryClient = QueryClient . withExtensions (
@@ -120,6 +129,8 @@ export class CosmWasmClient {
120129 setupTxExtension ,
121130 ) ;
122131 }
132+ const { accountParser = accountFromAny } = options ;
133+ this . accountParser = accountParser ;
123134 }
124135
125136 protected getCometClient ( ) : CometClient | undefined {
@@ -165,7 +176,7 @@ export class CosmWasmClient {
165176 public async getAccount ( searchAddress : string ) : Promise < Account | null > {
166177 try {
167178 const account = await this . forceGetQueryClient ( ) . auth . account ( searchAddress ) ;
168- return account ? accountFromAny ( account ) : null ;
179+ return account ? this . accountParser ( account ) : null ;
169180 } catch ( error : any ) {
170181 if ( / r p c e r r o r : c o d e = N o t F o u n d / i. test ( String ( error ) ) ) {
171182 return null ;
0 commit comments