diff --git a/packages/cosmwasm/src/lcdapi/wasm.ts b/packages/cosmwasm/src/lcdapi/wasm.ts index 6c836744..521faeb6 100644 --- a/packages/cosmwasm/src/lcdapi/wasm.ts +++ b/packages/cosmwasm/src/lcdapi/wasm.ts @@ -1,5 +1,5 @@ import { fromBase64, fromUtf8, toHex, toUtf8 } from "@cosmjs/encoding"; -import { LcdApiArray, LcdClient, LcdExtension, normalizeLcdApiArray } from "@cosmjs/sdk38"; +import { LcdApiArray, LcdClient, normalizeLcdApiArray } from "@cosmjs/sdk38"; import { JsonObject, Model, parseWasmData, WasmData } from "../types"; @@ -75,7 +75,7 @@ function unwrapWasmResponse(response: WasmResponse): T { /** * @see https://github.com/cosmwasm/wasmd/blob/master/x/wasm/client/rest/query.go#L19-L27 */ -export interface WasmExtension extends LcdExtension { +export interface WasmExtension { readonly wasm: { readonly listCodeInfo: () => Promise; diff --git a/packages/cosmwasm/types/lcdapi/wasm.d.ts b/packages/cosmwasm/types/lcdapi/wasm.d.ts index 5e454691..8859ffad 100644 --- a/packages/cosmwasm/types/lcdapi/wasm.d.ts +++ b/packages/cosmwasm/types/lcdapi/wasm.d.ts @@ -1,4 +1,4 @@ -import { LcdClient, LcdExtension } from "@cosmjs/sdk38"; +import { LcdClient } from "@cosmjs/sdk38"; import { JsonObject, Model } from "../types"; export interface CodeInfo { readonly id: number; @@ -40,7 +40,7 @@ export interface ContractDetails extends ContractInfo { /** * @see https://github.com/cosmwasm/wasmd/blob/master/x/wasm/client/rest/query.go#L19-L27 */ -export interface WasmExtension extends LcdExtension { +export interface WasmExtension { readonly wasm: { readonly listCodeInfo: () => Promise; /** diff --git a/packages/sdk38/src/index.ts b/packages/sdk38/src/index.ts index 6e9e6acf..d6053e6e 100644 --- a/packages/sdk38/src/index.ts +++ b/packages/sdk38/src/index.ts @@ -27,7 +27,6 @@ export { BroadcastMode, EncodeTxResponse, LcdApiArray, - LcdExtension, LcdClient, NodeInfoResponse, normalizeLcdApiArray, diff --git a/packages/sdk38/src/lcdapi/auth.ts b/packages/sdk38/src/lcdapi/auth.ts index 6ba13a63..d9066733 100644 --- a/packages/sdk38/src/lcdapi/auth.ts +++ b/packages/sdk38/src/lcdapi/auth.ts @@ -1,5 +1,5 @@ import { Coin } from "../coins"; -import { LcdClient, LcdExtension } from "./lcdclient"; +import { LcdClient } from "./lcdclient"; export interface CosmosSdkAccount { /** Bech32 account address */ @@ -19,7 +19,7 @@ export interface AuthAccountsResponse { }; } -export interface AuthExtension extends LcdExtension { +export interface AuthExtension { readonly auth: { readonly account: (address: string) => Promise; }; diff --git a/packages/sdk38/src/lcdapi/index.ts b/packages/sdk38/src/lcdapi/index.ts index 96e2c8b6..bc39d863 100644 --- a/packages/sdk38/src/lcdapi/index.ts +++ b/packages/sdk38/src/lcdapi/index.ts @@ -18,4 +18,4 @@ export { SearchTxsResponse, TxsResponse, } from "./base"; -export { LcdApiArray, LcdClient, LcdExtension, normalizeLcdApiArray } from "./lcdclient"; +export { LcdApiArray, LcdClient, normalizeLcdApiArray } from "./lcdclient"; diff --git a/packages/sdk38/src/lcdapi/lcdclient.spec.ts b/packages/sdk38/src/lcdapi/lcdclient.spec.ts index 97bf9990..2a35ee24 100644 --- a/packages/sdk38/src/lcdapi/lcdclient.spec.ts +++ b/packages/sdk38/src/lcdapi/lcdclient.spec.ts @@ -23,7 +23,7 @@ import { import { StdFee } from "../types"; import { setupAuthExtension } from "./auth"; import { TxsResponse } from "./base"; -import { LcdApiArray, LcdClient, LcdExtension, normalizeLcdApiArray } from "./lcdclient"; +import { LcdApiArray, LcdClient, normalizeLcdApiArray } from "./lcdclient"; /** Deployed as part of scripts/wasmd/init.sh */ export const deployedErc20 = { @@ -79,7 +79,7 @@ describe("LcdClient", () => { return response.result; } - interface WasmExtension extends LcdExtension { + interface WasmExtension { wasm: { listCodeInfo: () => Promise; }; diff --git a/packages/sdk38/src/lcdapi/lcdclient.ts b/packages/sdk38/src/lcdapi/lcdclient.ts index 1d82478f..d1685b68 100644 --- a/packages/sdk38/src/lcdapi/lcdclient.ts +++ b/packages/sdk38/src/lcdapi/lcdclient.ts @@ -20,9 +20,7 @@ export function normalizeLcdApiArray(backend: LcdApiArray): readonly T[] { return backend || []; } -export type LcdExtension = Record any>>; - -type LcdExtensionSetup

= (base: LcdClient) => P; +type LcdExtensionSetup

= (base: LcdClient) => P; export interface LcdClientBaseOptions { readonly apiUrl: string; @@ -68,20 +66,20 @@ export class LcdClient { public static withExtensions(options: LcdClientBaseOptions): LcdClient; /** Constructs an LCD client with 1 extension */ - public static withExtensions( + public static withExtensions( options: LcdClientBaseOptions, setupExtensionA: LcdExtensionSetup, ): LcdClient & A; /** Constructs an LCD client with 2 extensions */ - public static withExtensions( + public static withExtensions( options: LcdClientBaseOptions, setupExtensionA: LcdExtensionSetup, setupExtensionB: LcdExtensionSetup, ): LcdClient & A & B; /** Constructs an LCD client with 3 extensions */ - public static withExtensions( + public static withExtensions( options: LcdClientBaseOptions, setupExtensionA: LcdExtensionSetup, setupExtensionB: LcdExtensionSetup, @@ -89,12 +87,7 @@ export class LcdClient { ): LcdClient & A & B & C; /** Constructs an LCD client with 4 extensions */ - public static withExtensions< - A extends LcdExtension, - B extends LcdExtension, - C extends LcdExtension, - D extends LcdExtension - >( + public static withExtensions( options: LcdClientBaseOptions, setupExtensionA: LcdExtensionSetup, setupExtensionB: LcdExtensionSetup, @@ -104,11 +97,11 @@ export class LcdClient { /** Constructs an LCD client with 5 extensions */ public static withExtensions< - A extends LcdExtension, - B extends LcdExtension, - C extends LcdExtension, - D extends LcdExtension, - E extends LcdExtension + A extends object, + B extends object, + C extends object, + D extends object, + E extends object >( options: LcdClientBaseOptions, setupExtensionA: LcdExtensionSetup, @@ -120,12 +113,12 @@ export class LcdClient { /** Constructs an LCD client with 6 extensions */ public static withExtensions< - A extends LcdExtension, - B extends LcdExtension, - C extends LcdExtension, - D extends LcdExtension, - E extends LcdExtension, - F extends LcdExtension + A extends object, + B extends object, + C extends object, + D extends object, + E extends object, + F extends object >( options: LcdClientBaseOptions, setupExtensionA: LcdExtensionSetup, @@ -138,13 +131,13 @@ export class LcdClient { /** Constructs an LCD client with 7 extensions */ public static withExtensions< - A extends LcdExtension, - B extends LcdExtension, - C extends LcdExtension, - D extends LcdExtension, - E extends LcdExtension, - F extends LcdExtension, - G extends LcdExtension + A extends object, + B extends object, + C extends object, + D extends object, + E extends object, + F extends object, + G extends object >( options: LcdClientBaseOptions, setupExtensionA: LcdExtensionSetup, @@ -158,14 +151,14 @@ export class LcdClient { /** Constructs an LCD client with 8 extensions */ public static withExtensions< - A extends LcdExtension, - B extends LcdExtension, - C extends LcdExtension, - D extends LcdExtension, - E extends LcdExtension, - F extends LcdExtension, - G extends LcdExtension, - H extends LcdExtension + A extends object, + B extends object, + C extends object, + D extends object, + E extends object, + F extends object, + G extends object, + H extends object >( options: LcdClientBaseOptions, setupExtensionA: LcdExtensionSetup, @@ -179,14 +172,14 @@ export class LcdClient { ): LcdClient & A & B & C & D & E & F & G & H; public static withExtensions< - A extends LcdExtension, - B extends LcdExtension, - C extends LcdExtension, - D extends LcdExtension, - E extends LcdExtension, - F extends LcdExtension, - G extends LcdExtension, - H extends LcdExtension + A extends object, + B extends object, + C extends object, + D extends object, + E extends object, + F extends object, + G extends object, + H extends object >( options: LcdClientBaseOptions, setupExtensionA?: LcdExtensionSetup, @@ -200,7 +193,7 @@ export class LcdClient { ): any { const client = new LcdClient(options.apiUrl, options.broadcastMode); - const extensions = new Array(); + const extensions = new Array(); if (setupExtensionA) extensions.push(setupExtensionA(client)); if (setupExtensionB) extensions.push(setupExtensionB(client)); if (setupExtensionC) extensions.push(setupExtensionC(client)); @@ -211,9 +204,8 @@ export class LcdClient { if (setupExtensionH) extensions.push(setupExtensionH(client)); for (const extension of extensions) { assert(isNonNullObject(extension), `Extension must be a non-null object`); - for (const key in extension) { - assert(typeof key == "string", `Found non-string extension key: ${key}`); - (client as any)[key] = extension[key]; + for (const [key, value] of Object.entries(extension)) { + (client as any)[key] = value; } } diff --git a/packages/sdk38/src/lcdapi/supply.ts b/packages/sdk38/src/lcdapi/supply.ts index a0bfb77a..06443134 100644 --- a/packages/sdk38/src/lcdapi/supply.ts +++ b/packages/sdk38/src/lcdapi/supply.ts @@ -1,5 +1,5 @@ import { Coin } from "../coins"; -import { LcdApiArray, LcdClient, LcdExtension } from "./lcdclient"; +import { LcdApiArray, LcdClient } from "./lcdclient"; export interface TotalSupplyAllReponse { readonly height: string; @@ -12,7 +12,7 @@ export interface TotalSupplyReponse { readonly result: string; } -export interface SupplyExtension extends LcdExtension { +export interface SupplyExtension { readonly supply: { readonly totalAll: () => Promise; readonly total: (denom: string) => Promise; diff --git a/packages/sdk38/types/index.d.ts b/packages/sdk38/types/index.d.ts index fe93970c..38123a21 100644 --- a/packages/sdk38/types/index.d.ts +++ b/packages/sdk38/types/index.d.ts @@ -25,7 +25,6 @@ export { BroadcastMode, EncodeTxResponse, LcdApiArray, - LcdExtension, LcdClient, NodeInfoResponse, normalizeLcdApiArray, diff --git a/packages/sdk38/types/lcdapi/auth.d.ts b/packages/sdk38/types/lcdapi/auth.d.ts index 23ecb851..95f404d3 100644 --- a/packages/sdk38/types/lcdapi/auth.d.ts +++ b/packages/sdk38/types/lcdapi/auth.d.ts @@ -1,5 +1,5 @@ import { Coin } from "../coins"; -import { LcdClient, LcdExtension } from "./lcdclient"; +import { LcdClient } from "./lcdclient"; export interface CosmosSdkAccount { /** Bech32 account address */ readonly address: string; @@ -16,7 +16,7 @@ export interface AuthAccountsResponse { readonly value: CosmosSdkAccount; }; } -export interface AuthExtension extends LcdExtension { +export interface AuthExtension { readonly auth: { readonly account: (address: string) => Promise; }; diff --git a/packages/sdk38/types/lcdapi/index.d.ts b/packages/sdk38/types/lcdapi/index.d.ts index ad1eb321..dc0274a9 100644 --- a/packages/sdk38/types/lcdapi/index.d.ts +++ b/packages/sdk38/types/lcdapi/index.d.ts @@ -9,4 +9,4 @@ export { SearchTxsResponse, TxsResponse, } from "./base"; -export { LcdApiArray, LcdClient, LcdExtension, normalizeLcdApiArray } from "./lcdclient"; +export { LcdApiArray, LcdClient, normalizeLcdApiArray } from "./lcdclient"; diff --git a/packages/sdk38/types/lcdapi/lcdclient.d.ts b/packages/sdk38/types/lcdapi/lcdclient.d.ts index 6df6dc3a..009e556e 100644 --- a/packages/sdk38/types/lcdapi/lcdclient.d.ts +++ b/packages/sdk38/types/lcdapi/lcdclient.d.ts @@ -11,8 +11,7 @@ import { /** Unfortunately, Cosmos SDK encodes empty arrays as null */ export declare type LcdApiArray = readonly T[] | null; export declare function normalizeLcdApiArray(backend: LcdApiArray): readonly T[]; -export declare type LcdExtension = Record any>>; -declare type LcdExtensionSetup

= (base: LcdClient) => P; +declare type LcdExtensionSetup

= (base: LcdClient) => P; export interface LcdClientBaseOptions { readonly apiUrl: string; readonly broadcastMode?: BroadcastMode; @@ -33,30 +32,25 @@ export declare class LcdClient { /** Constructs an LCD client with 0 extensions */ static withExtensions(options: LcdClientBaseOptions): LcdClient; /** Constructs an LCD client with 1 extension */ - static withExtensions( + static withExtensions( options: LcdClientBaseOptions, setupExtensionA: LcdExtensionSetup, ): LcdClient & A; /** Constructs an LCD client with 2 extensions */ - static withExtensions( + static withExtensions( options: LcdClientBaseOptions, setupExtensionA: LcdExtensionSetup, setupExtensionB: LcdExtensionSetup, ): LcdClient & A & B; /** Constructs an LCD client with 3 extensions */ - static withExtensions( + static withExtensions( options: LcdClientBaseOptions, setupExtensionA: LcdExtensionSetup, setupExtensionB: LcdExtensionSetup, setupExtensionC: LcdExtensionSetup, ): LcdClient & A & B & C; /** Constructs an LCD client with 4 extensions */ - static withExtensions< - A extends LcdExtension, - B extends LcdExtension, - C extends LcdExtension, - D extends LcdExtension - >( + static withExtensions( options: LcdClientBaseOptions, setupExtensionA: LcdExtensionSetup, setupExtensionB: LcdExtensionSetup, @@ -65,11 +59,11 @@ export declare class LcdClient { ): LcdClient & A & B & C & D; /** Constructs an LCD client with 5 extensions */ static withExtensions< - A extends LcdExtension, - B extends LcdExtension, - C extends LcdExtension, - D extends LcdExtension, - E extends LcdExtension + A extends object, + B extends object, + C extends object, + D extends object, + E extends object >( options: LcdClientBaseOptions, setupExtensionA: LcdExtensionSetup, @@ -80,12 +74,12 @@ export declare class LcdClient { ): LcdClient & A & B & C & D & E; /** Constructs an LCD client with 6 extensions */ static withExtensions< - A extends LcdExtension, - B extends LcdExtension, - C extends LcdExtension, - D extends LcdExtension, - E extends LcdExtension, - F extends LcdExtension + A extends object, + B extends object, + C extends object, + D extends object, + E extends object, + F extends object >( options: LcdClientBaseOptions, setupExtensionA: LcdExtensionSetup, @@ -97,13 +91,13 @@ export declare class LcdClient { ): LcdClient & A & B & C & D & E & F; /** Constructs an LCD client with 7 extensions */ static withExtensions< - A extends LcdExtension, - B extends LcdExtension, - C extends LcdExtension, - D extends LcdExtension, - E extends LcdExtension, - F extends LcdExtension, - G extends LcdExtension + A extends object, + B extends object, + C extends object, + D extends object, + E extends object, + F extends object, + G extends object >( options: LcdClientBaseOptions, setupExtensionA: LcdExtensionSetup, @@ -116,14 +110,14 @@ export declare class LcdClient { ): LcdClient & A & B & C & D & E & F & G; /** Constructs an LCD client with 8 extensions */ static withExtensions< - A extends LcdExtension, - B extends LcdExtension, - C extends LcdExtension, - D extends LcdExtension, - E extends LcdExtension, - F extends LcdExtension, - G extends LcdExtension, - H extends LcdExtension + A extends object, + B extends object, + C extends object, + D extends object, + E extends object, + F extends object, + G extends object, + H extends object >( options: LcdClientBaseOptions, setupExtensionA: LcdExtensionSetup, diff --git a/packages/sdk38/types/lcdapi/supply.d.ts b/packages/sdk38/types/lcdapi/supply.d.ts index 4b45aeb7..e9bf1d2c 100644 --- a/packages/sdk38/types/lcdapi/supply.d.ts +++ b/packages/sdk38/types/lcdapi/supply.d.ts @@ -1,5 +1,5 @@ import { Coin } from "../coins"; -import { LcdApiArray, LcdClient, LcdExtension } from "./lcdclient"; +import { LcdApiArray, LcdClient } from "./lcdclient"; export interface TotalSupplyAllReponse { readonly height: string; readonly result: LcdApiArray; @@ -9,7 +9,7 @@ export interface TotalSupplyReponse { /** The amount */ readonly result: string; } -export interface SupplyExtension extends LcdExtension { +export interface SupplyExtension { readonly supply: { readonly totalAll: () => Promise; readonly total: (denom: string) => Promise;