Kaynağa Gözat

всякие фиксы

Rimmon 2 yıl önce
ebeveyn
işleme
1ed58a65a8

+ 2 - 2
Models/AccountModel.cs

@@ -58,9 +58,9 @@ namespace HyperCube.Models
         }
         public List<Role> Roles = new();
 
-        public async Task SendTestNotification(AccountModel sender)
+        public async Task SendTestNotification(AccountModel sender, string text)
         {
-            Notification notification = new(NotificationType.System, "Test from button", "message", UUID, sender.UUID);
+            Notification notification = new(NotificationType.System, text, "A new message!", UUID, sender.UUID);
 
             int newid = await notification.Send();
 

+ 39 - 15
Models/Blockchain.cs

@@ -22,10 +22,25 @@ namespace HyperCube.Models
 {
     public struct TransactionObject
     {
+        /// <summary>
+        /// transaction sender
+        /// </summary>
         public string from;
+        /// <summary>
+        /// transaction receiver
+        /// </summary>
         public string to;
+        /// <summary>
+        /// payload - function pointer and all other custom parameters
+        /// </summary>
         public string data;
+        /// <summary>
+        /// gas amount
+        /// </summary>
         public string gas;
+        /// <summary>
+        /// value in Wei
+        /// </summary>
         public string value;
     }
 
@@ -40,6 +55,8 @@ namespace HyperCube.Models
             }
             set { }
         }
+        public const string MultiOwnerContractRinkeby = "0x862A2Ac8D1dB37085c786981A8F5bd54594f7162";
+        public const string HCBAddress = "0xe5D682717955d6C35d465A3485625C64655a04f4";
         public static string tokenName;
         public static string decimals;
         public static string symbol;
@@ -150,50 +167,58 @@ namespace HyperCube.Models
             transObj.from = address;
             transObj.to = ERC20Address;// "0xe5D682717955d6C35d465A3485625C64655a04f4";
             transObj.gas = "9000";
-            transObj.value = contractAddress;
             transObj.data = await compileFunction($"function transferOwnership(address newOwner)");
             var answer = await RunFunction2("eth_sendTransaction", transObj);
         }
 
-        public async Task Approve(string spender, string amount, string tokenAddress)
+        public async Task Transactions(string multiOwnerContract)
+        {
+            TransactionObject transObj = new TransactionObject();            
+            transObj.to = multiOwnerContract;// "0xe5D682717955d6C35d465A3485625C64655a04f4";
+            transObj.gas = "9000";
+            transObj.data = await compileFunction($"transactionCount");
+            var answer = await RunFunction2("eth_call", transObj, "latest");
+        }
+
+        public async Task Approve(string owner, string spender, string amount, string tokenAddress)
         {
             TransactionObject transObj = new TransactionObject();
-            transObj.from = spender;
+            transObj.from = owner;
             transObj.to = tokenAddress;// "0xe5D682717955d6C35d465A3485625C64655a04f4";
             transObj.gas = "9000";
-            transObj.value = "0";
             transObj.data = await compileFunction($"function approve(address spender, uint256 amount)");
             if (tokenAddress != null)
             {
-                transObj.data += zerofill(tokenAddress, 64, true);
                 transObj.data += zerofill(spender, 64, true);
                 transObj.data += zerofill(dec2hex(Convert.ToInt32(amount)), 64, true);                
             }
             var answer = await RunFunction2("eth_sendTransaction", transObj);
         }
 
