Add support for slashing queries

This commit is contained in:
Simon Warta 2020-07-09 11:08:28 +02:00
parent 5fd8396271
commit e09ff5a78c
7 changed files with 146 additions and 0 deletions

View File

@ -36,7 +36,11 @@ export {
SearchTxsResponse,
setupAuthExtension,
setupBankExtension,
setupSlashingExtension,
setupSupplyExtension,
SlashingExtension,
SlashingParametersResponse,
SlashingSigningInfosResponse,
SupplyExtension,
TxsResponse,
} from "./lcdapi";

View File

@ -4,6 +4,12 @@
export { AuthExtension, AuthAccountsResponse, setupAuthExtension } from "./auth";
export { BankBalancesResponse, BankExtension, setupBankExtension } from "./bank";
export {
setupSlashingExtension,
SlashingExtension,
SlashingParametersResponse,
SlashingSigningInfosResponse,
} from "./slashing";
export { setupSupplyExtension, SupplyExtension, TotalSupplyAllResponse, TotalSupplyResponse } from "./supply";
//

View File

@ -0,0 +1,49 @@
/* eslint-disable @typescript-eslint/camelcase */
import { nonNegativeIntegerMatcher, pendingWithoutWasmd, wasmd } from "../testutils.spec";
import { LcdClient } from "./lcdclient";
import { setupSlashingExtension, SlashingExtension } from "./slashing";
function makeSlashingClient(apiUrl: string): LcdClient & SlashingExtension {
return LcdClient.withExtensions({ apiUrl }, setupSlashingExtension);
}
describe("SlashingExtension", () => {
describe("signingInfos", () => {
it("works", async () => {
pendingWithoutWasmd();
const client = makeSlashingClient(wasmd.endpoint);
const response = await client.slashing.signingInfos();
expect(response).toEqual({
height: jasmine.stringMatching(nonNegativeIntegerMatcher),
result: [
{
address: "cosmosvalcons1yyjaavsv98lwn8he9lzcjhefzyyn4xygfyxls0",
start_height: "0",
index_offset: jasmine.stringMatching(nonNegativeIntegerMatcher),
jailed_until: "1970-01-01T00:00:00Z",
tombstoned: false,
missed_blocks_counter: "0",
},
],
});
});
});
describe("parameters", () => {
it("works", async () => {
pendingWithoutWasmd();
const client = makeSlashingClient(wasmd.endpoint);
const response = await client.slashing.parameters();
expect(response).toEqual({
height: jasmine.stringMatching(nonNegativeIntegerMatcher),
result: {
signed_blocks_window: "100",
min_signed_per_window: "0.500000000000000000",
downtime_jail_duration: "600000000000",
slash_fraction_double_sign: "0.050000000000000000",
slash_fraction_downtime: "0.010000000000000000",
},
});
});
});
});

View File

@ -0,0 +1,46 @@
import { LcdClient } from "./lcdclient";
interface SlashingSigningInfo {
readonly address: string;
readonly start_height: string;
readonly index_offset: string;
readonly jailed_until: string;
readonly tombstoned: boolean;
readonly missed_blocks_counter: string;
}
export interface SlashingSigningInfosResponse {
readonly height: string;
readonly result: readonly SlashingSigningInfo[];
}
export interface SlashingParametersResponse {
readonly height: string;
readonly result: {
readonly signed_blocks_window: string;
readonly min_signed_per_window: string;
readonly downtime_jail_duration: string;
readonly slash_fraction_double_sign: string;
readonly slash_fraction_downtime: string;
};
}
export interface SlashingExtension {
readonly slashing: {
readonly signingInfos: () => Promise<SlashingSigningInfosResponse>;
readonly parameters: () => Promise<SlashingParametersResponse>;
};
}
export function setupSlashingExtension(base: LcdClient): SlashingExtension {
return {
slashing: {
signingInfos: async () => {
return base.get(`/slashing/signing_infos`);
},
parameters: async () => {
return base.get(`/slashing/parameters`);
},
},
};
}

View File

@ -34,7 +34,11 @@ export {
SearchTxsResponse,
setupAuthExtension,
setupBankExtension,
setupSlashingExtension,
setupSupplyExtension,
SlashingExtension,
SlashingParametersResponse,
SlashingSigningInfosResponse,
SupplyExtension,
TxsResponse,
} from "./lcdapi";

View File

@ -1,5 +1,11 @@
export { AuthExtension, AuthAccountsResponse, setupAuthExtension } from "./auth";
export { BankBalancesResponse, BankExtension, setupBankExtension } from "./bank";
export {
setupSlashingExtension,
SlashingExtension,
SlashingParametersResponse,
SlashingSigningInfosResponse,
} from "./slashing";
export { setupSupplyExtension, SupplyExtension, TotalSupplyAllResponse, TotalSupplyResponse } from "./supply";
export {
BlockResponse,

View File

@ -0,0 +1,31 @@
import { LcdClient } from "./lcdclient";
interface SlashingSigningInfo {
readonly address: string;
readonly start_height: string;
readonly index_offset: string;
readonly jailed_until: string;
readonly tombstoned: boolean;
readonly missed_blocks_counter: string;
}
export interface SlashingSigningInfosResponse {
readonly height: string;
readonly result: readonly SlashingSigningInfo[];
}
export interface SlashingParametersResponse {
readonly height: string;
readonly result: {
readonly signed_blocks_window: string;
readonly min_signed_per_window: string;
readonly downtime_jail_duration: string;
readonly slash_fraction_double_sign: string;
readonly slash_fraction_downtime: string;
};
}
export interface SlashingExtension {
readonly slashing: {
readonly signingInfos: () => Promise<SlashingSigningInfosResponse>;
readonly parameters: () => Promise<SlashingParametersResponse>;
};
}
export declare function setupSlashingExtension(base: LcdClient): SlashingExtension;
export {};