|
@@ -1,11 +1,16 @@
|
|
|
using System;
|
|
|
+using System.Diagnostics;
|
|
|
using System.Text;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
|
+using System.Drawing;
|
|
|
+using System.Drawing.Imaging;
|
|
|
using System.Threading.Tasks;
|
|
|
using Newtonsoft.Json;
|
|
|
using Console = HyperCube.Utils.AdvConsole;
|
|
|
using System.Text.RegularExpressions;
|
|
|
+using QRCoder;
|
|
|
+using System.IO;
|
|
|
|
|
|
//0xe5D682717955d6C35d465A3485625C64655a04f4 - HCB in rinkeby
|
|
|
//0xb504ba124b74333d8536db534f7fcdc174d6ee3d - system address rinkeby
|
|
@@ -36,6 +41,7 @@ namespace HyperCube.Models
|
|
|
public static string decimals;
|
|
|
public static string symbol;
|
|
|
public static string tokenBalance;
|
|
|
+ public static string balanceHCB;
|
|
|
|
|
|
public static Dictionary<int, Blockchain> supported;
|
|
|
public static string Connected
|
|
@@ -85,6 +91,40 @@ namespace HyperCube.Models
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ public async Task<string> GetBalanceToken(string contractAddress, string address)
|
|
|
+ {
|
|
|
+ TransactionObject transObj = new TransactionObject();
|
|
|
+ transObj.to = contractAddress;
|
|
|
+
|
|
|
+ //compile data
|
|
|
+ //to.data = await compileFunction("decimals");
|
|
|
+ //transObj.data = await compileFunction("name");
|
|
|
+ //var answer = await RunFunction2("eth_call", transObj, "latest");
|
|
|
+ ////Console.WriteLine("ImportERC20 len "+ answer.Length + " answer " + answer);
|
|
|
+ //var parsed = ParseStringAnswer(answer);
|
|
|
+ //int tokenlen = hex2dec(parsed[1]);
|
|
|
+ //tokenName = HextoString(parsed[2]).Substring(0, tokenlen);
|
|
|
+ //to.data = await compileFunction("balanceOf(address)");
|
|
|
+ transObj.data = await compileFunction("symbol");
|
|
|
+ var answer = await RunFunction2("eth_call", transObj, "latest");
|
|
|
+ var parsed = ParseStringAnswer(answer);
|
|
|
+ int symlen = hex2dec(parsed[1]);
|
|
|
+ symbol = HextoString(parsed[2]).Substring(0, symlen);
|
|
|
+ //Console.WriteLine("ImportERC20 len " + answer.Length + " answer " + answer);
|
|
|
+ transObj.data = await compileFunction("decimals");
|
|
|
+ answer = await RunFunction2("eth_call", transObj, "latest");
|
|
|
+ decimals = hex2dec(ParseStringAnswer(answer)[0]).ToString();
|
|
|
+
|
|
|
+ transObj.data = await compileFunction($"function balanceOf(address account)");
|
|
|
+ if (address != null)
|
|
|
+ transObj.data += zerofill(address, 64, true);
|
|
|
+ //answer = await RunFunction2("eth_call", to, AccountModel.Current.GetActualAddress(this));
|
|
|
+ answer = await RunFunction2("eth_call", transObj, "latest");
|
|
|
+ balanceHCB = ((double)AccountModel.ConvertBalance(ParseStringAnswer(answer)[0]) / 1000000000000000000.0).ToString();
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
public async Task<string> Initialize()
|
|
|
{
|
|
|
if (!loaded.ContainsKey(id))
|
|
@@ -331,6 +371,70 @@ namespace HyperCube.Models
|
|
|
//return "test answer";
|
|
|
}
|
|
|
|
|
|
+ public static string QRtest(string input)
|
|
|
+ {
|
|
|
+ QRCodeGenerator qrGenerator = new QRCodeGenerator();
|
|
|
+ QRCodeData qrCodeData = qrGenerator.CreateQrCode(input, QRCodeGenerator.ECCLevel.Q);
|
|
|
+ QRCode qrCode = new QRCode(qrCodeData);
|
|
|
+ Bitmap qrCodeImage = qrCode.GetGraphic(7);
|
|
|
+ //Image img = qrCodeImage;
|
|
|
+
|
|
|
+ MemoryStream ms = new MemoryStream();
|
|
|
+ BinaryWriter bw = new BinaryWriter(ms);
|
|
|
+ //var fulltexname = Encoding.UTF8.GetBytes("http://" + myHostName + "/" + filename);
|
|
|
+
|
|
|
+ //bw.Write(loc_id);
|
|
|
+ //bw.Write(fulltexname);
|
|
|
+
|
|
|
+
|
|
|
+ //return base64String;
|
|
|
+ qrCodeImage.Save(ms, ImageFormat.Png);
|
|
|
+ byte[] imageBytes = ms.ToArray();
|
|
|
+ string base64String = Convert.ToBase64String(imageBytes);
|
|
|
+ Console.WriteLine($"base64String {base64String}");
|
|
|
+ return base64String;
|
|
|
+ //Image.FromStream(ms);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static List<string> ExecuteCommand(string cmd)
|
|
|
+ {
|
|
|
+ List<string> output = new List<string>();
|
|
|
+ var processInfo = new ProcessStartInfo(@"e:\www\nodejs\test.bat", cmd );
|
|
|
+ processInfo.CreateNoWindow = true;
|
|
|
+ processInfo.UseShellExecute = false;
|
|
|
+ processInfo.RedirectStandardError = true;
|
|
|
+ processInfo.RedirectStandardOutput = true;
|
|
|
+
|
|
|
+ var process = Process.Start(processInfo);
|
|
|
+
|
|
|
+ process.OutputDataReceived += (object sender, DataReceivedEventArgs e) => Echo(e.Data, ref output);
|
|
|
+ process.BeginOutputReadLine();
|
|
|
+
|
|
|
+ process.ErrorDataReceived += (object sender, DataReceivedEventArgs e) =>
|
|
|
+ Console.WriteLine("error>>" + e.Data);
|
|
|
+ process.BeginErrorReadLine();
|
|
|
+
|
|
|
+ process.WaitForExit();
|
|
|
+
|
|
|
+ Console.WriteLine($"ExitCode: {process.ExitCode}");
|
|
|
+ num = 0;
|
|
|
+ process.Close();
|
|
|
+ return output;
|
|
|
+ }
|
|
|
+
|
|
|
+ static int num = 0;
|
|
|
+
|
|
|
+ static void Echo(string msg, ref List<string> output)
|
|
|
+ {
|
|
|
+ //if (num > 0)
|
|
|
+ if (msg != null && msg.Length > 0)
|
|
|
+ {
|
|
|
+ Console.WriteLine("output >>" + msg);
|
|
|
+ output.Add(msg);
|
|
|
+ }
|
|
|
+ num++;
|
|
|
+ }
|
|
|
+
|
|
|
async Task<string> mySHA3(string code)
|
|
|
{
|
|
|
var res = await GetSHA3(code);
|
|
@@ -439,8 +543,9 @@ namespace HyperCube.Models
|
|
|
var answer = await RunFunction2("eth_sendTransaction", transObj);
|
|
|
}
|
|
|
|
|
|
- public async Task ImportERC20(string contractAddress)
|
|
|
+ public async Task ImportERC20(string contractAddress, string importAddress)
|
|
|
{
|
|
|
+ //"0xb504ba124b74333D8536DB534F7fcdC174d6Ee3d"
|
|
|
//var gbh = await GetTByHash("0x00bdbf1571aa69a2cf8c8c7913a01eaca3a4b7e5e7e49fc787cb81c0df2c2682");
|
|
|
//Console.WriteLine("GetTByHash " + gbh );
|
|
|
//runfunction balanceOf totalSupply symbol name
|
|
@@ -469,7 +574,7 @@ namespace HyperCube.Models
|
|
|
|
|
|
transObj.data = await compileFunction($"function balanceOf(address account)");
|
|
|
if (address != null)
|
|
|
- transObj.data += zerofill("0xb504ba124b74333D8536DB534F7fcdC174d6Ee3d", 64, true);
|
|
|
+ transObj.data += zerofill(importAddress, 64, true);
|
|
|
//answer = await RunFunction2("eth_call", to, AccountModel.Current.GetActualAddress(this));
|
|
|
answer = await RunFunction2("eth_call", transObj, "latest");
|
|
|
tokenBalance = ((double)AccountModel.ConvertBalance(ParseStringAnswer(answer)[0]) / 1000000000000000000.0).ToString();
|