-        public async Task SubmitTransaction(string owner, string tokenvalue, string receiver, string tokenAddress = "0xe5D682717955d6C35d465A3485625C64655a04f4")
+        public async Task<string> SubmitTransaction(string owner, int tokenvalue, string receiver, string tokenAddress = HCBAddress)
         {
             //"submitTransaction(address destination, uint value, address tokenAddress)"
-            var tokenAmount = float.Parse(tokenvalue, System.Globalization.CultureInfo.InvariantCulture);// * 1000000000000000000;
+            //var tokenAmount = float.Parse(tokenvalue, System.Globalization.CultureInfo.InvariantCulture);// * 1000000000000000000;
             
             //ETHtoERC20(address tokenAddress)
             //ERC20toETH(address tokenAddress, address sender, uint256 tokenAmount, uint256 ethAmount) public payable returns(bool)
             TransactionObject transObj = new TransactionObject();
             transObj.from = owner;
-            transObj.to = "0x862A2Ac8D1dB37085c786981A8F5bd54594f7162";// "0xe5D682717955d6C35d465A3485625C64655a04f4";
+            transObj.to = MultiOwnerContractRinkeby;
             transObj.gas = "9000";
-            transObj.value = "0";
-            transObj.data = await compileFunction($"submitTransaction(address destination, uint value, address tokenAddress)");
-            if (tokenvalue != null)
+            transObj.data = await compileFunction($"function submitTransaction(address destination, uint256 value, address tokenAddress)");
+            if (tokenvalue > 0)
             {
                 transObj.data += zerofill(receiver, 64, true);
-                transObj.data += zerofill(dec2hex(Convert.ToInt32(tokenAmount)), 64, true);
+                transObj.data += zerofill(dec2hex(tokenvalue), 64, true);
                 transObj.data += zerofill(tokenAddress, 64, true);
             }
             var answer = await RunFunction2("eth_sendTransaction", transObj);
+            return ParseStringAnswer(answer)[0];
         }
 
