Rimmon 3 éve
szülő
commit
3f0ac397fa
1 módosított fájl, 19 hozzáadás és 1 törlés
  1. 19 1
      Models/Blockchain.cs

+ 19 - 1
Models/Blockchain.cs

@@ -593,6 +593,24 @@ namespace HyperCube.Models
             var answer = await RunFunction2("eth_sendTransaction", transObj);
         }
 
+
+        //approve transfer amount from sender by contract to any address: approve(address spender, uint256 amount)
+        public async Task ApproveExchange(string tokenContract, AccountModel owner, AccountModel spender, string tokenAmount)
+        {
+            TransactionObject transObj = new TransactionObject();
+            transObj.from = owner.GetActualAddress(this);
+            transObj.to = tokenContract;
+            transObj.gas = "9000";
+            transObj.value = tokenAmount;   //тут должен быть эфир!
+            transObj.data = await compileFunction($"function approve(address spender, uint256 amount)");
+            if (tokenContract != null && tokenAmount != null)
+            {
+                transObj.data += zerofill(spender.GetActualAddress(this), 64, true);
+                transObj.data += zerofill(dec2hex(Convert.ToInt32(tokenAmount)), 64, true);
+            }
+            var answer = await RunFunction2("eth_sendTransaction", transObj);
+        }
+
         public async Task TransferToken(string sender, string tokenContract, string addressTo, string tokenAmount)
         {
             //transfer(address recipient, uint256 amount)
@@ -600,7 +618,7 @@ namespace HyperCube.Models
             transObj.from = sender;
             transObj.to = tokenContract;
             transObj.gas = "9000";
-            transObj.value = tokenAmount;
+            transObj.value = tokenAmount;   //тут должен быть эфир!
             transObj.data = await compileFunction($"function transfer(address recipient, uint256 amount)");
             if (addressTo != null && tokenAmount != null)
             {