get-status.ts 770 B

12345678910111213141516171819202122232425262728
  1. import { log } from "./debug";
  2. import { JoyApi } from "./joyApi";
  3. import { EraStatus } from "./Types";
  4. import { PromiseAllObj } from "./utils";
  5. const api = new JoyApi();
  6. export async function getChainState() {
  7. await api.init;
  8. const status = await PromiseAllObj({
  9. totalIssuance: await api.totalIssuance(),
  10. finalizedBlockHeight: await api.finalizedBlockHeight(),
  11. validators: await api.validatorsData(),
  12. system: await api.systemData(),
  13. });
  14. log(status)
  15. return status;
  16. }
  17. export async function getValidatorStatistics(address: string, blockStart: number): Promise<EraStatus> {
  18. await api.init;
  19. const status = await PromiseAllObj({
  20. status: await api.getActiveErasForBlock(address, blockStart)
  21. })
  22. return status as unknown as EraStatus
  23. }