Sfoglia il codice sorgente

фиксы параметров контракта

Rimmon 4 anni fa
parent
commit
5d14988f48
4 ha cambiato i file con 57 aggiunte e 30 eliminazioni
  1. 13 10
      Models/Blockchain.cs
  2. 8 8
      Models/SmartContract.cs
  3. 36 11
      Pages/Blockchains.razor
  4. 0 1
      Pages/_Host.cshtml

+ 13 - 10
Models/Blockchain.cs

@@ -49,12 +49,13 @@ namespace HyperCube.Models
             return "0x" + hex;
         }
 
-        public static string zerofill(string hex, int byteCount, bool hexPrefix0x)
+        public static string zerofill(string hex, int charCount, bool hexPrefix0x)
         {
             if (hexPrefix0x)
                 hex = hex.Remove(0, 2);
-            var res = hex.PadRight(byteCount, '0');
-            Console.WriteLine($"zerofill input {hex} out {res}");
+            Console.WriteLine($"zerofill input {hex} count {hex.Length}");
+            var res = hex.PadLeft(charCount, '0');
+            Console.WriteLine($"zerofill out {hex} count {res.Length}");
             return res;
         }
 
@@ -172,8 +173,6 @@ namespace HyperCube.Models
 
         public async Task<object[]> AddContract(string name, string code, string bytecode)
         {
-            int id = (int)MySQLConnector.Instance().SQLInsert($"insert into smart_contracts (code, bytecode, name, date_add) values ('{code}','{bytecode}','{name}',NOW())");
-
             Console.WriteLine("bytecode " + bytecode);
             var req = $"{{ \"jsonrpc\":\"2.0\",\"method\":\"eth_sendTransaction\",\"params\":[{{\"from\":\"{address}\",\"gas\":\"0x31b2e\", \"data\":\"{bytecode}\"}}], \"id\":1}}";
 
@@ -181,11 +180,15 @@ namespace HyperCube.Models
             dynamic jsonDe = JsonConvert.DeserializeObject(answer);
             var res = jsonDe.result;
             Console.WriteLine("result AddContract transactionAddress: " + res);
-
-            SmartContract newctr = new SmartContract(id, name, code, bytecode);
-            contracts.Add(id, newctr);
-            contractNames.Add(name, newctr);
-            return new object[]{ res, newctr };
+            if (res != null)
+            {
+                int id = (int)MySQLConnector.Instance().SQLInsert($"insert into smart_contracts (code, bytecode, name, date_add) values ('{code}','{bytecode}','{name}',NOW())");
+                SmartContract newctr = new SmartContract(id, name, code, bytecode);
+                contracts.Add(id, newctr);
+                contractNames.Add(name, newctr);
+                return new object[] { res, newctr };
+            }
+            return null;
         }
 
         public async Task<string> ListAccounts()

+ 8 - 8
Models/SmartContract.cs

@@ -57,7 +57,6 @@ namespace HyperCube.Models
                     functionId = Convert.ToInt32(ret[0]["id"]);
                     functionName = ret[0]["name_with_args"].ToString();
                     functionCompiledHeader = ret[0]["compiled_header"].ToString();
-                    functionCompiledHeader = Blockchain.zerofill(functionCompiledHeader, 32, false);
                     Console.WriteLine($"{ID} LoadFunction {functionId} name {functionName} header {functionCompiledHeader}");
                 }
             }
@@ -77,19 +76,20 @@ namespace HyperCube.Models
         public async Task Run(ArticleModel newArticle, string weiValue = "0x0")
         {
             var uuid = await newArticle.GetInitiatorUUID();
-            Console.WriteLine($"Current {AccountModel.Current.Email}");
-            var verifier_address = AccountModel.Current.eth_address.Remove(0, 2);
+            var verifier_address = AccountModel.Current.eth_address;
 
             var initiator = AccountModel.Find(uuid);
-            var initiator_address = initiator.eth_address.Remove(0, 2);
+            var initiator_address = initiator.eth_address;
             var article_value = (int)newArticle.Rating;
             
-            var article_value_hex = article_value.ToString("X32");
-            Console.WriteLine($"article_value {article_value} hex {article_value_hex}");
+            var article_value_hex = article_value.ToString("X64");
+            //Console.WriteLine($"article_value {article_value} hex {article_value_hex}");
             var edits = await newArticle.GetEditsCount();
-            var edits_hex = edits.ToString("X32");
+            var edits_hex = edits.ToString("X64");
+            verifier_address = Blockchain.zerofill(verifier_address, 64, true);
+            initiator_address = Blockchain.zerofill(initiator_address, 64, true);
 
-            Console.WriteLine($"edits {edits} hex {edits_hex}");
+            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}");
             //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}");

File diff suppressed because it is too large
+ 36 - 11
Pages/Blockchains.razor


+ 0 - 1
Pages/_Host.cshtml

@@ -34,6 +34,5 @@
     </div>
 
     <script src="_framework/blazor.server.js"></script>
-    <script src="_content/Radzen.Blazor/Radzen.Blazor.js"></script>
 </body>
 </html>