account.dart 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import 'dart:async';
  2. import 'dart:convert';
  3. import 'package:polkawallet_sdk/service/index.dart';
  4. class ServiceAccount {
  5. ServiceAccount(this.serviceRoot);
  6. final SubstrateService serviceRoot;
  7. /// encode addresses to publicKeys
  8. Future<Map?> encodeAddress(List<String> pubKeys, ss58List) async {
  9. final dynamic res = await serviceRoot.webView!.evalJavascript(
  10. 'account.encodeAddress(${jsonEncode(pubKeys)}, ${jsonEncode(ss58List)})');
  11. return res;
  12. }
  13. /// decode addresses to publicKeys
  14. Future<Map?> decodeAddress(List<String?> addresses) async {
  15. final dynamic res = await serviceRoot.webView!
  16. .evalJavascript('account.decodeAddress(${jsonEncode(addresses)})');
  17. return res;
  18. }
  19. /// check address matches ss58Format
  20. Future<bool?> checkAddressFormat(String address, int ss58) async {
  21. final dynamic res = await serviceRoot.webView!
  22. .evalJavascript('account.checkAddressFormat("$address", $ss58)');
  23. return res;
  24. }
  25. /// query balance
  26. Future<Map?> queryBalance(String? address) async {
  27. final dynamic res = await serviceRoot.webView!
  28. .evalJavascript('account.getBalance(api, "$address")');
  29. return res;
  30. }
  31. /// Get on-chain account info of addresses
  32. Future<List?> queryIndexInfo(List addresses) async {
  33. final dynamic res = await serviceRoot.webView!.evalJavascript(
  34. 'account.getAccountIndex(api, ${jsonEncode(addresses)})');
  35. return res;
  36. }
  37. /// query address with account index
  38. Future<List?> queryAddressWithAccountIndex(String index, int? ss58) async {
  39. final res = await serviceRoot.webView!.evalJavascript(
  40. 'account.queryAddressWithAccountIndex(api, "$index", $ss58)');
  41. return res;
  42. }
  43. Future<List?> getPubKeyIcons(List<String?> keys) async {
  44. final dynamic res = await serviceRoot.webView!
  45. .evalJavascript('account.genPubKeyIcons(${jsonEncode(keys)})');
  46. return res;
  47. }
  48. Future<List?> getAddressIcons(List addresses) async {
  49. final dynamic res = await serviceRoot.webView!
  50. .evalJavascript('account.genIcons(${jsonEncode(addresses)})');
  51. return res;
  52. }
  53. }