|
@@ -9,6 +9,19 @@ namespace HyperCube.Models
|
|
{
|
|
{
|
|
public class Blockchain
|
|
public class Blockchain
|
|
{
|
|
{
|
|
|
|
+ public static string Connected
|
|
|
|
+ {
|
|
|
|
+ get {
|
|
|
|
+ var bc = GetMain();
|
|
|
|
+ if (bc != null)
|
|
|
|
+ return $"{bc.name}";
|
|
|
|
+ return "none";
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ public static string URLdefault = "127.0.0.1";
|
|
|
|
+ public static int defaultPort = 8545;
|
|
|
|
+ public static string defaultName = "Ethereum dev network";
|
|
|
|
+
|
|
public static bool newData = false;
|
|
public static bool newData = false;
|
|
public static Dictionary<string, Blockchain> loaded = new();
|
|
public static Dictionary<string, Blockchain> loaded = new();
|
|
public Dictionary<int, SmartContract> contracts = new();
|
|
public Dictionary<int, SmartContract> contracts = new();
|
|
@@ -17,6 +30,14 @@ namespace HyperCube.Models
|
|
public string url;
|
|
public string url;
|
|
public string address;
|
|
public string address;
|
|
public string name;
|
|
public string name;
|
|
|
|
+ static Blockchain instance;
|
|
|
|
+
|
|
|
|
+ public static Blockchain GetInstance()
|
|
|
|
+ {
|
|
|
|
+ if (instance == null)
|
|
|
|
+ instance = new Blockchain(URLdefault, defaultPort);
|
|
|
|
+ return instance;
|
|
|
|
+ }
|
|
|
|
|
|
Blockchain()
|
|
Blockchain()
|
|
{
|
|
{
|
|
@@ -61,7 +82,9 @@ namespace HyperCube.Models
|
|
|
|
|
|
public static Blockchain GetMain()
|
|
public static Blockchain GetMain()
|
|
{
|
|
{
|
|
- return loaded.Last().Value;
|
|
|
|
|
|
+ if (loaded.Count > 0)
|
|
|
|
+ return loaded.Last().Value;
|
|
|
|
+ return null;
|
|
}
|
|
}
|
|
|
|
|
|
public async Task<string> Initialize()
|
|
public async Task<string> Initialize()
|
|
@@ -71,9 +94,9 @@ namespace HyperCube.Models
|
|
loaded.Add(addr, this);
|
|
loaded.Add(addr, this);
|
|
Console.WriteLine("loaded blockchains " + loaded.Count);
|
|
Console.WriteLine("loaded blockchains " + loaded.Count);
|
|
|
|
|
|
- LoadContracts();
|
|
|
|
|
|
+ await LoadContracts();
|
|
Console.WriteLine("LoadContracts count " + contracts.Count);
|
|
Console.WriteLine("LoadContracts count " + contracts.Count);
|
|
- return $"Blockchain connected: {url}";
|
|
|
|
|
|
+ return $"{name} {url}:{port}";
|
|
}
|
|
}
|
|
|
|
|
|
public async Task LoadContracts()
|
|
public async Task LoadContracts()
|