Browse Source

блокчейн работает

Rimmon 3 years ago
parent
commit
8dce7e38a1

+ 2 - 5
AppData.cs

@@ -3,9 +3,6 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Threading.Tasks;
 using HyperCube.Models;
-using Microsoft.AspNetCore.Components;
-using Microsoft.AspNetCore.Components.Authorization;
-using Microsoft.AspNetCore.Identity;
 using Console = HyperCube.Utils.AdvConsole;
 
 namespace HyperCube
@@ -14,9 +11,9 @@ namespace HyperCube
     /// Синглтон приложения
     /// </summary>
     public class AppData
-    {
+    {        
         public ReportModel Report { get; set; } = new();
-        public AccountModel CurrentAccount { get; set; }
+        public AccountModel CurrentAccount;
         public ArticleModel CurrentArticle { get; set; }
         public ArticleModel CurrentArticleClone { get; set; }
 

+ 6 - 2
Controllers/ValuesController.cs

@@ -24,10 +24,14 @@ namespace HyperCube.Controllers
         [HttpGet("{id}/{email}")]
         public async Task<string> Get(int id, string email)
         {
+            var acc = AccountModel.FindByMail(email);
             string transactionId = $"not found: {id} {email}";
             var article = ArticleModel.Find(id);
-            if (article != null)
-                transactionId = await SmartContract.Verify(article);
+            if (article != null && acc != null)
+            {
+                var bc = await acc.GetSelectedBlockChain();
+                transactionId = await SmartContract.Verify(acc, article, bc);
+            }
             return transactionId;
         }
 

+ 30 - 9
Models/AccountModel.cs

@@ -4,16 +4,22 @@ using System.Numerics;
 using System.Threading.Tasks;
 using System.Collections.Generic;
 using Console = HyperCube.Utils.AdvConsole;
+using Microsoft.AspNetCore.Components;
+using Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage;
 
 namespace HyperCube.Models
 {
     public enum Role { Admin = 1, Verifier, Initiator, Requester }
 
-    public class AccountModel
+    public class AccountModel: ComponentBase
     {
+        [Inject]
+        AppData AppData { get; set; }
+        [Inject]
+        ProtectedSessionStorage storage { get; set; }
         //public event EventHandler<int> RolesChanged;
         public Action<int> RolesChanged;
-        public byte bsel;
+        public byte bsel = 0;
         public byte blockchain_selected
         {
             get { return bsel; }
@@ -44,7 +50,6 @@ namespace HyperCube.Models
         }
 
         public static Dictionary<string, AccountModel> Loaded = new();
-        public static AccountModel Current;
         string eth_address { get; set; }
         string eth_address1 { get; set; }
         /// <summary>
@@ -88,13 +93,28 @@ namespace HyperCube.Models
                 eth_address = value;
         }
 
-        public AccountModel()
-        {
-        }
+        public AccountModel(){}
 
-        public static AccountModel GetCurrent()
+        public async Task<Blockchain> GetSelectedBlockChain()
         {
-            return Current;
+            //Console.WriteLine($"AppData null { AppData == null}");
+            //var res = await storage.GetAsync<AccountModel>("acc");
+            //var accountCurrent = res.Value;
+            //var accountCurrent = AppData.CurrentAccount;
+            //Console.WriteLine($"AppData acc null { accountCurrent == null}");
+            if (Blockchain.loaded.Count > blockchain_selected)
+            {
+                var bc = Blockchain.loaded[blockchain_selected];
+                Console.WriteLine($"GetMain blockchain_selected {blockchain_selected} " + bc.address);
+                return bc;
+            }
+            else
+            {
+                Console.WriteLine($"Error: blockchains loaded {Blockchain.loaded.Count}");
+                blockchain_selected = (byte)(Blockchain.loaded.Count - 1);
+            }
+
+            return null;
         }
 
         public static AccountModel FindByMail(string mail)
@@ -184,7 +204,8 @@ namespace HyperCube.Models
 
         public async Task<string> GetBalance()
         {
-            var res = await Blockchain.GetMain().GetBalance(this);
+            var bc = await GetSelectedBlockChain();
+            var res = await bc.GetBalance(this);
             //var balanceInt = ConvertBalance(res);
             //string balance = balanceInt.ToString();
             //Console.WriteLine($"GetBalance {balance}");

+ 15 - 25
Models/Blockchain.cs

@@ -11,6 +11,7 @@ using Console = HyperCube.Utils.AdvConsole;
 using System.Text.RegularExpressions;
 using QRCoder;
 using System.IO;
+using Microsoft.AspNetCore.Components;
 
 //0xe5D682717955d6C35d465A3485625C64655a04f4 - HCB in rinkeby
 //0xb504ba124b74333d8536db534f7fcdc174d6ee3d - system address rinkeby
@@ -18,7 +19,7 @@ using System.IO;
 
 
 namespace HyperCube.Models
-{    
+{
     public struct TransactionObject
     {
         public string from;
@@ -30,6 +31,8 @@ namespace HyperCube.Models
 
     public class Blockchain
     {
+        [Inject]
+        AppData AppData { get; set; }
         public static Blockchain Dev
         {
             get {
@@ -44,15 +47,16 @@ namespace HyperCube.Models
         public static string balanceHCB;
 
         public static Dictionary<int, Blockchain> supported;
-        public static string Connected
-        {
-            get {
-                var bc = GetMain();
-                if (bc != null)
-                    return $"{bc.name}";
-                return "none";
-            }
-        }
+        //public static string Connected
+        //{
+        //    get
+        //    {
+        //        var bc = AppData.CurrentAccount.GetSelectedBlockChain(); //acc selected
+        //        if (bc != null)
+        //            return $"{bc.name}";
+        //        return "none";
+        //    }
+        //}
         public static string URLdefault = "127.0.0.1";
         //public static int defaultPort = 8545;
         public static int defaultPort = 8666;
@@ -134,7 +138,7 @@ namespace HyperCube.Models
 
             await LoadContracts();
             Console.WriteLine("LoadContracts count " + contracts.Count);
-            Console.WriteLine("connected " + Connected);
+            //Console.WriteLine("connected " + Connected);
             return $"{name} {url}:{port}";
         }
 
@@ -223,20 +227,6 @@ namespace HyperCube.Models
             return res;
         }
 
-        public static Blockchain GetMain()
-        {
-            if (loaded.Count > AccountModel.GetCurrent()?.blockchain_selected)
-            {
-                var bc = loaded[AccountModel.GetCurrent().blockchain_selected];
-                Console.WriteLine($"GetMain blockchain_selected {AccountModel.GetCurrent().blockchain_selected} " + bc.address);
-                return bc;
-            }
-            else
-                Console.WriteLine($"Error: blockchains loaded {loaded.Count}");
-
-            return null;
-        }
-
         public async Task<string> ListAccounts()
         {
             Console.WriteLine($"ListAccounts blockchain {id}");

+ 15 - 0
Models/Expert.cs

@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+
+namespace HyperCube.Models
+{
+    public class Expert: AccountModel
+    {
+        //Modify
+        //Verify
+        //ApproveMaterial
+        //DenyMaterial
+    }
+}

+ 15 - 0
Models/Initiator.cs

@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+
+namespace HyperCube.Models
+{
+    public class Initiator : AccountModel
+    {
+        //RequestEvent
+        //Fund
+        //Start Event
+        //Approve smthn
+    }
+}

+ 12 - 0
Models/Miner.cs

@@ -0,0 +1,12 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+
+namespace HyperCube.Models
+{
+    public class Miner: AccountModel
+    {
+        //ProposeMaterial
+    }
+}

+ 6 - 6
Models/SmartContract.cs

@@ -33,18 +33,18 @@ namespace HyperCube.Models
             return null;
         }
 
-        public static async Task<string> Verify(ArticleModel articleModel)
+        public static async Task<string> Verify(AccountModel verifier, ArticleModel articleModel, Blockchain bc)
         {
             if (articleModel == null)
                 return "Verify failed";
             Console.WriteLine($"Verify starting");
             try
             {
-                VerifyContract verifyContract = Find("Verify", Blockchain.GetMain()) as VerifyContract;
+                VerifyContract verifyContract = Find("Verify", bc) as VerifyContract;
                 if (verifyContract != null)
                 {
                     Console.WriteLine($"VerifyContract found");
-                    return await verifyContract.Run(articleModel);
+                    return await verifyContract.Run(verifier, articleModel);
                 }
                 else
                     Console.WriteLine($"VerifyContract null");
@@ -122,13 +122,13 @@ namespace HyperCube.Models
         /// <param name="newArticle"></param>
         /// <param name="weiValue"></param>
         /// <returns>ID транзакции</returns>
-        public async Task<string> Run(ArticleModel newArticle, string weiValue = "0x0")
+        public async Task<string> Run(AccountModel verifier, ArticleModel newArticle, string weiValue = "0x0")
         {
             var uuid = await newArticle.GetInitiatorUUID();
             var bc = Blockchain.Find(blockchainId);
             if (bc != null)
             {
-                var verifier_address = await AccountModel.Current.GetOrCreateActualAddress(bc);
+                var verifier_address = await verifier.GetOrCreateActualAddress(bc);
 
                 var initiator = AccountModel.Find(uuid);
                 var initiator_address = await initiator.GetOrCreateActualAddress(bc);
@@ -141,7 +141,7 @@ namespace HyperCube.Models
                 verifier_address = Blockchain.zerofill(verifier_address, 64, true);
                 initiator_address = Blockchain.zerofill(initiator_address, 64, true);
 
-                Console.WriteLine($"VerifyContract params article_value  {article_value} edits {edits} verifier {AccountModel.Current.Name} verifier_address: {verifier_address} initiator {initiator.Name} initiator_address: {initiator_address}");
+                Console.WriteLine($"VerifyContract params article_value  {article_value} edits {edits} verifier {verifier.Name} verifier_address: {verifier_address} initiator {initiator.Name} initiator_address: {initiator_address}");
                 //function verify( address payable verifier, address payable initiator, int article_value, int verify_complexity) public returns (uint vReward, uint iReward) 
                 var paramstring = "0x" + functionCompiledHeader + verifier_address + initiator_address + article_value_hex + edits_hex;
                 Console.WriteLine($"VerifyContract Run {initiator.Name} params {paramstring}");

+ 1 - 1
Pages/Account.razor.cs

@@ -20,7 +20,7 @@ namespace HyperCube.Pages
         protected override async Task OnInitializedAsync()
         {
             account = await GetCurrentAcc();
-            if (Blockchain.GetMain() != null)
+            if (account.GetSelectedBlockChain() != null)
                 myBalance = await account.GetBalance();
         }
 

+ 66 - 28
Pages/Blockchains.razor

@@ -8,6 +8,8 @@
 @using Microsoft.AspNetCore.Identity;
 @inject AuthenticationStateProvider AuthenticationStateProvider
 @inject UserManager<IdentityUser> UserManager
+@using Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage;
+@inject ProtectedSessionStorage storage
 
 @attribute [Authorize]
 <div class="tabs__content">
@@ -94,11 +96,11 @@
 
 @if (Blockchain.blockChainsInitialized)
 {
-    <select @bind="AccountModel.GetCurrent().blockchain_selected" style="color:green">
+    <select @bind="account.blockchain_selected" style="color:green">
         <option value=0>Ethereum Dev Network</option>
         <option value=1>Ethereum Test Network</option>
     </select>
-    <p><b>@Blockchain.GetMain().url:@Blockchain.GetMain().port </b><br /> <b>Address:</b> @Blockchain.GetMain().address<br /> <b>Balance:</b> @Blockchain.GetMain().balance</p>
+    <p><b>@bcMain.url:@bcMain.port </b><br /> <b>Address:</b> @bcMain.address<br /> <b>Balance:</b> @bcMain.balance</p>
 
     @*@foreach(var bc in Blockchain.loaded.Values)
                {
@@ -162,9 +164,9 @@
             @if (Blockchain.loaded.Count > 0)
             {
                 result = Blockchain.loaded.Count.ToString();
-                if (Blockchain.GetMain().contracts.Count > 0)
+                if (bcMain.contracts.Count > 0)
                 {
-                    @foreach (var c in Blockchain.GetMain().contracts.Values)
+                    @foreach (var c in bcMain.contracts.Values)
                     {
                         <option value="@c.ID">
                             [@c.ID] @c.Name [@c.Address]
@@ -180,7 +182,7 @@
     </p>
     @ctrSelected.Name
     <br>
-    @Blockchain.GetMain().id;
+    @bcMain.id;
     <br />
     </p>
 
@@ -219,6 +221,7 @@
 }
 @code
     {
+    Blockchain bcMain;
     AccountModel account;
     private Random r = new Random();
     private string bcURL = Blockchain.URLdefault;
@@ -271,7 +274,7 @@
             var acc = AccountModel.Find(accountSelected);
             if (acc != null)
             {
-                myWallet = await acc.GetOrCreateActualAddress(Blockchain.GetMain());
+                myWallet = await acc.GetOrCreateActualAddress(bcMain);
                 return myWallet;
             }
         }
@@ -285,7 +288,7 @@
 
     async Task<string> Unlock()
     {
-        var bc = Blockchain.GetMain();
+        var bc = bcMain;
         var ret = await bc.RunFunction("personal_unlockAccount", $"\"{bc.address}\",\"test_Password_212\",0");
         //address, passphrase, duration
         //{ "method": "personal_unlockAccount", "params": [string, string, number]}
@@ -294,23 +297,23 @@
 
     async Task ImportERC20()
     {
-        await Blockchain.GetMain().ImportERC20(tokenContract, myWallet);
+        await bcMain.ImportERC20(tokenContract, myWallet);
         //await Blockchain.GetMain().ImportERC20("0x413D9500A675d9b645034aC5f4325BF12ddeb7c1");
     }
 
     async Task TransferToken()
     {
-        await Blockchain.GetMain().TransferToken(Blockchain.GetMain().address, tokenContract, addressTo, tokenAmount);
+        await bcMain.TransferToken(bcMain.address, tokenContract, addressTo, tokenAmount);
     }
 
     async Task EstimateGas()
     {
-        gas = await Blockchain.GetMain().GetEstimatedGasContractAdd(ctrSelected.ByteCode);
+        gas = await bcMain.GetEstimatedGasContractAdd(ctrSelected.ByteCode);
     }
 
     async Task deleteContract()
     {
-        var main = Blockchain.GetMain();
+        var main = bcMain;
         if (main != null)
         {
             main.contracts.Remove(ctrSelected.ID);
@@ -352,7 +355,7 @@
         //function_processed = final + ")";
         //sha3 = await GetSHA3(function_processed);
         //getFiles();
-        function_processed = await Blockchain.GetMain().compileFunction(function1, false);
+        function_processed = await bcMain.compileFunction(function1, false);
 
         if (function1 != "()" && function1 != "")
             contractAddDisabled = "";
@@ -362,7 +365,7 @@
 
     async Task<string> GetSHA3(string code)
     {
-        var res = await Blockchain.GetMain().GetSHA3(code);
+        var res = await bcMain.GetSHA3(code);
         Console.WriteLine($"GetSHA3 {code} {res}");
         var ret = res.Substring(2, 8);
         return ret;
@@ -370,7 +373,7 @@
 
     async Task<string> GetSHA3_2()
     {
-        var res = await Blockchain.GetMain().GetSHA3(sha3);
+        var res = await bcMain.GetSHA3(sha3);
         Console.WriteLine($"GetSHA3 {res}");
         var ret = res.Substring(2, 8);
         return ret;
@@ -424,9 +427,9 @@
     private async Task Transfer50()
     {
         var acc = AccountModel.Find(accountSelected);
-        var bc = Blockchain.GetMain();
+        var bc = bcMain;
         var addr = await acc.GetOrCreateActualAddress(bc);
-        var res = await bc.SendTransaction(Blockchain.GetMain().address, addr, 50);
+        var res = await bc.SendTransaction(bcMain.address, addr, 50);
     }
 
     private async Task GetBalance()
@@ -437,16 +440,16 @@
             var acc = AccountModel.Find(accountSelected);
             if (acc != null)
             {
-                myWallet = await acc.GetOrCreateActualAddress(Blockchain.GetMain());
+                myWallet = await acc.GetOrCreateActualAddress(bcMain);
                 balance = await acc.GetBalance();
             }
         }
         else
         {
-            myWallet = Blockchain.GetMain().address;
-            balance = await Blockchain.GetMain().GetBalance();
+            myWallet = bcMain.address;
+            balance = await bcMain.GetBalance();
         }
-        await Blockchain.GetMain().GetBalanceToken("0xe5D682717955d6C35d465A3485625C64655a04f4", myWallet);
+        await bcMain.GetBalanceToken("0xe5D682717955d6C35d465A3485625C64655a04f4", myWallet);
     }
 
     //private async Task CreateBlockchainAccount(Blockchain bc, string pass)
@@ -476,12 +479,12 @@
     {
         if (Blockchain.loaded.Count > 0)
         {
-            var taddr = await Blockchain.GetMain().AddContract(newname, newcode, bytecode);
+            var taddr = await bcMain.AddContract(newname, newcode, bytecode);
             if (taddr.Length > 0 && taddr[0] != "")
             {
                 result = taddr[0].ToString();
                 //hidereceipt = "visible";
-                var caddr = await Blockchain.GetMain().GetReceipt(result, true);
+                var caddr = await bcMain.GetReceipt(result, true);
                 if (caddr != "")
                 {
                     result = "contractAddress: " + caddr;
@@ -503,21 +506,56 @@
 
     SmartContract GetContract(int id)
     {
-        if (Blockchain.GetMain().contracts.ContainsKey(id))
-            return Blockchain.GetMain().contracts[id];
-        else
-            return null;
+        if (bcMain != null)
+        {
+            if (bcMain.contracts.ContainsKey(id))
+                return bcMain.contracts[id];
+        }
+        return null;
     }
 
     protected override async Task OnInitializedAsync()
     {
         //Console.WriteLine($"Blazor is {Smart}");
-
-        account = AccountModel.Current;
         Console.WriteLine($"Blockchains OnInitializedAsync");
+        //account = AppData.CurrentAccount;
+        //var res = await storage.GetAsync<AccountModel>("acc");
+        account = await GetCurrentAcc();
+        //Console.WriteLine($"myFlag {myFlag.Value.Name}");
+
+        Console.WriteLine($"Blockchains account {account}");
+        bcMain = await account.GetSelectedBlockChain();
+        Console.WriteLine($"Blockchains OnInitializedAsync {bcMain}");
         await GetBalance();
     }
 
+    private async Task<AccountModel> GetCurrentAcc()
+    {
+        AccountModel account = new();
+
+        var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
+        var user = authState.User;
+
+        if (user.Identity.IsAuthenticated)
+        {
+            var currentUser = await UserManager.GetUserAsync(user);
+            account.UUID = currentUser.Id;
+            //account.Name = currentUser.UserName;
+            //account.Email = currentUser.Email;
+
+            var acc = AccountModel.Find(account.UUID);
+            if (acc != null)
+                account = acc;
+            ///tmp
+
+            //account.AccRole = Role.User;
+            return account;
+        }
+
+        return null;
+    }
+
+
     //private async Task GetBlockChain()
     //{
     //    //if (Blockchain.loaded.Count == 0)

+ 9 - 8
Pages/DocEdit.razor.cs

@@ -56,11 +56,12 @@ namespace HyperCube.Pages
             Console.WriteLine($"Verify starting");
             try
             {
-                VerifyContract verifyContract = SmartContract.Find("Verify", Blockchain.GetMain()) as VerifyContract;
+                var bc = await currentAcc.GetSelectedBlockChain();
+                VerifyContract verifyContract = SmartContract.Find("Verify", bc) as VerifyContract;
                 if (verifyContract != null)
                 {
                     Console.WriteLine($"VerifyContract found");
-                    transactionId = await verifyContract.Run(article);
+                    transactionId = await verifyContract.Run(currentAcc, article);
                     return transactionId;
                 }
                 else
@@ -103,7 +104,7 @@ namespace HyperCube.Pages
                 header = "Загрузка материала";
 
 
-            await InitializeAccount();
+            //await InitializeAccount();
 
             //int count = await articleModel.GetEditsCount();
             //int countbyid = await articleModel.GetEditsCount(currentAcc.UUID);
@@ -275,11 +276,11 @@ namespace HyperCube.Pages
             }
         }
 
-        public async Task InitializeAccount()
-        {
-            AccountModel.Current = await GetCurrentAcc();
-            Console.WriteLine("InitializeAccount in DocEdit " + AccountModel.Current.Name);
-        }
+        //public async Task InitializeAccount()
+        //{
+        //    AccountModel.Current = await GetCurrentAcc();
+        //    Console.WriteLine("InitializeAccount in DocEdit " + AccountModel.Current.Name);
+        //}
 
         private async Task<AccountModel> GetCurrentAcc()
         {

+ 1 - 1
Pages/Wallet.razor

@@ -42,7 +42,7 @@
             </tr>
             <tr>
                 <td>ETH Address:</td>
-                <td>@account.GetActualAddress(Blockchain.GetMain())</td>
+                <td>@address)</td>
             </tr>
             <tr>
                 <td>Balance:</td>

+ 8 - 3
Pages/Wallet.razor.cs

@@ -1,18 +1,23 @@
 using System.Threading.Tasks;
 using HyperCube.Models;
-using HyperCube;
+using Microsoft.AspNetCore.Components;
 
 namespace HyperCube.Pages
 {
     public partial class Wallet
     {
+        [Inject]
+        AppData AppData { get; set; }
         private AccountModel account = new();
         string myBalance = "";
+        string address = "";
 
         protected override async Task OnInitializedAsync()
         {
-            account = await GetCurrentAcc();
-            if (Blockchain.GetMain() != null)
+            account = AppData.CurrentAccount;
+            var bc = await account.GetSelectedBlockChain();
+            address = account.GetActualAddress(bc);
+            if (bc != null)
                 myBalance = await account.GetBalance();
         }
 

+ 2 - 3
Pages/WebAPI.razor

@@ -23,14 +23,13 @@
             var acc = AccountModel.FindByMail("valafar@mail.ru");
             if (acc != null)
             {
-                AccountModel.Current = acc;
                 Console.WriteLine("acc found "+acc.Name);
-                var bc = Blockchain.GetMain();
+                var bc = await acc.GetSelectedBlockChain();
                 if (bc != null)
                 {
                     //Console.WriteLine("bc found, Smart "+ Smart);
                     var addr = await acc.GetOrCreateActualAddress(bc);
-                    var res = await bc.SendTransaction(Blockchain.GetMain().address, addr, Smart);
+                    var res = await bc.SendTransaction(bc.address, addr, Smart);
                 }
                 else
                     Console.WriteLine("bc null ");

+ 32 - 2
Shared/MainLayout.razor

@@ -1,4 +1,5 @@
-@inherits LayoutComponentBase
+@using HyperCube.Models;
+@inherits LayoutComponentBase
 <AuthorizeView>
     <Authorized>
         <div class="wrap">
@@ -6,10 +7,39 @@
             <div class="main-content">
                 @Body
                 <Footer />
-            </div>    
+            </div>
         </div>
     </Authorized>
     <NotAuthorized>
         @Body
     </NotAuthorized>
 </AuthorizeView>
+
+@code {
+    List<string> Networks = new();
+    bool connected = false;
+
+    protected override async Task OnInitializedAsync()
+    {
+        //try
+        //{
+        //    //await Blockchain.GetInstance().Initialize();
+        //    Console.WriteLine("OnInitializedAsync RegisterNetworks");
+        //    await Blockchain.RegisterNetworks();
+        //    //if (Blockchain.Connected != "" && Blockchain.Connected != "none")
+        //    //{
+        //    //    connected = true;
+        //    //    Networks.Add(Blockchain.Connected);
+        //    //}
+        //    //else
+        //    //{
+        //    //    connected = false;
+        //    //    Networks.Add("Blockchain not connected");
+        //    //}
+        //}
+        //catch (Exception e)
+        //{
+        //    Console.WriteLine(e.Message + ", stack trace:" + e.StackTrace);
+        //}
+    }
+}

+ 13 - 3
Shared/Sidebar.razor.cs

@@ -6,12 +6,14 @@ using Microsoft.AspNetCore.Components.Authorization;
 using Microsoft.AspNetCore.Identity;
 using HyperCube.Pages;
 using HyperCube.Models;
-using Console = HyperCube.Utils.AdvConsole;
+using Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage;
 
 namespace HyperCube.Shared
 {
     public partial class Sidebar : ComponentBase
     {
+        [Inject]
+        ProtectedSessionStorage storage { get; set; }
         [Inject]
         NavigationManager NavigationManager { get; set; }
         [Inject]
@@ -28,10 +30,18 @@ namespace HyperCube.Shared
         ModalInfo modalError404 { get; set; }
         ModalLoading modalLoading { get; set; }
 
-        AccountModel _currentAccount;
+        AccountModel _currentAccount;        
 
         protected override async Task OnInitializedAsync()
-        {
+        {            
+            var acc = await GetCurrentAcc();
+            Console.WriteLine($"sidebar myFlag set1 {acc.Name}");
+            //AppData.CurrentAccount = acc;
+            await storage.SetAsync("acc", acc.Email);
+
+            var myFlag = await storage.GetAsync<string>("acc");
+            Console.WriteLine($"sidebar myFlag set {myFlag.Value}");
+            await storage.SetAsync("completed", true);
         }
 
         async Task ProfileClick()

+ 9 - 1
Startup.cs

@@ -24,7 +24,15 @@ namespace HyperCube
         {
             Configuration = configuration;
             Models.AccountModel.InitializeAccounts();
-            //Models.ArticleModel.LoadArticles();
+            try
+            {
+                Console.WriteLine("OnInitializedAsync RegisterNetworks");
+                Models.Blockchain.RegisterNetworks();
+            }
+            catch (Exception e)
+            {
+                Console.WriteLine(e.Message + ", stack trace:" + e.StackTrace);
+            }
         }
 
         public IConfiguration Configuration { get; }