mirror of
https://github.com/cosmos/cosmjs.git
synced 2025-03-11 14:09:15 +00:00
Add MintExtension
This commit is contained in:
parent
0fa5da299c
commit
50dbca558b
@ -30,12 +30,17 @@ export {
|
||||
EncodeTxResponse,
|
||||
LcdApiArray,
|
||||
LcdClient,
|
||||
MintAnnualProvisionsResponse,
|
||||
MintExtension,
|
||||
MintInflationResponse,
|
||||
MintParametersResponse,
|
||||
NodeInfoResponse,
|
||||
normalizeLcdApiArray,
|
||||
PostTxsResponse,
|
||||
SearchTxsResponse,
|
||||
setupAuthExtension,
|
||||
setupBankExtension,
|
||||
setupMintExtension,
|
||||
setupSlashingExtension,
|
||||
setupSupplyExtension,
|
||||
SlashingExtension,
|
||||
|
@ -4,6 +4,13 @@
|
||||
|
||||
export { AuthExtension, AuthAccountsResponse, setupAuthExtension } from "./auth";
|
||||
export { BankBalancesResponse, BankExtension, setupBankExtension } from "./bank";
|
||||
export {
|
||||
MintAnnualProvisionsResponse,
|
||||
MintExtension,
|
||||
MintInflationResponse,
|
||||
MintParametersResponse,
|
||||
setupMintExtension,
|
||||
} from "./mint";
|
||||
export {
|
||||
setupSlashingExtension,
|
||||
SlashingExtension,
|
||||
|
59
packages/sdk38/src/lcdapi/mint.spec.ts
Normal file
59
packages/sdk38/src/lcdapi/mint.spec.ts
Normal file
@ -0,0 +1,59 @@
|
||||
/* eslint-disable @typescript-eslint/camelcase */
|
||||
import {
|
||||
bigDecimalMatcher,
|
||||
nonNegativeIntegerMatcher,
|
||||
pendingWithoutWasmd,
|
||||
smallDecimalMatcher,
|
||||
wasmd,
|
||||
} from "../testutils.spec";
|
||||
import { LcdClient } from "./lcdclient";
|
||||
import { MintExtension, setupMintExtension } from "./mint";
|
||||
|
||||
function makeMintClient(apiUrl: string): LcdClient & MintExtension {
|
||||
return LcdClient.withExtensions({ apiUrl }, setupMintExtension);
|
||||
}
|
||||
|
||||
describe("MintExtension", () => {
|
||||
describe("parameters", () => {
|
||||
it("works", async () => {
|
||||
pendingWithoutWasmd();
|
||||
const client = makeMintClient(wasmd.endpoint);
|
||||
const response = await client.mint.parameters();
|
||||
expect(response).toEqual({
|
||||
height: jasmine.stringMatching(nonNegativeIntegerMatcher),
|
||||
result: {
|
||||
mint_denom: "ustake",
|
||||
inflation_rate_change: "0.130000000000000000",
|
||||
inflation_max: "0.200000000000000000",
|
||||
inflation_min: "0.070000000000000000",
|
||||
goal_bonded: "0.670000000000000000",
|
||||
blocks_per_year: "6311520",
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("inflation", () => {
|
||||
it("works", async () => {
|
||||
pendingWithoutWasmd();
|
||||
const client = makeMintClient(wasmd.endpoint);
|
||||
const response = await client.mint.inflation();
|
||||
expect(response).toEqual({
|
||||
height: jasmine.stringMatching(nonNegativeIntegerMatcher),
|
||||
result: jasmine.stringMatching(smallDecimalMatcher),
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("annualProvisions", () => {
|
||||
it("works", async () => {
|
||||
pendingWithoutWasmd();
|
||||
const client = makeMintClient(wasmd.endpoint);
|
||||
const response = await client.mint.annualProvisions();
|
||||
expect(response).toEqual({
|
||||
height: jasmine.stringMatching(nonNegativeIntegerMatcher),
|
||||
result: jasmine.stringMatching(bigDecimalMatcher),
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
41
packages/sdk38/src/lcdapi/mint.ts
Normal file
41
packages/sdk38/src/lcdapi/mint.ts
Normal file
@ -0,0 +1,41 @@
|
||||
import { LcdClient } from "./lcdclient";
|
||||
|
||||
export interface MintParametersResponse {
|
||||
readonly height: string;
|
||||
readonly result: {
|
||||
readonly mint_denom: string;
|
||||
readonly inflation_rate_change: string;
|
||||
readonly inflation_max: string;
|
||||
readonly inflation_min: string;
|
||||
readonly goal_bonded: string;
|
||||
readonly blocks_per_year: string;
|
||||
};
|
||||
}
|
||||
|
||||
export interface MintInflationResponse {
|
||||
readonly height: string;
|
||||
readonly result: string;
|
||||
}
|
||||
|
||||
export interface MintAnnualProvisionsResponse {
|
||||
readonly height: string;
|
||||
readonly result: string;
|
||||
}
|
||||
|
||||
export interface MintExtension {
|
||||
readonly mint: {
|
||||
readonly parameters: () => Promise<MintParametersResponse>;
|
||||
readonly inflation: () => Promise<MintInflationResponse>;
|
||||
readonly annualProvisions: () => Promise<MintAnnualProvisionsResponse>;
|
||||
};
|
||||
}
|
||||
|
||||
export function setupMintExtension(base: LcdClient): MintExtension {
|
||||
return {
|
||||
mint: {
|
||||
parameters: async () => base.get(`/minting/parameters`),
|
||||
inflation: async () => base.get(`/minting/inflation`),
|
||||
annualProvisions: async () => base.get(`/minting/annual-provisions`),
|
||||
},
|
||||
};
|
||||
}
|
@ -9,6 +9,10 @@ export function makeRandomAddress(): string {
|
||||
}
|
||||
|
||||
export const nonNegativeIntegerMatcher = /^[0-9]+$/;
|
||||
/** Matches decimals < 1.0 */
|
||||
export const smallDecimalMatcher = /^0\.[0-9]+$/;
|
||||
/** Matches decimals >= 1.0 */
|
||||
export const bigDecimalMatcher = /^[1-9][0-9]*\.[0-9]+$/;
|
||||
export const tendermintIdMatcher = /^[0-9A-F]{64}$/;
|
||||
export const tendermintOptionalIdMatcher = /^([0-9A-F]{64}|)$/;
|
||||
export const tendermintAddressMatcher = /^[0-9A-F]{40}$/;
|
||||
|
5
packages/sdk38/types/index.d.ts
vendored
5
packages/sdk38/types/index.d.ts
vendored
@ -28,12 +28,17 @@ export {
|
||||
EncodeTxResponse,
|
||||
LcdApiArray,
|
||||
LcdClient,
|
||||
MintAnnualProvisionsResponse,
|
||||
MintExtension,
|
||||
MintInflationResponse,
|
||||
MintParametersResponse,
|
||||
NodeInfoResponse,
|
||||
normalizeLcdApiArray,
|
||||
PostTxsResponse,
|
||||
SearchTxsResponse,
|
||||
setupAuthExtension,
|
||||
setupBankExtension,
|
||||
setupMintExtension,
|
||||
setupSlashingExtension,
|
||||
setupSupplyExtension,
|
||||
SlashingExtension,
|
||||
|
7
packages/sdk38/types/lcdapi/index.d.ts
vendored
7
packages/sdk38/types/lcdapi/index.d.ts
vendored
@ -1,5 +1,12 @@
|
||||
export { AuthExtension, AuthAccountsResponse, setupAuthExtension } from "./auth";
|
||||
export { BankBalancesResponse, BankExtension, setupBankExtension } from "./bank";
|
||||
export {
|
||||
MintAnnualProvisionsResponse,
|
||||
MintExtension,
|
||||
MintInflationResponse,
|
||||
MintParametersResponse,
|
||||
setupMintExtension,
|
||||
} from "./mint";
|
||||
export {
|
||||
setupSlashingExtension,
|
||||
SlashingExtension,
|
||||
|
28
packages/sdk38/types/lcdapi/mint.d.ts
vendored
Normal file
28
packages/sdk38/types/lcdapi/mint.d.ts
vendored
Normal file
@ -0,0 +1,28 @@
|
||||
import { LcdClient } from "./lcdclient";
|
||||
export interface MintParametersResponse {
|
||||
readonly height: string;
|
||||
readonly result: {
|
||||
readonly mint_denom: string;
|
||||
readonly inflation_rate_change: string;
|
||||
readonly inflation_max: string;
|
||||
readonly inflation_min: string;
|
||||
readonly goal_bonded: string;
|
||||
readonly blocks_per_year: string;
|
||||
};
|
||||
}
|
||||
export interface MintInflationResponse {
|
||||
readonly height: string;
|
||||
readonly result: string;
|
||||
}
|
||||
export interface MintAnnualProvisionsResponse {
|
||||
readonly height: string;
|
||||
readonly result: string;
|
||||
}
|
||||
export interface MintExtension {
|
||||
readonly mint: {
|
||||
readonly parameters: () => Promise<MintParametersResponse>;
|
||||
readonly inflation: () => Promise<MintInflationResponse>;
|
||||
readonly annualProvisions: () => Promise<MintAnnualProvisionsResponse>;
|
||||
};
|
||||
}
|
||||
export declare function setupMintExtension(base: LcdClient): MintExtension;
|
Loading…
x
Reference in New Issue
Block a user