|
@@ -36,16 +36,31 @@ namespace HyperCube.Models
|
|
|
public string name;
|
|
|
static Blockchain instance;
|
|
|
|
|
|
- public static void RegisterNetworks()
|
|
|
+ public async static Task RegisterNetworks()
|
|
|
{
|
|
|
- Console.WriteLine($"RegisterNetworks");
|
|
|
- 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);
|
|
|
- ethDev.Initialize();
|
|
|
- ethRinkeby.Initialize();
|
|
|
+ if (!blockChainsInitialized)
|
|
|
+ {
|
|
|
+ Console.WriteLine($"RegisterNetworks");
|
|
|
+ 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);
|
|
|
+ await ethDev.Initialize();
|
|
|
+ await ethRinkeby.Initialize();
|
|
|
|
|
|
+ blockChainsInitialized = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public async Task<string> Initialize()
|
|
|
+ {
|
|
|
+ if (!loaded.ContainsKey(id))
|
|
|
+ loaded.Add(id, this);
|
|
|
+ Console.WriteLine($"Initialize: {name}, loaded blockchains " + loaded.Count);
|
|
|
+ string addr = await ListAccounts();
|
|
|
|
|
|
- blockChainsInitialized = true;
|
|
|
+ await LoadContracts();
|
|
|
+ Console.WriteLine("LoadContracts count " + contracts.Count);
|
|
|
+ Console.WriteLine("connected " + Connected);
|
|
|
+ return $"{name} {url}:{port}";
|
|
|
}
|
|
|
|
|
|
//public static Blockchain GetInstance()
|
|
@@ -100,9 +115,10 @@ namespace HyperCube.Models
|
|
|
|
|
|
public static Blockchain GetMain()
|
|
|
{
|
|
|
+ Console.WriteLine("GetMain blockchain_selected " + AccountModel.GetCurrent().blockchain_selected);
|
|
|
try
|
|
|
{
|
|
|
- if (loaded.Count > AccountModel.GetCurrent().blockchain_selected + 1)
|
|
|
+ if (loaded.Count > AccountModel.GetCurrent().blockchain_selected)
|
|
|
return loaded[AccountModel.GetCurrent().blockchain_selected];
|
|
|
else
|
|
|
Console.WriteLine($"Error: blockchains loaded {loaded.Count}");
|
|
@@ -114,19 +130,6 @@ namespace HyperCube.Models
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
- public async Task<string> Initialize()
|
|
|
- {
|
|
|
- if (!loaded.ContainsKey(id))
|
|
|
- loaded.Add(AccountModel.GetCurrent().blockchain_selected, this);
|
|
|
- Console.WriteLine($"Initialize: {name }loaded blockchains " + loaded.Count);
|
|
|
- string addr = await ListAccounts();
|
|
|
-
|
|
|
- await LoadContracts();
|
|
|
- Console.WriteLine("LoadContracts count " + contracts.Count);
|
|
|
- Console.WriteLine("connected " + Connected);
|
|
|
- return $"{name} {url}:{port}";
|
|
|
- }
|
|
|
-
|
|
|
public async Task<string> ListAccounts()
|
|
|
{
|
|
|
Console.WriteLine("ListAccounts");
|
|
@@ -154,7 +157,7 @@ namespace HyperCube.Models
|
|
|
public async Task LoadContracts()
|
|
|
{
|
|
|
MySQLConnector dbCon = MySQLConnector.Instance();
|
|
|
- contracts = await dbCon.SQLSelectContracts();
|
|
|
+ contracts = await dbCon.SQLSelectContracts(id);
|
|
|
foreach (var contract in contracts.Values)
|
|
|
{
|
|
|
await contract.LoadFunction();
|