diff --git a/packages/sdk38/src/lcdapi/index.ts b/packages/sdk38/src/lcdapi/index.ts new file mode 100644 index 00000000..353d2fb3 --- /dev/null +++ b/packages/sdk38/src/lcdapi/index.ts @@ -0,0 +1,3 @@ +// See tracking issue https://github.com/CosmWasm/cosmjs/issues/276 for module support + +export { SupplyModule, TotalSupplyAllReponse, TotalSupplyReponse } from "./supply"; diff --git a/packages/sdk38/src/lcdapi/supply.spec.ts b/packages/sdk38/src/lcdapi/supply.spec.ts new file mode 100644 index 00000000..6ae295e7 --- /dev/null +++ b/packages/sdk38/src/lcdapi/supply.spec.ts @@ -0,0 +1,40 @@ +import { LcdClient } from "../lcdclient"; +import { pendingWithoutWasmd, wasmd } from "../testutils.spec"; +import { setupSupplyModule } from "./supply"; + +describe("supply", () => { + describe("totalSupplyAll", () => { + it("works", async () => { + pendingWithoutWasmd(); + + const client = LcdClient.withModules({ apiUrl: wasmd.endpoint }, setupSupplyModule); + const supply = await client.totalSupplyAll(); + expect(supply).toEqual({ + height: jasmine.stringMatching(/^[0-9]+$/), + result: [ + { + amount: jasmine.stringMatching(/^[0-9]+$/), + denom: "ucosm", + }, + { + amount: jasmine.stringMatching(/^[0-9]+$/), + denom: "ustake", + }, + ], + }); + }); + }); + + describe("totalSupply", () => { + it("works", async () => { + pendingWithoutWasmd(); + + const client = LcdClient.withModules({ apiUrl: wasmd.endpoint }, setupSupplyModule); + const supply = await client.totalSupply("ucosm"); + expect(supply).toEqual({ + height: jasmine.stringMatching(/^[0-9]+$/), + result: jasmine.stringMatching(/^[0-9]+$/), + }); + }); + }); +}); diff --git a/packages/sdk38/src/lcdapi/supply.ts b/packages/sdk38/src/lcdapi/supply.ts new file mode 100644 index 00000000..2063954f --- /dev/null +++ b/packages/sdk38/src/lcdapi/supply.ts @@ -0,0 +1,29 @@ +import { Coin } from "../coins"; +import { LcdApiArray, LcdClient, LcdModule } from "../lcdclient"; + +export interface TotalSupplyAllReponse { + readonly height: string; + readonly result: LcdApiArray; +} + +export interface TotalSupplyReponse { + readonly height: string; + /** The amount */ + readonly result: string; +} + +export interface SupplyModule extends LcdModule { + readonly totalSupplyAll: () => Promise; + readonly totalSupply: (denom: string) => Promise; +} + +export function setupSupplyModule(base: LcdClient): SupplyModule { + return { + totalSupplyAll: async () => { + return base.get(`/supply/total`); + }, + totalSupply: async (denom: string) => { + return base.get(`/supply/total/${denom}`); + }, + }; +} diff --git a/packages/sdk38/src/lcdclient.ts b/packages/sdk38/src/lcdclient.ts index 92613533..2a1581ba 100644 --- a/packages/sdk38/src/lcdclient.ts +++ b/packages/sdk38/src/lcdclient.ts @@ -21,7 +21,7 @@ export function normalizeArray(backend: LcdApiArray): ReadonlyArray { return backend || []; } -type LcdModule = Record any>; +export type LcdModule = Record any>; type LcdModuleSetup = (base: LcdClient) => M; diff --git a/packages/sdk38/types/lcdapi/index.d.ts b/packages/sdk38/types/lcdapi/index.d.ts new file mode 100644 index 00000000..0e8ba9fe --- /dev/null +++ b/packages/sdk38/types/lcdapi/index.d.ts @@ -0,0 +1 @@ +export { SupplyModule, TotalSupplyAllReponse, TotalSupplyReponse } from "./supply"; diff --git a/packages/sdk38/types/lcdapi/supply.d.ts b/packages/sdk38/types/lcdapi/supply.d.ts new file mode 100644 index 00000000..321869a9 --- /dev/null +++ b/packages/sdk38/types/lcdapi/supply.d.ts @@ -0,0 +1,16 @@ +import { Coin } from "../coins"; +import { LcdApiArray, LcdClient, LcdModule } from "../lcdclient"; +export interface TotalSupplyAllReponse { + readonly height: string; + readonly result: LcdApiArray; +} +export interface TotalSupplyReponse { + readonly height: string; + /** The amount */ + readonly result: string; +} +export interface SupplyModule extends LcdModule { + readonly totalSupplyAll: () => Promise; + readonly totalSupply: (denom: string) => Promise; +} +export declare function setupSupplyModule(base: LcdClient): SupplyModule; diff --git a/packages/sdk38/types/lcdapi/supply.spec.d.ts b/packages/sdk38/types/lcdapi/supply.spec.d.ts new file mode 100644 index 00000000..cb0ff5c3 --- /dev/null +++ b/packages/sdk38/types/lcdapi/supply.spec.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/packages/sdk38/types/lcdclient.d.ts b/packages/sdk38/types/lcdclient.d.ts index f044d509..f8c2519a 100644 --- a/packages/sdk38/types/lcdclient.d.ts +++ b/packages/sdk38/types/lcdclient.d.ts @@ -12,7 +12,7 @@ import { CosmosSdkTx, StdTx } from "./types"; /** Unfortunately, Cosmos SDK encodes empty arrays as null */ export declare type LcdApiArray = ReadonlyArray | null; export declare function normalizeArray(backend: LcdApiArray): ReadonlyArray; -declare type LcdModule = Record any>; +export declare type LcdModule = Record any>; declare type LcdModuleSetup = (base: LcdClient) => M; export interface LcdClientBaseOptions { readonly apiUrl: string;