staking.dart 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import 'dart:async';
  2. import 'dart:convert';
  3. import 'package:polkawallet_sdk/service/index.dart';
  4. class ServiceStaking {
  5. ServiceStaking(this.serviceRoot);
  6. final SubstrateService serviceRoot;
  7. Future<Map?> queryElectedInfo() async {
  8. dynamic data = await serviceRoot.webView!
  9. .evalJavascript('staking.querySortedTargets(api)', allowRepeat: false);
  10. return data;
  11. }
  12. Future<Map?> queryNominations() async {
  13. dynamic data = await serviceRoot.webView!
  14. .evalJavascript('staking.queryNominations(api)', allowRepeat: false);
  15. return data;
  16. }
  17. Future<Map?> queryNominationsCount() async {
  18. dynamic data = await serviceRoot.webView!.evalJavascript(
  19. 'staking.queryNominationsCount(api)',
  20. allowRepeat: false);
  21. return data;
  22. }
  23. Future<List?> queryBonded(List<String> pubKeys) async {
  24. dynamic res = await serviceRoot.webView!.evalJavascript(
  25. 'account.queryAccountsBonded(api, ${jsonEncode(pubKeys)})');
  26. return res;
  27. }
  28. Future<Map?> queryOwnStashInfo(String accountId) async {
  29. dynamic data = await serviceRoot.webView!
  30. .evalJavascript('staking.getOwnStashInfo(api, "$accountId")');
  31. return data;
  32. }
  33. Future<Map?> loadValidatorRewardsData(String validatorId) async {
  34. dynamic data = await serviceRoot.webView!.evalJavascript(
  35. 'staking.loadValidatorRewardsData(api, "$validatorId")');
  36. return data;
  37. }
  38. Future<List?> getAccountRewardsEraOptions() async {
  39. final dynamic res = await serviceRoot.webView!
  40. .evalJavascript('staking.getAccountRewardsEraOptions(api)');
  41. return res;
  42. }
  43. // this query takes extremely long time
  44. Future<Map?> fetchAccountRewards(String address, int eras) async {
  45. final dynamic res = await serviceRoot.webView!.evalJavascript(
  46. 'staking.loadAccountRewardsData(api, "$address", $eras)');
  47. return res;
  48. }
  49. Future<int?> getSlashingSpans(String stashId) async {
  50. final dynamic spans = await serviceRoot.webView!
  51. .evalJavascript('staking.getSlashingSpans(api, "$stashId")');
  52. return spans;
  53. }
  54. }