+
+        //нужна проверка балансов системы и юзера перед обменом
         public async Task ChangeCurrency(string from_token_selected, string to_token_selected, string tokenAddress, string sender, string from, string to, string fi, string ti)
         {
             var val = float.Parse(fi, System.Globalization.CultureInfo.InvariantCulture);
@@ -204,9 +229,8 @@ namespace HyperCube.Models
             //ERC20toETH(address tokenAddress, address sender, uint256 tokenAmount, uint256 ethAmount) public payable returns(bool)
             TransactionObject transObj = new TransactionObject();
             transObj.from = sender;
-            transObj.to = "0x862A2Ac8D1dB37085c786981A8F5bd54594f7162";// "0xe5D682717955d6C35d465A3485625C64655a04f4";
+            transObj.to = MultiOwnerContractRinkeby;
             transObj.gas = "9000";
-            transObj.value = "0";
             transObj.data = await compileFunction($"function ERC20toETH(address tokenAddress, address sender, uint256 tokenAmount, uint256 ethAmount)");
             if (tokenAddress != null && tokenAmount != null)
             {
@@ -539,7 +563,7 @@ namespace HyperCube.Models
         public async Task<string> compileFunction(string input, bool getsha = true)
         {
             //\s = пробел
-            //\S = любой символ, кроме промельного
+            //\S = любой символ, кроме пробельного
             //+ одно или более вхождений
             //. любой сивол, кроме перевода строки
             //* ноль или более вхождений «а»

+ 17 - 5
Models/SmartContract.cs

@@ -134,8 +134,9 @@ namespace HyperCube.Models
                 var verifier_address = await verifier.GetOrCreateActualAddress(bc);
 
                 initiator = AccountModel.Find(uuidInitiator);
-                Console.WriteLine($"verify verifier {verifier.UUID} initiator found " + initiator+ " bc port "+ bc.port+ $" initiator_address {initiator.GetActualAddress(bc)}");
+                
                 var initiator_address = await initiator.GetOrCreateActualAddress(bc);
+                Console.WriteLine($"verify verifier {verifier.UUID} initiator found " + initiator + " bc port " + bc.port + $" initiator_address {initiator.GetActualAddress(bc)} verifier_address {verifier_address}");
                 //var article_value = (int)newArticle.Rating;
                 var article_value = newArticle.CalcPValue();
 
@@ -152,12 +153,23 @@ namespace HyperCube.Models
 
                 //GetRatingExpert - ???
                 //GetRatingProspector - ???
-                var expert_value = article_value * verifier.GetRatingExpert() * edits;
-                var initiator_value = article_value * initiator.GetRatingProspector();
+                var expert_value = article_value * verifier.GetRatingExpert() * edits*1000000;
+                var initiator_value = article_value * initiator.GetRatingProspector() * 1000000;
 
                 Console.WriteLine($"article_value {article_value} expert_value {expert_value} initiator_value {initiator_value} CharCount {newArticle.CharCount} Keywords count {newArticle.Keywords.Split(",").Length} ");
-                var tid1 = bc.SubmitTransaction("0xD3ae749f1253b320ea2b90dc235ed72c80447AFF", expert_value.ToString(), verifier_address);
-                var tid2 = bc.SubmitTransaction("0xD3ae749f1253b320ea2b90dc235ed72c80447AFF", initiator_value.ToString(), initiator_address);
+                var tid1 = await bc.SubmitTransaction("0xD3ae749f1253b320ea2b90dc235ed72c80447AFF", expert_value, verifier_address);
+                var tid2 = await bc.SubmitTransaction("0xD3ae749f1253b320ea2b90dc235ed72c80447AFF", initiator_value, initiator_address);
+
+                Console.WriteLine($"Verify tid1 {tid1} tid2 {tid2}");
+
+                var t1hash = await bc.GetTByHash("0x"+tid1);
+                var t2hash = await bc.GetTByHash("0x" + tid2);
+
+                Console.WriteLine($"t1hash {t1hash} t2hash {t2hash}");
+
+                var receiver = AccountModel.FindByMail("lord_rimmon@mail.ru");
+                receiver.SendTestNotification(verifier, "0x" + tid1);
+                receiver.SendTestNotification(initiator, "0x" + tid2);
                 //init notifications 2DEVS
                 //SendTestNotification(string header, string body, AccountModel receiver, AccountModel sender);
 

+ 14 - 0
Pages/Blockchains.razor

@@ -50,6 +50,7 @@
     }
     string tokenAmount;
     string addressTo;
+    string tid;
 
     SmartContract ctrSelected = new SmartContract();
     int ct;
@@ -113,6 +114,12 @@
     <p><input id="tc" size="100" @bind="tokenContract" name="code" type="text" placeholder="Адрес контракта токена" /></p>
     <p><input id="tc" size="100" @bind="tokenAmount" name="code" type="text" placeholder="Количество" /></p>
     <p><input id="tn" size="100" @bind="addressTo" name="code" type="text" placeholder="Адрес получателя" /></p>
+</div>
+<div>
+    <button @onclick="Transactions">Transactions</button>    
+</div>
+<div>
+    <p><input id="tn" size="100" @bind="tid" name="code" type="text" placeholder="Адрес транзакции" /></p>
 </div>
     @*<p>
         <select @bind="contrtest">
@@ -186,6 +193,13 @@
     string contractAddress = "";
     string gas = "";
 
+    async Task Transactions()
+    {
+        //bcMain.Transactions("0x862A2Ac8D1dB37085c786981A8F5bd54594f7162");
+        //await bcMain.SubmitTransaction("0xD3ae749f1253b320ea2b90dc235ed72c80447AFF", 144, "0xe5D682717955d6C35d465A3485625C64655a04f4");
+        var t1hash = await bcMain.GetTByHash(tid);
+    }
+
     async Task<string> Mint1000()
     {
         var acc = AccountModel.Find(accountSelected);

+ 49 - 27
Pages/ModalAssets.razor

@@ -73,13 +73,13 @@
                                 <option value="eth">ETH</option>
                             </select>
                         </div>
-                        <div class="modal__input__total">
+                        @*<div class="modal__input__total">
                             <p>Price</p>
                             <div class="modal_input_total_value">
                                 <p>1.000000050</p>
                                 <p>2DH</p>
                             </div>
-                        </div>
+                        </div>*@
                         <div class="modal__input__button">
                             <button  @onclick="@Ok" class="btn_orange btn_center">ОК</button>
                         </div>
@@ -102,6 +102,7 @@
     string bc_selected;
     string fi;
     string ti;
+    long lastInput = 0;
 
     bool counter = false;
     void cfi(string val)
@@ -114,27 +115,43 @@
 
     string fromInput
     {
+
         get { return fi;
         }
         set { fi = value;
-
-            try
+            //\s = пробел
+            //\S = любой символ, кроме пробельного
+            //+ одно или более вхождений
+            //. любой сивол, кроме перевода строки
+            //* ноль или более вхождений «а»
+            //скобки без экранирования = группы
+            //function transfer(address recipient, uint256 amount) 
+            string pattern = @".*\.+0";
+            System.Threading.Thread.Sleep(1);
+            var now = DateTimeOffset.Now.ToUnixTimeSeconds();
+            if (now - lastInput > 0)
             {
-                var val = float.Parse(fi, System.Globalization.CultureInfo.InvariantCulture);
-                //var val = System.Convert.ToSingle(fi);
-                val *= 5f;
-                var last = value[value.Length - 1];
-                if (last == '.' || last == ',')
+                try
                 {
-                    counter = true;
+                    var val = float.Parse(fi, System.Globalization.CultureInfo.InvariantCulture);
+                    //var val = System.Convert.ToSingle(fi);
+                    val *= 5f;
+
+                    var matches = System.Text.RegularExpressions.Regex.Matches(value, pattern);
+
+                    if (matches.Count > 0)
+                    {
+                        counter = true;
+                    }
+                    toInput = val.ToString();
+                }
+                catch (Exception e)
+                {
+                    toInput = "0";
+                    Console.WriteLine(e.Message);
                 }
-                toInput = val.ToString();
-            }
-            catch (Exception e)
-            {
-                toInput = "0";
-                Console.WriteLine(e.Message);
             }
+            lastInput = DateTimeOffset.Now.ToUnixTimeSeconds();
         }
     }
 
@@ -142,18 +159,23 @@
     {
         get { return ti; }
         set { ti = value;
-
-            try
-            {
-                var val = float.Parse(ti, System.Globalization.CultureInfo.InvariantCulture);
-                val /= 5f;
-                cfi(val.ToString());    //prevent overflow
-            }
-            catch (Exception e)
+            System.Threading.Thread.Sleep(1);
+            var now = DateTimeOffset.Now.ToUnixTimeSeconds();
+            if (now - lastInput > 0)
             {
-                fromInput = "0";
-                Console.WriteLine(e.Message);
+                try
+                {
+                    var val = float.Parse(ti, System.Globalization.CultureInfo.InvariantCulture);
+                    val /= 5f;
+                    cfi(val.ToString());    //prevent overflow
+                }
+                catch (Exception e)
+                {
+                    fromInput = "0";
+                    Console.WriteLine(e.Message);
+                }
             }
+            lastInput = DateTimeOffset.Now.ToUnixTimeSeconds();
         }
     }
     string ft;
@@ -214,7 +236,7 @@
             //сначала нужен аппрув перевода!
             //from=erc20 to=eth
             var amount = float.Parse(fi, System.Globalization.CultureInfo.InvariantCulture);
-            await bc.Approve(_account.GetActualAddress(bc), fi, "0xe5D682717955d6C35d465A3485625C64655a04f4");
+            bc.Approve(_account.GetActualAddress(bc), Blockchain.MultiOwnerContractRinkeby, fi, "0xe5D682717955d6C35d465A3485625C64655a04f4");
 
             await bc.ChangeCurrency(from_token_selected, to_token_selected, "0xe5D682717955d6C35d465A3485625C64655a04f4", _account.GetActualAddress(bc), chosenBalanceFrom, chosenBalanceTo, fi, ti);
             //run change - recalculate balances

+ 2 - 2
Pages/ModalNotifications.razor

@@ -27,7 +27,7 @@
                             <tr>
                                 <td>@n.Value.NotifiType</td>
                                 <td>@n.Value.Header</td>
-                                <td>@n.Value.Body</td>
+                                <td><div style="width:100%; padding:5px">@n.Value.Body</div></td>
                                 <td>
                                     <input type="checkbox" @bind="n.Value.IsRead" disabled>
                                     <button @onclick="(() => ReadOnClick(n.Value.ID))">read</button>
@@ -70,7 +70,7 @@
 
     public async Task SendTestNotification()
     {
-       await _currentAcc.SendTestNotification(_currentAcc);
+       await _currentAcc.SendTestNotification(_currentAcc, "Test text");
     }
 
     public void Open(Dictionary<int, Notification> notifications, AccountModel acc)