|
@@ -4,6 +4,7 @@ using System.Numerics;
|
|
|
using System.Threading.Tasks;
|
|
|
using System.Collections.Generic;
|
|
|
using Console = HyperCube.Utils.AdvConsole;
|
|
|
+using Microsoft.AspNetCore.Components;
|
|
|
|
|
|
namespace HyperCube.Models
|
|
|
{
|
|
@@ -11,6 +12,9 @@ namespace HyperCube.Models
|
|
|
|
|
|
public class AccountModel
|
|
|
{
|
|
|
+ [Inject]
|
|
|
+ AppData AppData { get; set; }
|
|
|
+
|
|
|
//public event EventHandler<int> RolesChanged;
|
|
|
public Action<int> RolesChanged;
|
|
|
public byte bsel;
|
|
@@ -43,13 +47,11 @@ namespace HyperCube.Models
|
|
|
Console.WriteLine($"role removed, сount: {Roles.Count}");
|
|
|
}
|
|
|
|
|
|
- public static Dictionary<string, AccountModel> Loaded = new();
|
|
|
- public static AccountModel Current;
|
|
|
- string eth_address { get; set; }
|
|
|
- string eth_address1 { get; set; }
|
|
|
- /// <summary>
|
|
|
- /// ASP Identity ID
|
|
|
- /// </summary>
|
|
|
+ //public Dictionary<string, AccountModel> Loaded = new();
|
|
|
+ //public AccountModel Current;
|
|
|
+
|
|
|
+ public string ETH_Address { get; set; }
|
|
|
+ public string ETH_Address1 { get; set; }
|
|
|
public string UUID { get; set; }
|
|
|
public string Name { get; set; }
|
|
|
public string Email { get; set; }
|
|
@@ -60,9 +62,9 @@ namespace HyperCube.Models
|
|
|
{
|
|
|
string addr;
|
|
|
if (bc.port == 8666)
|
|
|
- addr = eth_address1;
|
|
|
+ addr = ETH_Address1;
|
|
|
else
|
|
|
- addr = eth_address;
|
|
|
+ addr = ETH_Address;
|
|
|
|
|
|
return addr;
|
|
|
}
|
|
@@ -71,9 +73,9 @@ namespace HyperCube.Models
|
|
|
{
|
|
|
string addr;
|
|
|
if (bc.port == 8666)
|
|
|
- addr = eth_address1;
|
|
|
+ addr = ETH_Address1;
|
|
|
else
|
|
|
- addr = eth_address;
|
|
|
+ addr = ETH_Address;
|
|
|
|
|
|
if (addr == null || addr == "")
|
|
|
addr = await bc.CreateBlockchainAccount(this, PWDHash);
|
|
@@ -83,34 +85,38 @@ namespace HyperCube.Models
|
|
|
public void SetActualAddress(string value, Blockchain bc)
|
|
|
{
|
|
|
if (bc.port == 8666)
|
|
|
- eth_address1 = value;
|
|
|
+ ETH_Address1 = value;
|
|
|
else
|
|
|
- eth_address = value;
|
|
|
+ ETH_Address = value;
|
|
|
}
|
|
|
|
|
|
public AccountModel()
|
|
|
{
|
|
|
}
|
|
|
|
|
|
- public static AccountModel GetCurrent()
|
|
|
+ public AccountModel GetCurrent()
|
|
|
{
|
|
|
- return Current;
|
|
|
+ return AppData.CurrentAccount;
|
|
|
}
|
|
|
|
|
|
- public static AccountModel FindByMail(string mail)
|
|
|
+ public async Task<AccountModel> FindByMail(string mail)
|
|
|
{
|
|
|
- var selectedUsers = from user in Loaded.Values
|
|
|
+ var loaded = await AppData.LoadAccounts();
|
|
|
+
|
|
|
+ var selectedUsers = from user in loaded.Values
|
|
|
where user.Email == mail
|
|
|
select user;
|
|
|
return selectedUsers.First();
|
|
|
}
|
|
|
|
|
|
- public static AccountModel Find(string uuid)
|
|
|
+ public async Task<AccountModel> Find(string uuid)
|
|
|
{
|
|
|
+ var loaded = await AppData.LoadAccounts();
|
|
|
+
|
|
|
if (uuid == null)
|
|
|
return null;
|
|
|
- if (Loaded.ContainsKey(uuid))
|
|
|
- return Loaded[uuid];
|
|
|
+ if (loaded.ContainsKey(uuid))
|
|
|
+ return loaded[uuid];
|
|
|
else
|
|
|
return null;
|
|
|
}
|
|
@@ -128,31 +134,31 @@ namespace HyperCube.Models
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
- public static async void InitializeAccounts()
|
|
|
- {
|
|
|
- Loaded = await MySQLConnector.Instance().SQLSelectASPUsers();
|
|
|
- Console.WriteLine("InitializeAccounts");
|
|
|
- foreach (var acc in Loaded)
|
|
|
- {
|
|
|
- acc.Value.LoadRoles();
|
|
|
- var wallets = await MySQLConnector.Instance().SQLSelectComplex($"select * from account_wallets where account_uuid='{acc.Value.UUID}'");
|
|
|
-
|
|
|
- if (wallets.Count > 0)
|
|
|
- {
|
|
|
- foreach (var wallet in wallets)
|
|
|
- {
|
|
|
- var bc_id = Convert.ToInt32(wallet["blockchain_id"]);
|
|
|
- var wallet_id = Convert.ToString(wallet["uuid"]);
|
|
|
- if (bc_id == 0)
|
|
|
- acc.Value.eth_address = wallet_id;
|
|
|
- else
|
|
|
- acc.Value.eth_address1 = wallet_id;
|
|
|
- Console.WriteLine($"acc {acc.Value.Name} wallet0 {acc.Value.eth_address} wallet1 {acc.Value.eth_address1}");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
+ //public static async void InitializeAccounts()
|
|
|
+ //{
|
|
|
+ // Loaded = await MySQLConnector.Instance().SQLSelectASPUsers();
|
|
|
+ // Console.WriteLine("InitializeAccounts");
|
|
|
+ // foreach (var acc in Loaded)
|
|
|
+ // {
|
|
|
+ // acc.Value.LoadRoles();
|
|
|
+ // var wallets = await MySQLConnector.Instance().SQLSelectComplex($"select * from account_wallets where account_uuid='{acc.Value.UUID}'");
|
|
|
+
|
|
|
+ // if (wallets.Count > 0)
|
|
|
+ // {
|
|
|
+ // foreach (var wallet in wallets)
|
|
|
+ // {
|
|
|
+ // var bc_id = Convert.ToInt32(wallet["blockchain_id"]);
|
|
|
+ // var wallet_id = Convert.ToString(wallet["uuid"]);
|
|
|
+ // if (bc_id == 0)
|
|
|
+ // acc.Value.eth_address = wallet_id;
|
|
|
+ // else
|
|
|
+ // acc.Value.eth_address1 = wallet_id;
|
|
|
+ // Console.WriteLine($"acc {acc.Value.Name} wallet0 {acc.Value.eth_address} wallet1 {acc.Value.eth_address1}");
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+
|
|
|
+ // }
|
|
|
+ //}
|
|
|
|
|
|
public async void LoadRoles()
|
|
|
{
|