apiStaking.dart 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 = await (service.queryBonded(pubKeys)) ?? [];
  31. data.forEach((e) {
  32. res[e[0]] = AccountBondedInfo(e[0], e[1], e[2]);
  33. });
  34. return res;
  35. }
  36. Future<OwnStashInfoData> queryOwnStashInfo(String accountId) async {
  37. final Map data = await (service.queryOwnStashInfo(accountId)) ?? {};
  38. return OwnStashInfoData.fromJson(
  39. Map<String, dynamic>.of(data as Map<String, dynamic>));
  40. }
  41. Future<Map?> loadValidatorRewardsData(String validatorId) async {
  42. Map? data = await service.loadValidatorRewardsData(validatorId);
  43. return data;
  44. }
  45. Future<List?> getAccountRewardsEraOptions() async {
  46. final List? res = await service.getAccountRewardsEraOptions();
  47. return res;
  48. }
  49. // this query takes extremely long time
  50. Future<Map?> queryAccountRewards(String address, int eras) async {
  51. final Map? res = await service.fetchAccountRewards(address, eras);
  52. return res;
  53. }
  54. Future<int?> getSlashingSpans(String stashId) async {
  55. final int? spans = await service.getSlashingSpans(stashId);
  56. return spans;
  57. }
  58. }