|
@@ -41,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
|
|
@@ -90,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))
|
|
@@ -508,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
|
|
@@ -538,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();
|