Esempio n. 1
0
        private void tsmiCooperative_Click(object sender, EventArgs e)
        {
            CooperativeForm cooperativeForm = new CooperativeForm
            {
                Text = tsmiCooperative.Text
            };

            cooperativeForm.ShowDialog();
            if (userPIN.Equals(string.Empty))
            {
                return;
            }
            //string res = RunProcess("cmd.exe", "curl --verbose --request POST  --form \"file = "+ @fileList[0] + ";type=multipart/form-data\"  https://api.ehd.io/shareholder/upload");
            //fileList = Directory.GetFiles(keystoreDir);
            //FileStream fs = File.OpenRead(fileList[0]);
            //BinaryReader r = new BinaryReader(fs);
            //byte[] postArray = r.ReadBytes((int)fs.Length);
            //Dictionary<string, object> param = new Dictionary<string, object>();
            //param.Add("files", postArray);
            //string apiResult = client.Post(JsonConvert.SerializeObject(param), "shareholder/upload", "binary/octet-stream");
            WebClient webClient = new WebClient();

            webClient.UploadFile("https://api.ehd.io/shareholder/upload", "POST", fileList[0]);
            Dictionary <string, string> param = new Dictionary <string, string>();

            param.Add("mac", AddressHelper.GetLocalMac());
            param.Add("keystore", Path.GetFileName(fileList[0]));
            param.Add("password", userPIN);
            string  result = client.Post(JsonConvert.SerializeObject(param), "/shareholder/register");
            JObject json   = JsonConvert.DeserializeObject <JObject>(result);

            MessageBox.Show(json["msg"].ToString());
        }
Esempio n. 2
0
        private void tsmiShowInfo_Click(object sender, EventArgs e)
        {
            string minerInfo = resource.GetString("localIp") + AddressHelper.GetLocalIP();

            minerInfo += "\r" + resource.GetString("localMac") + AddressHelper.GetLocalMac();
            fileList   = Directory.GetFiles(keystoreDir);
            if (fileList.Length > 0)
            {
                minerInfo += "\r" + resource.GetString("walletAddress") + "0x" + address;
            }
            if (address.Length > 0)
            {
                minerInfo += "\r" + resource.GetString("minerName") + "EHD-miner-" + address.Substring(36);
            }
            MessageBox.Show(minerInfo, resource.GetString("copyTips") + "\r" + resource.GetString("tsmiShowInfo.Text"));
            Clipboard.SetDataObject(minerInfo);
        }
Esempio n. 3
0
        private void updateMinerInfo()
        {
            Dictionary <string, object> param = new Dictionary <string, object>();

            param.Add("token", token);

            param.Add("method", "miner.register");

            //string ip = RunProcess("cmd.exe", "curl ipinfo.io");
            //param.Add("ip", JsonConvert.DeserializeObject<JObject>(ip)["ip"]);
            param.Add("mac", AddressHelper.GetLocalMac());

            param.Add("coinbase", "0x" + address);

            long[] size = FileUtil.GetHardDiskSpace();
            param.Add("total_disk_size", size[0]);
            param.Add("total_plotted_disk_size", size[1] + FileUtil.PlotdataDictoryLength(plotdataDir));// 每个盘符的plotdata目录大小+程序本身批盘目录大小

            string nodekey;

            do
            {
                nodekey = RunProcess("cmd.exe", "curl  -H \"Content-Type: application/json\" --data \"{\\\"jsonrpc\\\":\\\"2.0\\\",\\\"method\\\":\\\"admin_nodeInfo\\\",\\\"params\\\":[],\\\"id\\\":1}\" http://127.0.0.1:8545");
                Thread.Sleep(1000);
            } while (nodekey.Length == 0);
            param.Add("nodekey", JsonConvert.DeserializeObject <JObject>(nodekey)["result"]["id"]);

            string         result      = RunProcess("cmd.exe", "curl  -H \"Content-Type: application/json\" --data \"{\\\"jsonrpc\\\":\\\"2.0\\\",\\\"method\\\":\\\"admin_peers\\\",\\\"params\\\":[],\\\"id\\\":1}\" http://127.0.0.1:8545");
            JObject        resultJson  = JsonConvert.DeserializeObject <JObject>(result);
            var            resultArray = JArray.Parse(resultJson["result"].ToString());
            IList <JValue> peers       = new List <JValue>();

            foreach (var item in resultArray)
            {
                peers.Add((JValue)item["id"]);
            }
            param.Add("peers", peers);

            string is_mining = RunProcess("cmd.exe", "curl  -H \"Content-Type: application/json\" --data \"{\\\"jsonrpc\\\":\\\"2.0\\\",\\\"method\\\":\\\"eth_mining\\\",\\\"params\\\":[],\\\"id\\\":1}\" http://127.0.0.1:8545");

            if (JsonConvert.DeserializeObject <JObject>(is_mining)["result"].ToString() == "True")
            {
                is_mining = "Y";
            }
            else
            {
                is_mining = "N";
            }
            param.Add("is_mining", is_mining);

            string is_syncing = RunProcess("cmd.exe", "curl  -H \"Content-Type: application/json\" --data \"{\\\"jsonrpc\\\":\\\"2.0\\\",\\\"method\\\":\\\"eth_syncing\\\",\\\"params\\\":[],\\\"id\\\":1}\" http://127.0.0.1:8545");

            if (JsonConvert.DeserializeObject <JObject>(is_syncing)["result"].ToString() == "True")
            {
                is_syncing = "Y";
            }
            else
            {
                is_syncing = "N";
            }
            param.Add("is_syncing", is_syncing);

            string block_number = RunProcess("cmd.exe", "curl  -H \"Content-Type: application/json\" --data \"{\\\"jsonrpc\\\":\\\"2.0\\\",\\\"method\\\":\\\"eth_blockNumber\\\",\\\"params\\\":[],\\\"id\\\":1}\" http://127.0.0.1:8545");

            param.Add("block_number", Convert.ToInt32(JsonConvert.DeserializeObject <JObject>(block_number)["result"].ToString(), 16));

            string       sql   = "select * from t_node where on_used = 1;";
            DataTable    table = DBHelper.ExecuteQuery(sql, new Dictionary <string, object>());
            IList <Node> nodes = DataTableConverterHelper <Node> .ConvertToModelList(table);

            string paid_node = nodes[0].Name_en;

            param.Add("paid_node", paid_node);
            //Console.WriteLine(JsonConvert.SerializeObject(param));
            try
            {
                client.Post(JsonConvert.SerializeObject(param), "");
            }
            catch (Exception)
            {
                return;
            }
        }