コード例 #1
0
ファイル: MainForm.cs プロジェクト: vicyui/ehd-miner
        private void InitNodeStatus()
        {
            tsslNode.Alignment = ToolStripItemAlignment.Right;

            /*tsslNode.Text = "Free node";
             * if (language == "zh")
             * {
             *  tsslNode.Text = "免费节点";
             * }*/
            //string selectTable = "SELECT COUNT(*) FROM sqlite_master where type = 'table' and name = 't_node';";
            //int count = Convert.ToInt32(DBHelper.ExecuteScalar(selectTable, new Dictionary<string, object>()));

            IDbConnection conn        = DBHelper.CreateConnection();
            string        createTable = "CREATE TABLE if not exists \"t_node\"(\"id\" integer NOT NULL PRIMARY KEY AUTOINCREMENT,\"name_zh\" text NOT NULL,\"name_en\" text NOT NULL,\"address\" text NOT NULL  DEFAULT deafult,\"access\" integer NOT NULL DEFAULT 0,\"end_date\" text,\"on_used\" integer NOT NULL DEFAULT 0); ";

            DBHelper.ExecuteNonQuery(conn, createTable, new Dictionary <string, object>());
            string insertNodes =
                "INSERT OR IGNORE INTO \"t_node\" VALUES(0, '免费节点', 'Free node', 'deafult', 1, NULL, 1); " +
                "INSERT OR IGNORE INTO \"t_node\" VALUES(1, '中国区华南节点', 'South China node in China', 'sz', 0, NULL, 0);" +
                "INSERT OR IGNORE INTO \"t_node\" VALUES(2, '中国区华中节点', 'China central node', 'sz', 0, NULL, 0);" +
                "INSERT OR IGNORE INTO \"t_node\" VALUES(3, '中国区华北节点', 'North China node in China', 'sz', 0, NULL, 0);" +
                "INSERT OR IGNORE INTO \"t_node\" VALUES(4, '中国区东北节点', 'Northeast node of China', 'sz', 0, NULL, 0);" +
                "INSERT OR IGNORE INTO \"t_node\" VALUES(5, '中国区西南节点', 'Southwest node of China', 'sz', 0, NULL, 0);" +
                "INSERT OR IGNORE INTO \"t_node\" VALUES(6, '中国区西北节点', 'Northwest node of China', 'sz', 0, NULL, 0);" +
                "INSERT OR IGNORE INTO \"t_node\" VALUES(7, '亚洲区韩国节点', 'South Korea node in Asia', 'deafult', 0, NULL, 0);" +
                "INSERT OR IGNORE INTO \"t_node\" VALUES(8, '亚洲区日本节点', 'Japan node in Asia', 'deafult', 0, NULL, 0);" +
                "INSERT OR IGNORE INTO \"t_node\" VALUES(9, '亚洲新加坡节点', 'Singapore node in Asia', 'deafult', 0, NULL, 0);" +
                "INSERT OR IGNORE INTO \"t_node\" VALUES(10, '欧洲区英国节点', 'UK node in Europe', 'deafult', 0, NULL, 0);" +
                "INSERT OR IGNORE INTO \"t_node\" VALUES(11, '欧洲区德国节点', 'German node in Europe', 'deafult', 0, NULL, 0);" +
                "INSERT OR IGNORE INTO \"t_node\" VALUES(12, '美州区美国节点', 'Us node', 'deafult', 0, NULL, 0);" +
                "INSERT OR IGNORE INTO \"t_node\" VALUES(13, '非洲区南非节点', 'Africa South Africa node', 'deafult', 0, NULL, 0);" +
                "INSERT OR IGNORE INTO \"t_node\" VALUES(14, '大洋洲区巴西节点', 'Oceania Brazil node', 'deafult', 0, NULL, 0); " +
                "INSERT OR IGNORE INTO \"t_node\" VALUES(15, '中国区华东节点', 'East China node in China', 'sz', 0, NULL, 0); " +
                "UPDATE \"t_node\" SET name_en = 'Oceania Brazil node' where name_en = '.Oceania Brazil node'; ";

            DBHelper.ExecuteNonQuery(conn, insertNodes, new Dictionary <string, object>());
            conn.Close();

            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);

            if (null != nodes[0])
            {
                tsslNode.Text = nodes[0].Name_zh;
                if (language == "en")
                {
                    tsslNode.Text = nodes[0].Name_en;
                }

                if (nodes[0].End_date != null)
                {
                    tsslNode.Text += "|" + resource.GetString("nodeStatusTips") + nodes[0].End_date;
                }

                if (nodes[0].End_date == DateTime.Now.ToString("yyyy-MM-dd"))
                {
                    RunProcess("cmd.exe", "taskkill /F /IM poc.exe");
                    string updateNode = "update t_node set on_used = 0,access = 0,end_date = @date where id = @id;"
                                        + "update t_node set on_used =1 where id = 0";
                    DBHelper.ExecuteNonQuery(updateNode, new Dictionary <string, object> {
                        { "id", nodes[0].Id }, { "date", null }
                    });
                    FileUtil.ExtractResFile("EHDMiner.Resources." + poc, Application.StartupPath + "\\bin\\" + poc);
                }
            }
        }
