apiStaking.dart 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import 'dart:async';
  2. import 'package:polkawallet_sdk/api/api.dart';
  3. import 'package:polkawallet_sdk/api/types/staking/accountBondedInfo.dart';
  4. import 'package:polkawallet_sdk/api/types/staking/ownStashInfo.dart';
  5. import 'package:polkawallet_sdk/service/staking.dart';
  6. class ApiStaking {
  7. ApiStaking(this.apiRoot, this.service);
  8. final PolkawalletApi apiRoot;
  9. final ServiceStaking service;
  10. Future<Map?> queryElectedInfo() async {
  11. Map? data = await service.queryElectedInfo();
  12. return data;
  13. }
  14. Future<Map?> queryNominations() async {
  15. final res = await service.queryNominations();
  16. return res;
  17. }
  18. Future<Map?> queryNominationsCount() async {
  19. final res = await service.queryNominationsCount();
  20. return res;
  21. }
  22. /// query staking stash-controller relationship of a list of pubKeys,
  23. /// return list of [pubKey, controllerAddress, stashAddress].
  24. Future<Map<String?, AccountBondedInfo>> queryBonded(
  25. List<String> pubKeys) async {
  26. if (pubKeys.length == 0) {
  27. return {};
  28. }
  29. final res = Map<String?, AccountBondedInfo>();
  30. final List data =
  31. await (service.queryBonded(pubKeys) as FutureOr<List<dynamic>>);
  32. data.forEach((e) {
  33. res[e[0]] = AccountBondedInfo(e[0], e[1], e[2]);
  34. });
  35. return res;
  36. }
  37. Future<OwnStashInfoData> queryOwnStashInfo(String accountId) async {
  38. final Map data = await (service.queryOwnStashInfo(accountId)
  39. as FutureOr<Map<dynamic, dynamic>>);
  40. return OwnStashInfoData.fromJson(
  41. Map<String, dynamic>.of(data as Map<String, dynamic>));
  42. }
  43. Future<Map?> loadValidatorRewardsData(String validatorId) async {
  44. Map? data = await service.loadValidatorRewardsData(validatorId);
  45. return data;
  46. }
  47. Future<List?> getAccountRewardsEraOptions() async {
  48. final List? res = await service.getAccountRewardsEraOptions();
  49. return res;
  50. }
  51. // this query takes extremely long time
  52. Future<Map?> queryAccountRewards(String address, int eras) async {
  53. final Map? res = await service.fetchAccountRewards(address, eras);
  54. return res;
  55. }
  56. Future<int?> getSlashingSpans(String stashId) async {
  57. final int? spans = await service.getSlashingSpans(stashId);
  58. return spans;
  59. }
  60. }