Explorar o código

доработки блокчейнов

Rimmon %!s(int64=4) %!d(string=hai) anos
pai
achega
8295014e14
Modificáronse 4 ficheiros con 52 adicións e 11 borrados
  1. 27 6
      Models/AccountModel.cs
  2. 9 2
      Models/Blockchain.cs
  3. 4 2
      MySQLConnector.cs
  4. 12 1
      Pages/Blockchains.razor

+ 27 - 6
Models/AccountModel.cs

@@ -32,6 +32,7 @@ namespace HyperCube.Models
         public static Dictionary<string, AccountModel> Loaded = new();
         public static AccountModel Current;
         public string eth_address { get; set; }
+        public string eth_address1 { get; set; }
         /// <summary>
         /// ASP Identity ID
         /// </summary>
@@ -61,11 +62,15 @@ namespace HyperCube.Models
 
         public static BigInteger ConvertBalance(string hex)
         {
-            Console.WriteLine($"ConvertBalance {hex}");
-            string newHex = hex.Remove(0, 2);
-            var balance = System.Numerics.BigInteger.Parse("0"+ newHex, System.Globalization.NumberStyles.HexNumber );
-            Console.WriteLine($"ConvertBalance {hex} {balance}");
-            return balance;
+            if (hex != null && hex.Length > 0)
+            {
+                Console.WriteLine($"ConvertBalance {hex}");
+                string newHex = hex.Remove(0, 2);
+                var balance = System.Numerics.BigInteger.Parse("0" + newHex, System.Globalization.NumberStyles.HexNumber);
+                Console.WriteLine($"ConvertBalance {hex} {balance}");
+                return balance;
+            }
+            return 0;
         }
 
         public static async void InitializeAccounts()
@@ -75,6 +80,22 @@ namespace HyperCube.Models
             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}");
+                    }
+                }
+
             }
         }
 
@@ -108,7 +129,7 @@ namespace HyperCube.Models
 
         public async Task<string> GetBalance()
         {
-            var res = await Blockchain.GetMain().GetBalance(eth_address);
+            var res = await Blockchain.GetMain().GetBalance(this);
             var balanceInt = ConvertBalance(res);
             string balance = balanceInt.ToString();
             //Console.WriteLine($"GetBalance {balance}");

+ 9 - 2
Models/Blockchain.cs

@@ -96,7 +96,8 @@ namespace HyperCube.Models
             if (account != null)
             {
                 Console.WriteLine($"CreateBlockchainAccount {account}: {res}");
-                query = $"update aspnetusers set eth_address='{res}' where UserName='{account.Name}'";
+                //query = $"update aspnetusers set eth_address='{res}' where UserName='{account.Name}'";
+                query = $"update account_wallets set uuid='{res}' where account_uuid='{account.UUID}'";
                 account.eth_address = res;
                 Console.WriteLine($"CreateBlockchainAccount query {query}");
                 MySQLConnector.Instance().SQLInsert(query);
@@ -165,7 +166,6 @@ namespace HyperCube.Models
             if (res.Count > 0)
             {
                 address = jsonDe.result[0];
-
             }
             else
             {
@@ -218,6 +218,13 @@ namespace HyperCube.Models
             //return "test answer";
         }
 
+        public async Task<string> GetBalance(AccountModel account)
+        {
+            var addr = id == 0 ? account.eth_address : account.eth_address1;
+            var ret = await RunFunction("eth_getBalance", $"\"{addr}\",\"latest\"");
+            return ret;
+        }
+
         public async Task<string> GetBalance(string address)
         {
             var ret = await RunFunction("eth_getBalance", $"\"{address}\",\"latest\"");

+ 4 - 2
MySQLConnector.cs

@@ -77,8 +77,10 @@ namespace HyperCube
                     newacc.UUID = rdr.GetString(0); 
                     newacc.Name = rdr.GetString(1);
                     newacc.Email = rdr.GetString(3);
-                    if (!rdr.IsDBNull(15))
-                        newacc.eth_address = rdr.GetString(15);
+                    //if (!rdr.IsDBNull(15))
+                    //    newacc.eth_address = rdr.GetString(15);
+
+
                     if (!accs.ContainsKey(newacc.UUID))
                         accs.Add(newacc.UUID, newacc);
                     newacc.blockchain_selected = rdr.GetByte(17);

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 12 - 1
Pages/Blockchains.razor