|
@@ -9,6 +9,7 @@ namespace HyperCube.Models
|
|
|
{
|
|
|
public class Blockchain
|
|
|
{
|
|
|
+ public static bool newData = false;
|
|
|
public static List<Blockchain> loaded = new List<Blockchain>();
|
|
|
public int port;
|
|
|
public string url;
|
|
@@ -23,29 +24,50 @@ namespace HyperCube.Models
|
|
|
{
|
|
|
this.url = url;
|
|
|
this.port = port;
|
|
|
- ListAccounts();
|
|
|
+ }
|
|
|
+
|
|
|
+ public async Task<string> GetReceipt(string transactionAddress)
|
|
|
+ {
|
|
|
+ Console.WriteLine("contractAddress " + transactionAddress);
|
|
|
+ var req = $"{{ \"jsonrpc\":\"2.0\",\"method\":\"eth_getTransactionReceipt\",\"params\":[\"{transactionAddress}\"], \"id\":1}}";
|
|
|
+
|
|
|
+ var res = await Post.PostRequestAsync(req);
|
|
|
+ Console.WriteLine("result " + res);
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ public async Task<string> Initialize()
|
|
|
+ {
|
|
|
+ await ListAccounts();
|
|
|
if (!loaded.Contains(this))
|
|
|
loaded.Add(this);
|
|
|
Console.WriteLine("loaded blockchains " + loaded.Count);
|
|
|
+ return $"Blockchain connected: {url}";
|
|
|
+ }
|
|
|
+
|
|
|
+ public async void GetGas(string bytecode)
|
|
|
+ {
|
|
|
+
|
|
|
}
|
|
|
|
|
|
- public async void AddContract(string bytecode)
|
|
|
+ public async Task<string> AddContract(string bytecode)
|
|
|
{
|
|
|
- var req = $"{{ \"jsonrpc\":\"2.0\",\"method\":\"eth_sendTransaction\",\"params\":[{{\"from\":\"0x4Ce13B6012ad8AB5Bf2E364679173D81C28Cd8d4\",\"gas\":\"0x31b2e\", \"data\":\"{bytecode}\"}}], \"id\":1}}";
|
|
|
+ Console.WriteLine("bytecode " + bytecode);
|
|
|
+ var req = $"{{ \"jsonrpc\":\"2.0\",\"method\":\"eth_sendTransaction\",\"params\":[{{\"from\":\"{address}\",\"gas\":\"0x31b2e\", \"data\":\"{bytecode}\"}}], \"id\":1}}";
|
|
|
|
|
|
var res = await Post.PostRequestAsync(req);
|
|
|
Console.WriteLine("result "+ res);
|
|
|
+ return res;
|
|
|
}
|
|
|
|
|
|
- public async void ListAccounts()
|
|
|
+ public async Task 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);
|
|
|
-
|
|
|
+ answer = await Post.PostRequestAsync(req);
|
|
|
|
|
|
//string json = Encoding.UTF8.GetString(bytedata, 1, bytedata.Length - 1);
|
|
|
//try
|
|
@@ -55,6 +77,7 @@ namespace HyperCube.Models
|
|
|
address = jsonDe.result[0];
|
|
|
Console.WriteLine("Json addr " + jsonDe.result[0]);
|
|
|
var methodName = (string)jsonDe.name;
|
|
|
+ newData = true;
|
|
|
}
|
|
|
|
|
|
public async void ExecuteContract()
|