Переглянути джерело

рабочее скачивание private key

Rimmon 3 роки тому
батько
коміт
4d87cdd98f
3 змінених файлів з 30 додано та 12 видалено
  1. 13 2
      Pages/Blockchains.razor
  2. 13 4
      Pages/Blockchains.razor.cs
  3. 4 6
      wwwroot/js/getfile.js

+ 13 - 2
Pages/Blockchains.razor

@@ -226,7 +226,18 @@
 
     async Task<string> Dload()
     {
-        return await JsRuntime.InvokeAsync<string>("test");
+        //string filepath = @"c:\Users\Администратор\AppData\Local\Ethereum\rinkeby\keystore\
+        if (accountSelected != "" && accountSelected != null && accountSelected != "0")
+        {
+            var acc = AccountModel.Find(accountSelected);
+            if (acc != null)
+            {
+                myWallet = await acc.GetOrCreateActualAddress(Blockchain.GetMain());
+                string text = getFiles(myWallet);
+                return await JsRuntime.InvokeAsync<string>("test", text);
+            }
+        }
+        return "";
     }
 
 
@@ -302,7 +313,7 @@
         //}
         //function_processed = final + ")";
         //sha3 = await GetSHA3(function_processed);
-        getFiles();
+        //getFiles();
         function_processed = await Blockchain.GetMain().compileFunction(function1, false);
 
         if (function1 != "()" && function1 != "")

+ 13 - 4
Pages/Blockchains.razor.cs

@@ -3,6 +3,7 @@ using System.Threading.Tasks;
 using System.Net;
 using System.IO;
 
+
 using Microsoft.AspNetCore.Components;
 
 namespace HyperCube.Pages
@@ -22,19 +23,27 @@ namespace HyperCube.Pages
         
         //public string mypath = @"Wallet";
         public string mypath = @"getfile";
-        public string getFiles()
+        public string getFiles(string wallet)
         {
-            //mypath = @"c:\Users\Администратор\AppData\Local\Ethereum\rinkeby\keystore\";
+            mypath = @"c:\Users\Администратор\AppData\Local\Ethereum\rinkeby\keystore\";
+            //string filepath = @"c:\Users\Администратор\AppData\Local\Ethereum\rinkeby\keystore\UTC--2021-04-21T07-20-25.392048000Z--1841462ee3e39af00de42b067853c58ab7e18876";
+            //text = File.ReadAllText(filepath);
             string toprint = "";
             var files = Directory.GetFiles(mypath);
 
             foreach (var file in files)
             {
                 string fileName = file.Substring(mypath.Length + 1);
-                //var name = fileName.Split("_");
+                var name = fileName.Split("--");
                 try
                 {
-                    Console.WriteLine($"fileName {fileName}");
+                    var filepath = mypath + file;                    
+                    if ("0x" + name[2] == wallet)
+                    {
+                        var content = File.ReadAllText(file);
+                        Console.WriteLine($"fileName {name[2]} path {filepath} {"0x" + name[2] == wallet} first {content[0]}");
+                        return content;
+                    }                    
                     //uint fileTaskId = Convert.ToUInt32(name[0]);
                     //if (fileTaskId == taskid)
                     //{

+ 4 - 6
wwwroot/js/getfile.js

@@ -1,7 +1,7 @@
-function test()
+function test(text)
 {
-    alert("Testing private key export!!");
-    download("GFG.json", "Test private keystore");
+    //alert("Testing private key export!!");
+    download("GFG.json", text);
     return "111";
 }
 
@@ -9,9 +9,7 @@ function download(file, text) {
 
     //creating an invisible element
     var element = document.createElement('a');
-    element.setAttribute('href',
-        'data:text/plain;charset=utf-8, '
-        + encodeURIComponent(text));
+    element.setAttribute('href','data:text/plain;charset=utf-8,'+encodeURIComponent(text));
     element.setAttribute('download', file);
 
     // Above code is equivalent to