AccountModel.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using System;
  2. using System.Numerics;
  3. using System.Threading.Tasks;
  4. using System.Collections.Generic;
  5. using Console = HyperCube.Utils.AdvConsole;
  6. namespace HyperCube.Models
  7. {
  8. public enum Role { Admin = 1, Verifier, User }
  9. public class AccountModel
  10. {
  11. public static Dictionary<string, AccountModel> Loaded = new();
  12. public static AccountModel Current;
  13. public string eth_address { get; set; }
  14. /// <summary>
  15. /// ASP Identity ID
  16. /// </summary>
  17. public string UUID { get; set; }
  18. public string Name { get; set; }
  19. public string Email { get; set; }
  20. public Role AccRole { get; set; }
  21. public AccountModel()
  22. {
  23. }
  24. public static AccountModel GetCurrent()
  25. {
  26. return Current;
  27. }
  28. public static AccountModel Find(string uuid)
  29. {
  30. if (uuid == null)
  31. return null;
  32. if (Loaded.ContainsKey(uuid))
  33. return Loaded[uuid];
  34. else
  35. return null;
  36. }
  37. public static BigInteger ConvertBalance(string hex)
  38. {
  39. if (hex.Length > 0)
  40. {
  41. string newHex = hex.Remove(0, 2);
  42. var balance = System.Numerics.BigInteger.Parse("0" + newHex, System.Globalization.NumberStyles.HexNumber);
  43. Console.WriteLine($"ConvertBalance {hex} {balance}");
  44. return balance;
  45. }
  46. else
  47. return 0;
  48. }
  49. public static async void InitializeAccounts()
  50. {
  51. Loaded = await MySQLConnector.Instance().SQLSelectASPUsers();
  52. Console.WriteLine("InitializeAccounts");
  53. }
  54. public async Task GetEthAddress()
  55. {
  56. var addr = await Blockchain.GetMain().CreateBlockchainAccount(this);
  57. }
  58. public async Task<string> GetBalance()
  59. {
  60. var res = await Blockchain.GetMain().GetBalance(eth_address);
  61. var balanceInt = ConvertBalance(res);
  62. string balance = balanceInt.ToString();
  63. //Console.WriteLine($"GetBalance {balance}");
  64. return balance;
  65. }
  66. }
  67. }