コード例 #2
0
ファイル: MainForm.cs プロジェクト: vicyui/ehd-miner
        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;
            }
        }
コード例 #3
0
ファイル: AddNodeForm.cs プロジェクト: vicyui/ehd-miner
        private void AddNodeForm_Load(object sender, EventArgs e)
        {
            btnAddNode.Text       = "确定";
            btnAddNodeCancel.Text = "取消";
            //InitTableNode();

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

            //string filePath = Path.Combine(Application.StartupPath, "config");//在当前程序路径创建
            //Dictionary<string, Node> nodes = new Dictionary<string, Node>
            //{
            //    { "00", new Node("00", "免费节点", "Free node", "default", true) },
            //    { "01", new Node("01", "01.中国区华南节点", "01.South China node in China", "sz") },
            //    { "02", new Node("02", "02.中国区华中节点", "02.China central node", "sz") },
            //    { "03", new Node("03", "03.中国区华北节点", "03.North China node in China", "sz") },
            //    { "04", new Node("04", "04.中国区东北节点", "04.Northeast node of China", "sz") },
            //    { "05", new Node("05", "05.中国区西南节点", "05.Southwest node of China", "sz") },
            //    { "06", new Node("06", "06.中国区西北节点", "06.Northwest node of China", "sz") },
            //    { "07", new Node("07", "07.亚洲区韩国节点", "07.South Korea node in Asia", "default") },
            //    { "08", new Node("08", "08.亚洲区日本节点", "08.Japan node in Asia", "default") },
            //    { "09", new Node("09", "09.亚洲新加坡节点", "09.Singapore node in Asia", "default") },
            //    { "10", new Node("10", "10.欧洲区英国节点", "10.UK node in Europe", "default") },
            //    { "11", new Node("11", "11.欧洲区德国节点", "11.German node in Europe", "default") },
            //    { "12", new Node("12", "12.美州区美国节点", "12.Us node", "default") },
            //    { "13", new Node("13", "13.非洲区南非节点", "13.Africa South Africa node", "default") },
            //    { "14", new Node("14", "14.大洋洲区巴西节点", "14.Oceania Brazil node", "default") }
            //};

            //FileStream fs;
            //StreamWriter sw;
            //StreamReader sr;
            //if (!File.Exists(filePath))
            //{
            //    fs = new FileStream(filePath, FileMode.Create, FileAccess.Write);
            //    sw = new StreamWriter(fs);
            //    fs.Seek(fs.Length, SeekOrigin.End);
            //    foreach (KeyValuePair<string, Node> node in nodes)
            //    {
            //        sw.WriteLine(node.Key + "=" + nodes[node.Key].Access);//开始写入值
            //    }
            //    sw.Close();
            //    fs.Close();
            //}
            ////File.SetAttributes(filePath, FileAttributes.Hidden);
            //fs = new FileStream(filePath, FileMode.Open, FileAccess.Read);
            //sr = new StreamReader(fs);
            //fs.Seek(0, SeekOrigin.Begin);
            //string line;
            //while ((line = sr.ReadLine()) != null)
            //{
            //    if ("true".Equals(line.Split('=')[1].ToLower()))
            //    {
            //        nodes[line.Split('=')[0]].Access = true;
            //        nodes[line.Split('=')[0]].Zh_name += "[已开通]";
            //        nodes[line.Split('=')[0]].En_name += "[Opened]";
            //    }
            //}
            //sr.Close();
            //fs.Close();

            foreach (Node node in nodes)
            {
                if (node.Access == 1)
                {
                    node.Name_zh += "[已开通]";
                    node.Name_en += "[Opened]";
                }
                if (node.On_used == 1)
                {
                    node.Name_zh += "[已选择]";
                    node.Name_en += "[Selected]";
                }
            }

            comboBox.DataSource    = nodes;
            comboBox.DisplayMember = "name_zh";
            comboBox.ValueMember   = "address";
            if (mainForm.language == "en")
            {
                btnAddNode.Text        = "OK";
                btnAddNodeCancel.Text  = "Cancel";
                comboBox.DisplayMember = "name_en";
            }
        }