|
@@ -20,13 +20,12 @@ namespace HyperCube.Models
|
|
return "none";
|
|
return "none";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- public static int selectedId;
|
|
|
|
public static string URLdefault = "127.0.0.1";
|
|
public static string URLdefault = "127.0.0.1";
|
|
//public static int defaultPort = 8545;
|
|
//public static int defaultPort = 8545;
|
|
public static int defaultPort = 8666;
|
|
public static int defaultPort = 8666;
|
|
public static string defaultName = "Ethereum dev network";
|
|
public static string defaultName = "Ethereum dev network";
|
|
|
|
|
|
- public static bool newData = false;
|
|
|
|
|
|
+ public static bool blockChainsInitialized = false;
|
|
public static Dictionary<int, Blockchain> loaded = new();
|
|
public static Dictionary<int, Blockchain> loaded = new();
|
|
public Dictionary<int, SmartContract> contracts = new();
|
|
public Dictionary<int, SmartContract> contracts = new();
|
|
public Dictionary<string, SmartContract> contractNames = new();
|
|
public Dictionary<string, SmartContract> contractNames = new();
|
|
@@ -39,11 +38,14 @@ namespace HyperCube.Models
|
|
|
|
|
|
public static void RegisterNetworks()
|
|
public static void RegisterNetworks()
|
|
{
|
|
{
|
|
|
|
+ Console.WriteLine($"RegisterNetworks");
|
|
var ethDev = new Blockchain(0, "Ethereum Dev Network", "127.0.0.1", 8545);
|
|
var ethDev = new Blockchain(0, "Ethereum Dev Network", "127.0.0.1", 8545);
|
|
var ethRinkeby = new Blockchain(1, "Ethereum Test Network", "127.0.0.1", 8666);
|
|
var ethRinkeby = new Blockchain(1, "Ethereum Test Network", "127.0.0.1", 8666);
|
|
ethDev.Initialize();
|
|
ethDev.Initialize();
|
|
ethRinkeby.Initialize();
|
|
ethRinkeby.Initialize();
|
|
- Console.WriteLine($"RegisterNetworks");
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ blockChainsInitialized = true;
|
|
}
|
|
}
|
|
|
|
|
|
//public static Blockchain GetInstance()
|
|
//public static Blockchain GetInstance()
|
|
@@ -98,17 +100,26 @@ namespace HyperCube.Models
|
|
|
|
|
|
public static Blockchain GetMain()
|
|
public static Blockchain GetMain()
|
|
{
|
|
{
|
|
- if (loaded.Count > 0)
|
|
|
|
- return loaded[selectedId];
|
|
|
|
|
|
+ try
|
|
|
|
+ {
|
|
|
|
+ if (loaded.Count > AccountModel.GetCurrent().blockchain_selected + 1)
|
|
|
|
+ return loaded[AccountModel.GetCurrent().blockchain_selected];
|
|
|
|
+ else
|
|
|
|
+ Console.WriteLine($"Error: blockchains loaded {loaded.Count}");
|
|
|
|
+ }
|
|
|
|
+ catch (Exception e)
|
|
|
|
+ {
|
|
|
|
+ Console.WriteLine("GetMain exception " + e.Message + ", stack trace:" + e.StackTrace);
|
|
|
|
+ }
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
|
|
|
|
public async Task<string> Initialize()
|
|
public async Task<string> Initialize()
|
|
- {
|
|
|
|
- string addr = await ListAccounts();
|
|
|
|
|
|
+ {
|
|
if (!loaded.ContainsKey(id))
|
|
if (!loaded.ContainsKey(id))
|
|
- loaded.Add(selectedId, this);
|
|
|
|
|
|
+ loaded.Add(AccountModel.GetCurrent().blockchain_selected, this);
|
|
Console.WriteLine($"Initialize: {name }loaded blockchains " + loaded.Count);
|
|
Console.WriteLine($"Initialize: {name }loaded blockchains " + loaded.Count);
|
|
|
|
+ string addr = await ListAccounts();
|
|
|
|
|
|
await LoadContracts();
|
|
await LoadContracts();
|
|
Console.WriteLine("LoadContracts count " + contracts.Count);
|
|
Console.WriteLine("LoadContracts count " + contracts.Count);
|
|
@@ -116,6 +127,30 @@ namespace HyperCube.Models
|
|
return $"{name} {url}:{port}";
|
|
return $"{name} {url}:{port}";
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public async Task<string> ListAccounts()
|
|
|
|
+ {
|
|
|
|
+ Console.WriteLine("ListAccounts");
|
|
|
|
+ string answer = "no";
|
|
|
|
+ //{ "jsonrpc":"2.0","method":"eth_getCode","params":["0x938cae6f6c21ed9d55196e96ef880f562e530553", "latest" ],"id":1}
|
|
|
|
+ //string req = "{\"jsonrpc\":\"2.0\",\"method\":\"eth_getCode\",\"params\":[\"0x874c6a51e62680d4594cd2555ed8fa47b63ed253\",\"latest\"],\"id\":1}";
|
|
|
|
+ string req = "{\"jsonrpc\":\"2.0\",\"method\":\"eth_accounts\", \"params\":[],\"id\":1}";
|
|
|
|
+
|
|
|
|
+ answer = await Post.PostRequestAsync(req);
|
|
|
|
+
|
|
|
|
+ //string json = Encoding.UTF8.GetString(bytedata, 1, bytedata.Length - 1);
|
|
|
|
+ //try
|
|
|
|
+ //{
|
|
|
|
+ Console.WriteLine("Json string " + answer);
|
|
|
|
+ dynamic jsonDe = JsonConvert.DeserializeObject(answer);
|
|
|
|
+ address = jsonDe.result[0];
|
|
|
|
+ var query = $"update blockchains set address_main='{address}' where id=1";
|
|
|
|
+ Console.WriteLine("query " + query);
|
|
|
|
+ MySQLConnector.Instance().SQLInsert(query);
|
|
|
|
+ Console.WriteLine("Json addr " + jsonDe.result[0]);
|
|
|
|
+ var methodName = (string)jsonDe.name;
|
|
|
|
+ return address;
|
|
|
|
+ }
|
|
|
|
+
|
|
public async Task LoadContracts()
|
|
public async Task LoadContracts()
|
|
{
|
|
{
|
|
MySQLConnector dbCon = MySQLConnector.Instance();
|
|
MySQLConnector dbCon = MySQLConnector.Instance();
|
|
@@ -245,30 +280,6 @@ namespace HyperCube.Models
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
|
|
|
|
- public async Task<string> ListAccounts()
|
|
|
|
- {
|
|
|
|
- string answer = "no";
|
|
|
|
- //{ "jsonrpc":"2.0","method":"eth_getCode","params":["0x938cae6f6c21ed9d55196e96ef880f562e530553", "latest" ],"id":1}
|
|
|
|
- //string req = "{\"jsonrpc\":\"2.0\",\"method\":\"eth_getCode\",\"params\":[\"0x874c6a51e62680d4594cd2555ed8fa47b63ed253\",\"latest\"],\"id\":1}";
|
|
|
|
- string req = "{\"jsonrpc\":\"2.0\",\"method\":\"eth_accounts\", \"params\":[],\"id\":1}";
|
|
|
|
-
|
|
|
|
- answer = await Post.PostRequestAsync(req);
|
|
|
|
-
|
|
|
|
- //string json = Encoding.UTF8.GetString(bytedata, 1, bytedata.Length - 1);
|
|
|
|
- //try
|
|
|
|
- //{
|
|
|
|
- Console.WriteLine("Json string " + answer);
|
|
|
|
- dynamic jsonDe = JsonConvert.DeserializeObject(answer);
|
|
|
|
- address = jsonDe.result[0];
|
|
|
|
- var query = $"update blockchains set address_main='{address}' where id=1";
|
|
|
|
- Console.WriteLine("query " + query);
|
|
|
|
- MySQLConnector.Instance().SQLInsert(query);
|
|
|
|
- Console.WriteLine("Json addr " + jsonDe.result[0]);
|
|
|
|
- var methodName = (string)jsonDe.name;
|
|
|
|
- newData = true;
|
|
|
|
- return address;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
public string GetAddress()
|
|
public string GetAddress()
|
|
{
|
|
{
|
|
//this.address = address;
|
|
//this.address = address;
|