Create proper supply module
This commit is contained in:
parent
6d767cf5b1
commit
467b29e451
3
packages/sdk38/src/lcdapi/index.ts
Normal file
3
packages/sdk38/src/lcdapi/index.ts
Normal file
@ -0,0 +1,3 @@
|
||||
// See tracking issue https://github.com/CosmWasm/cosmjs/issues/276 for module support
|
||||
|
||||
export { SupplyModule, TotalSupplyAllReponse, TotalSupplyReponse } from "./supply";
|
||||
40
packages/sdk38/src/lcdapi/supply.spec.ts
Normal file
40
packages/sdk38/src/lcdapi/supply.spec.ts
Normal file
@ -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]+$/),
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
29
packages/sdk38/src/lcdapi/supply.ts
Normal file
29
packages/sdk38/src/lcdapi/supply.ts
Normal file
@ -0,0 +1,29 @@
|
||||
import { Coin } from "../coins";
|
||||
import { LcdApiArray, LcdClient, LcdModule } from "../lcdclient";
|
||||
|
||||
export interface TotalSupplyAllReponse {
|
||||
readonly height: string;
|
||||
readonly result: LcdApiArray<Coin>;
|
||||
}
|
||||
|
||||
export interface TotalSupplyReponse {
|
||||
readonly height: string;
|
||||
/** The amount */
|
||||
readonly result: string;
|
||||
}
|
||||
|
||||
export interface SupplyModule extends LcdModule {
|
||||
readonly totalSupplyAll: () => Promise<TotalSupplyAllReponse>;
|
||||
readonly totalSupply: (denom: string) => Promise<TotalSupplyReponse>;
|
||||
}
|
||||
|
||||
export function setupSupplyModule(base: LcdClient): SupplyModule {
|
||||
return {
|
||||
totalSupplyAll: async () => {
|
||||
return base.get(`/supply/total`);
|
||||
},
|
||||
totalSupply: async (denom: string) => {
|
||||
return base.get(`/supply/total/${denom}`);
|
||||
},
|
||||
};
|
||||
}
|
||||
@ -21,7 +21,7 @@ export function normalizeArray<T>(backend: LcdApiArray<T>): ReadonlyArray<T> {
|
||||
return backend || [];
|
||||
}
|
||||
|
||||
type LcdModule = Record<string, () => any>;
|
||||
export type LcdModule = Record<string, (...args: any[]) => any>;
|
||||
|
||||
type LcdModuleSetup<M> = (base: LcdClient) => M;
|
||||
|
||||
|
||||
1
packages/sdk38/types/lcdapi/index.d.ts
vendored
Normal file
1
packages/sdk38/types/lcdapi/index.d.ts
vendored
Normal file
@ -0,0 +1 @@
|
||||
export { SupplyModule, TotalSupplyAllReponse, TotalSupplyReponse } from "./supply";
|
||||
16
packages/sdk38/types/lcdapi/supply.d.ts
vendored
Normal file
16
packages/sdk38/types/lcdapi/supply.d.ts
vendored
Normal file
@ -0,0 +1,16 @@
|
||||
import { Coin } from "../coins";
|
||||
import { LcdApiArray, LcdClient, LcdModule } from "../lcdclient";
|
||||
export interface TotalSupplyAllReponse {
|
||||
readonly height: string;
|
||||
readonly result: LcdApiArray<Coin>;
|
||||
}
|
||||
export interface TotalSupplyReponse {
|
||||
readonly height: string;
|
||||
/** The amount */
|
||||
readonly result: string;
|
||||
}
|
||||
export interface SupplyModule extends LcdModule {
|
||||
readonly totalSupplyAll: () => Promise<TotalSupplyAllReponse>;
|
||||
readonly totalSupply: (denom: string) => Promise<TotalSupplyReponse>;
|
||||
}
|
||||
export declare function setupSupplyModule(base: LcdClient): SupplyModule;
|
||||
1
packages/sdk38/types/lcdapi/supply.spec.d.ts
vendored
Normal file
1
packages/sdk38/types/lcdapi/supply.spec.d.ts
vendored
Normal file
@ -0,0 +1 @@
|
||||
export {};
|
||||
2
packages/sdk38/types/lcdclient.d.ts
vendored
2
packages/sdk38/types/lcdclient.d.ts
vendored
@ -12,7 +12,7 @@ import { CosmosSdkTx, StdTx } from "./types";
|
||||
/** Unfortunately, Cosmos SDK encodes empty arrays as null */
|
||||
export declare type LcdApiArray<T> = ReadonlyArray<T> | null;
|
||||
export declare function normalizeArray<T>(backend: LcdApiArray<T>): ReadonlyArray<T>;
|
||||
declare type LcdModule = Record<string, () => any>;
|
||||
export declare type LcdModule = Record<string, (...args: any[]) => any>;
|
||||
declare type LcdModuleSetup<M> = (base: LcdClient) => M;
|
||||
export interface LcdClientBaseOptions {
|
||||
readonly apiUrl: string;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user