Ejemplo n.º 1
0
        static BlockSub GetUniqueTransfer(string url, string unique)
        {
            try
            {
                if (httpPoolRelay == null)
                {
                    using (var dbSnapshot = Entity.Root.GetComponent <LevelDBStore>().GetSnapshot(0))
                    {
                        string hasht = dbSnapshot.Get($"unique_{unique}");
                        if (!string.IsNullOrEmpty(hasht))
                        {
                            return(dbSnapshot.Transfers.Get(hasht));
                        }
                    }
                    return(null);
                }

                HttpMessage quest = new HttpMessage();
                quest.map = new Dictionary <string, string>();
                quest.map.Add("cmd", "uniquetransfer");
                quest.map.Add("unique", unique);
                var result = ComponentNetworkHttp.QueryStringSync($"http://{url}", quest);
                if (string.IsNullOrEmpty(result) || result == "{\"ret\":\"failed\"}")
                {
                    return(null);
                }
                return(JsonHelper.FromJson <BlockSub>(result));
            }
            catch (Exception)
            {
            }
            return(null);
        }
Ejemplo n.º 2
0
        static Account GetAccount(string url, string address)
        {
            try
            {
                if (httpPoolRelay == null)
                {
                    using (DbSnapshot dbSnapshot = Entity.Root.GetComponent <LevelDBStore>().GetSnapshot(0))
                    {
                        return(dbSnapshot.Accounts.Get(address));
                    }
                }

                var list = new List <string>();
                list.Add(address);

                HttpMessage quest = new HttpMessage();
                quest.map = new Dictionary <string, string>();
                quest.map.Add("cmd", "getaccounts");
                quest.map.Add("List", Base58.Encode(JsonHelper.ToJson(list).ToByteArray()));

                var result   = ComponentNetworkHttp.QueryStringSync($"http://{url}", quest);
                var accounts = JsonHelper.FromJson <Dictionary <string, Account> >(result);
                accounts.TryGetValue(address, out Account acc);

                return(acc);
            }
            catch (Exception)
            {
            }
            return(null);
        }
Ejemplo n.º 3
0
        public Block GetMcBlock(long ___height)
        {
            if (___height <= 1)
            {
                return(null);
            }

            try
            {
                PoolBlock poolBlock = null;
                using (DbSnapshot snapshot = pool.PoolDBStore.GetSnapshot())
                {
                    var str = snapshot.Get($"PoolBlock_{___height}");
                    if (!string.IsNullOrEmpty(str))
                    {
                        poolBlock = JsonHelper.FromJson <PoolBlock>(str);
                        if (poolBlock != null && Wallet.CheckAddress(poolBlock.Address))
                        {
                            return(new Block()
                            {
                                hash = poolBlock.hash, Address = poolBlock.Address, random = poolBlock.random
                            });
                        }
                    }
                }

                HttpMessage quest = new HttpMessage();
                quest.map = new Dictionary <string, string>();
                quest.map.Add("cmd", "GetMcBlock");
                quest.map.Add("version", version);
                quest.map.Add("height", ___height.ToString());
                var result = ComponentNetworkHttp.QueryStringSync($"http://{poolUrl}", quest, 5);
                if (string.IsNullOrEmpty(result))
                {
                    return(null);
                }
                poolBlock = JsonHelper.FromJson <PoolBlock>(result);
                if (poolBlock != null && Wallet.CheckAddress(poolBlock.Address))
                {
                    using (DbSnapshot snapshot = pool.PoolDBStore.GetSnapshot())
                    {
                        snapshot.Add($"PoolBlock_{___height}", JsonHelper.ToJson(poolBlock));
                        snapshot.Commit();
                    }
                    return(new Block()
                    {
                        hash = poolBlock.hash, Address = poolBlock.Address, random = poolBlock.random
                    });
                }
            }
            catch (Exception)
            {
            }
            return(null);
        }
Ejemplo n.º 4
0
        private static async System.Threading.Tasks.Task <string> GetNonceAsync(string address, HttpMessage httpMessage, string ruleIP)
        {
            httpMessage.map["cmd"]     = "getnonce";
            httpMessage.map["address"] = address;
            HttpMessage result = await ComponentNetworkHttp.QueryCommand(ruleIP + $"/{httpMessage.map["cmd"]}", httpMessage);

            if (result.result == "INVALID URL, set the correct url" || result.result == "false")
            {
                return(result.result);
            }
            Dictionary <string, string> nonce = JsonHelper.FromJson <Dictionary <string, string> >(result.result);
            string nonc = nonce["nonce"];

            return(nonc);
        }
Ejemplo n.º 5
0
        private static async System.Threading.Tasks.Task <string> GetHeightAsync()
        {
            Dictionary <string, object> latestBlockHeight = new Dictionary <string, object>();

            latestBlockHeight.Add("success", true);
            latestBlockHeight.Add("message", "successful operation");
            latestBlockHeight.Add("height", "");
            HttpMessage temp = new HttpMessage();

            temp.map = new Dictionary <string, string>();
            temp.map.Add("cmd", "latest-block-height");
            temp = await ComponentNetworkHttp.QueryCommand(Program.ruleIP + $"/{temp.map["cmd"]}", temp);

            var temp1 = JsonHelper.FromJson <Dictionary <string, object> >(temp.result);

            return((string)temp1["height"]);
        }
Ejemplo n.º 6
0
        public override void Update()
        {
            if (timepassHearBeat.IsPassSet())
            {
                if (hearbeat == null)
                {
                    hearbeat     = new HttpMessage();
                    hearbeat.map = new Dictionary <string, string>();
                    hearbeat.map.Add("cmd", "hearbeat");
                }
                _ = ComponentNetworkHttp.Query(this.prefix, hearbeat);
            }

            if (httpThread == null)
            {
                httpListener.Abort();
                httpListener.Close();
                StartAccept(this.prefix);
            }
        }
Ejemplo n.º 7
0
        public async void Run()
        {
            await Task.Delay(1000);

            HttpMessage quest = new HttpMessage();

            quest.map = new Dictionary <string, string>();

            while (true)
            {
                quest.map.Clear();
                quest.map.Add("cmd", "submit");
                quest.map.Add("height", height.ToString());
                quest.map.Add("address", address);
                quest.map.Add("number", number);
                quest.map.Add("random", random);
                quest.map.Add("taskid", taskid);
                HttpMessage result = await ComponentNetworkHttp.Query(url, quest);

                string rel = result.map["rel"];
                if (rel != "ok")
                {
                    long.TryParse(result.map["height"], out long tempheight);
                    taskid = result.map["taskID"];
                    string temphash = result.map["hashmining"];
                    if (temphash == null || temphash == "" || temphash != hashmining)
                    {
                        if (diff_max != 0)
                        {
                            calculatePower.Insert(diff_max);
                        }

                        diff_max   = 0;
                        hashmining = temphash;
                        height     = tempheight;
                        random     = "";
                    }
                }
                await Task.Delay(1000);
            }
        }
Ejemplo n.º 8
0
        static public long GetHeight(string url, float timeout = 1)
        {
            try
            {
                if (httpPoolRelay == null)
                {
                    return(Entity.Root.GetComponent <Consensus>().transferHeight);
                }

                HttpMessage quest = new HttpMessage();
                quest.map = new Dictionary <string, string>();
                quest.map.Add("cmd", "stats");
                quest.map.Add("style", "1");
                var result = ComponentNetworkHttp.QuerySync($"http://{url}", quest, timeout);
                return(result == null?0:long.Parse(result.map["H"]));
            }
            catch (Exception)
            {
            }
            return(0);
        }
Ejemplo n.º 9
0
        // Pool Call
        public void RegisterPool()
        {
            HttpMessage quest = new HttpMessage();

            quest.map = new Dictionary <string, string>();
            quest.map.Clear();
            quest.map.Add("cmd", "registerPool");
            quest.map.Add("version", version);
            quest.map.Add("password", HttpPool.poolPassword);
            quest.map.Add("poolInfo", $"{number}->0.0.0.0:{httpPool.GetHttpAdderrs().Port}##http://0.0.0.0:{httpRpc.GetHttpAdderrs().Port}");
            HttpMessage result = null;

            result = ComponentNetworkHttp.QuerySync($"http://{poolUrl}/mining", quest, 5);
            if (result != null && result.map != null)
            {
                if (result.map.TryGetValue("report", out string report) && report != "accept")
                {
                    Log.Warning($"\n {result.map["tips"]}");
                    return;
                }
                if (result.map.TryGetValue("ownerAddress", out string ownerAddress))
                {
                    if (pool.ownerAddress != ownerAddress)
                    {
                        pool.ownerAddress = ownerAddress;
                        Log.Info($"RegisterPool addr: {ownerAddress}");
                    }
                }
                if (result.map.TryGetValue("serviceFee", out string serviceFee))
                {
                    float.TryParse(serviceFee, out float fee);
                    if (rulerServiceFee != fee)
                    {
                        rulerServiceFee = fee;
                        Log.Info($"RegisterPool  fee: {rulerServiceFee}");
                    }
                }
            }
        }
Ejemplo n.º 10
0
        static int SendTransfer(string url, BlockSub blockSub)
        {
            try
            {
                if (httpPoolRelay == null)
                {
                    return(Entity.Root.GetComponent <Rule>().AddTransfer(blockSub, false));
                }

                var quest = new HttpMessage();
                quest.map = new Dictionary <string, string>();
                quest.map.Clear();
                quest.map.Add("cmd", "transfer");
                quest.map.Add("type", blockSub.type);
                quest.map.Add("hash", blockSub.hash);
                quest.map.Add("nonce", blockSub.nonce.ToString());
                quest.map.Add("addressIn", blockSub.addressIn);
                quest.map.Add("addressOut", blockSub.addressOut);
                quest.map.Add("amount", blockSub.amount);
                quest.map.Add("data", System.Web.HttpUtility.UrlEncode(blockSub.data));
                quest.map.Add("sign", blockSub.sign.ToHexString());
                quest.map.Add("fee", blockSub.gas.ToString());
                quest.map.Add("timestamp", blockSub.timestamp.ToString());
                quest.map.Add("remarks", System.Web.HttpUtility.UrlEncode(blockSub.remarks));
                quest.map.Add("depend", System.Web.HttpUtility.UrlEncode(blockSub.depend));
                quest.map.Add("extend", System.Web.HttpUtility.UrlEncode(JsonHelper.ToJson(blockSub.extend)));

                var result = ComponentNetworkHttp.QuerySync($"http://{url}", quest);

                if (result.map["success"] == "false")
                {
                    return(int.Parse(result.map["rel"]));
                }
            }
            catch (Exception)
            {
            }
            return(-1);
        }
Ejemplo n.º 11
0
 public override void Start()
 {
     networkHttp = this.entity.GetComponent <ComponentNetworkHttp>();
     Log.Info($"smartxRpc http://{networkHttp.ipEndPoint}/");
 }
Ejemplo n.º 12
0
        public static async System.Threading.Tasks.Task OrderAsync(HttpMessage httpMessage)
        {
            Wallet.Inst = null;
            if (httpMessage.map["0"] == "importkey")
            {
                if (!GetParam(httpMessage, "1", "1", out string privatekey))
                {
                    httpMessage.result = "command error! \nexample: import key privatekey";
                    return;
                }
                string address = AddKeyBag(privatekey, Program.keyBag);
                httpMessage.result = $" {address}";
            }
            else if (httpMessage.map["0"] == "showip")
            {
                httpMessage.result = JsonHelper.ToJson(Program.ruleIP);
            }
            else if (httpMessage.map["0"] == "openwallet")
            {
                Wallet wallet = new Wallet();
                if (httpMessage.map.Count == 2)
                {
                    httpMessage.map.Add("1", "./smartx-wallet.json");
                }
                if (Program.wallet.keys.Count > 0)
                {
                    httpMessage.result = "please close wallet first!";
                    return;
                }
                try
                {
                    string path    = httpMessage.map["1"];
                    Wallet wallet1 = Wallet.GetWallet(path);
                    wallet = wallet1;
                }
                catch (Exception e)
                {
                    httpMessage.result = "Please check your path";
                    return;
                }


                if (wallet == null)
                {
                    httpMessage.result = "Password error";
                    return;
                }
                if (Program.keyBag.Count > 0)
                {
                    if (!Program.keyBag.ContainsKey(wallet.keys[0].ToAddress()))
                    {
                        Program.keyBag.Add(Wallet.ToAddress(wallet.keys[0].publickey), wallet.keys[0]);
                    }
                }
                else
                {
                    Program.keyBag.Add(Wallet.ToAddress(wallet.keys[0].publickey), wallet.keys[0]);
                }
                Program.wallet = wallet;
                //string random = Program.wallet.keys[0].random.ToHex();
                //string nonce="0";
                string nonce = await GetNonceAsync(Wallet.ToAddress(Program.wallet.keys[0].publickey), httpMessage, Program.ruleIP);//0

                if (nonce == "INVALID URL, set the correct url" || nonce == "false")
                {
                    httpMessage.result = nonce;
                    return;
                }
                Program.nonce = (int.Parse(nonce) + 1).ToString();
                //Console.WriteLine(Program.nonce);
                httpMessage.result = Wallet.ToAddress(Program.wallet.keys[0].publickey) + " open";
            }
            else if (httpMessage.map["0"] == "setwallet")
            {
                if (!GetParam(httpMessage, "1", "address", out string address))
                {
                    httpMessage.result = "command error! \nexample: setwallet address";
                    return;
                }
                WalletKey key = new WalletKey();
                if (Program.keyBag.Count > 0)
                {
                    if (Program.keyBag.ContainsKey(address))
                    {
                        key = Program.keyBag[address];
                    }
                    else
                    {
                        httpMessage.result = "The address isn't in the key bag";
                        return;
                    }
                }
                else
                {
                    httpMessage.result = "The address isn't in the key bag";
                    return;
                }

                if (Program.wallet.keys.Count != 0)
                {
                    httpMessage.result = "please close wallet first!";
                    return;
                }
                Program.wallet.keys.Add(key);
                string nonce = await GetNonceAsync(address, httpMessage, Program.ruleIP);//0

                if (nonce == "INVALID URL, set the correct url" || nonce == "false")
                {
                    httpMessage.result = nonce;
                    return;
                }
                Program.nonce      = (int.Parse(nonce) + 1).ToString();
                httpMessage.result = $"{address} set";
            }
            else if (httpMessage.map["0"] == "list")
            {
                List <string> list = new List <string>();
                foreach (KeyValuePair <string, WalletKey> k in Program.keyBag)
                {
                    list.Add(k.Key);
                }
                httpMessage.result = JsonHelper.ToJson(list);
            }
            else if (httpMessage.map["0"] == "closewallet")
            {
                Wallet.Inst        = null;
                Program.wallet     = new Wallet();
                Program.nonce      = "";
                httpMessage.result = "wallet closed";
            }
            else if (httpMessage.map["0"] == "getprivatekey")
            {
                if (Program.wallet.keys.Count != 0)
                {
                    httpMessage.result = JsonHelper.ToJson(Program.wallet.keys[0].random.ToHexString());
                }
                else
                {
                    httpMessage.result = "please set wallet";
                }
            }
            else if (httpMessage.map["0"] == "exportkey")
            {
                if (Program.wallet.keys.Count == 0)
                {
                    httpMessage.result = "please set wallet";
                    return;
                }
                if (httpMessage.map.Count <= 2)
                {
                    File.WriteAllText("./private.json", Program.wallet.keys[0].random.ToHexString());
                    httpMessage.result = $"export key  successful";
                    return;
                }
                else if (Program.wallet.keys.Count > 0)
                {
                    try
                    {
                        File.WriteAllText(httpMessage.map["1"] + "/private.json", Program.wallet.keys[0].random.ToHexString());
                        httpMessage.result = $"export key  successful";
                    }
                    catch (Exception)
                    {
                        httpMessage.result = "Please check the path";
                        return;
                    }
                }
                else
                {
                    httpMessage.result = "Please set the wallet first";
                }
            }
            else if (httpMessage.map["0"] == "clear")
            {
                Console.Clear();
            }
            else if (httpMessage.map["0"] == "transfer")
            {
                if (httpMessage.map.Count <= 3)
                {
                    Console.WriteLine("transfer error example transfer addressOut amount fee");
                    return;
                }
                if (Program.wallet.keys.Count == 0)
                {
                    httpMessage.result = "Please set the wallet first";
                    return;
                }
                if (!Wallet.CheckAddress(httpMessage.map["1"]))
                {
                    httpMessage.result = "Please check addressOut";
                    return;
                }
                TransferInfo(httpMessage, Program.ruleIP);
                HttpMessage result = await ComponentNetworkHttp.QueryCommand(Program.ruleIP + $"/{httpMessage.map["cmd"]}", httpMessage);

                if (result.result.Contains("true"))
                {
                    Program.nonce      = (int.Parse(Program.nonce) + 1).ToString();
                    httpMessage.result = result.result + " " + httpMessage.map["hash"];
                }
                else
                {
                    httpMessage.result = "false";
                }
            }
            else if (httpMessage.map["0"] == "createkey")
            {
                Console.WriteLine("Please enter random word: ");
                string    input     = Console.ReadLine();
                WalletKey walletKey = new WalletKey();
                walletKey.random = CryptoHelper.Sha256(Seek().ToHexString() + "#" + input).HexToBytes();
                ed25519.ed25519_create_keypair(walletKey.publickey, walletKey.privatekey, walletKey.random);
                if (walletKey.random != null)
                {
                    Dictionary <string, string> walletinfo = new Dictionary <string, string>();
                    walletinfo.Add("address", walletKey.ToAddress());
                    walletinfo.Add("privatekey", walletKey.random.ToHexString());
                    httpMessage.result = JsonHelper.ToJson(walletinfo);
                    return;
                }
                httpMessage.result = "createkey error";
            }
            else if (httpMessage.map["0"] == "createwallet")
            {
                OnCreat(httpMessage);
            }
            else if (httpMessage.map["0"] == "mempool")
            {
                HttpMessage result = await ComponentNetworkHttp.QueryCommand(Program.ruleIP + $"/{httpMessage.map["cmd"]}", httpMessage);

                httpMessage.result = result.result;
            }
            else if (httpMessage.map["0"] == "getlastblock")
            {
                try
                {
                    if (!GetParam(httpMessage, "1", "index", out string index))
                    {
                        httpMessage.result = "command error! \nexample: getlastblock index";
                        return;
                    }
                    string height = await GetHeightAsync();

                    httpMessage.map["1"] = (long.Parse(height) - 19 * long.Parse(httpMessage.map["1"])) != 0 ? (long.Parse(height) - 19 * long.Parse(httpMessage.map["1"])).ToString() : "0";
                    HttpMessage result = await ComponentNetworkHttp.QueryCommand(Program.ruleIP + $"/{httpMessage.map["cmd"]}", httpMessage);

                    httpMessage.result = result.result;
                } catch (Exception e)
                {
                    httpMessage.result = "command error! \nexample: getlastblock index";
                }
            }
            else if (httpMessage.map["0"] == "transfercount")
            {
                HttpMessage result = await ComponentNetworkHttp.QueryCommand(Program.ruleIP + $"/{httpMessage.map["cmd"]}", httpMessage);

                httpMessage.result = result.result;
            }
            else if (httpMessage.map["0"] == "search")
            {
                HttpMessage result = await ComponentNetworkHttp.QueryCommand(Program.ruleIP + $"/{httpMessage.map["cmd"]}", httpMessage);

                httpMessage.result = result.result;
            }
            else if (httpMessage.map["0"] == "miner")
            {
                HttpMessage result = await ComponentNetworkHttp.QueryCommand(Program.ruleIP + $"/{httpMessage.map["cmd"]}", httpMessage);

                httpMessage.result = result.result;
            }
            else if (httpMessage.map["0"] == "node")
            {
                HttpMessage result = await ComponentNetworkHttp.QueryCommand(Program.ruleIP + $"/{httpMessage.map["cmd"]}", httpMessage);

                httpMessage.result = result.result;
            }
            else if (httpMessage.map["0"] == "beruler")
            {
                HttpMessage result = await ComponentNetworkHttp.QueryCommand(Program.ruleIP + $"/{httpMessage.map["cmd"]}", httpMessage);

                httpMessage.result = result.result;
            }
            else if (httpMessage.map["0"] == "rules")
            {
                HttpMessage result = await ComponentNetworkHttp.QueryCommand(Program.ruleIP + $"/{httpMessage.map["cmd"]}", httpMessage);

                httpMessage.result = result.result;
            }
            else if (httpMessage.map["0"] == "stats")
            {
                HttpMessage result = await ComponentNetworkHttp.QueryCommand(Program.ruleIP + $"/{httpMessage.map["cmd"]}", httpMessage);

                httpMessage.result = result.result;
            }
            else if (httpMessage.map["0"] == "account")
            {
                HttpMessage result = await ComponentNetworkHttp.QueryCommand(Program.ruleIP + $"/{httpMessage.map["cmd"]}", httpMessage);

                httpMessage.result = result.result;
            }
            else if (httpMessage.map["0"] == "help")
            {
                OnHelp(httpMessage);
            }
            else
            {
                httpMessage.result = "command error";
            }
        }
Ejemplo n.º 13
0
        public async void Run()
        {
            Program.DisbleQuickEditMode();
            Console.Clear();
            Console.CursorVisible = false;
            Console.Title         = $" address:{address} number:{number}  poolUrl:{poolUrl}";

            await Task.Delay(1000);

            //创建后台工作线程
            for (int ii = 0; ii < 16; ii++)
            {
                System.Threading.Thread thread = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(Mining));
                thread.IsBackground = true;//设置为后台线程
                thread.Start(this);
            }

            HttpMessage quest = new HttpMessage();

            quest.map = new Dictionary <string, string>();

            while (true)
            {
                try
                {
                    if (timePass.IsPassSet())
                    {
                        string hash = CryptoHelper.Sha256(hashmining + random);
                        Log.Debug($"\n height:{height}, taskid:{taskid}, random:{random}, diff:{diff_max}, power:{calculatePower.GetPower()} hash:{hash}");
                    }

                    quest.map.Clear();
                    quest.map.Add("cmd", "submit");
                    quest.map.Add("height", height.ToString());
                    quest.map.Add("address", address);
                    quest.map.Add("number", number);
                    quest.map.Add("random", random);
                    quest.map.Add("taskid", taskid);
                    HttpMessage result = await ComponentNetworkHttp.Query(poolUrl, quest);

                    if (result.map != null)
                    {
                        if (result.map.ContainsKey("taskID"))
                        {
                            long.TryParse(result.map["height"], out long tempheight);
                            taskid = result.map["taskID"];
                            string temphash = result.map["hashmining"];
                            if (temphash == null || temphash == "" || temphash != hashmining)
                            {
                                if (diff_max != 0)
                                {
                                    calculatePower.Insert(diff_max);
                                }

                                diff_max   = 0;
                                hashmining = temphash;
                                height     = tempheight;
                                random     = "";
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    Log.Error(e);
                }
                await Task.Delay(1000);
            }
        }
Ejemplo n.º 14
0
        public async void Run()
        {
            Program.DisbleQuickEditMode();
            Console.Clear();
            Console.CursorVisible = false;
            Console.Title         = $" address:{address},thread:{thread}, number:{number}, poolUrl:{poolUrl}";

            Log.Info($"start mining...");

            await Task.Delay(1000);

            //创建后台工作线程
            for (int ii = 0; ii < thread; ii++)
            {
                System.Threading.Thread thread = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(Mining));
                thread.IsBackground = true;//设置为后台线程
                thread.Start(this);
            }

            HttpMessage quest = new HttpMessage();

            quest.map = new Dictionary <string, string>();

            while (true)
            {
                try
                {
                    if (timePassInfo.IsPassSet())
                    {
                        string hash = CryptoHelper.Sha256(hashmining + random);
                        Log.Info($"\n height:{height}, taskid:{taskid}, random:{random}, diff:{diff_max}, power:{calculatePower.GetPower()} hash:{hash}");
                    }

                    quest.map.Clear();
                    quest.map.Add("cmd", "submit");
                    quest.map.Add("height", height.ToString());
                    quest.map.Add("address", address);
                    quest.map.Add("number", number);
                    quest.map.Add("random", random);
                    quest.map.Add("taskid", taskid);
                    quest.map.Add("average", calculatePower.GetPowerDouble().ToString());
                    HttpMessage result = null;
                    try
                    {
                        result = await ComponentNetworkHttp.Query($"http://{poolUrl}/mining", quest);
                    }
                    catch (Exception)
                    {
                        if (timePassDebug.IsPassSet())
                        {
                            Log.Warning($"\n Unable to open the network connection http://{poolUrl}/mining");
                        }
                    }
                    if (result != null && result.map != null)
                    {
                        if (result.map.ContainsKey("taskid"))
                        {
                            if (result.map.ContainsKey("number"))
                            {
                                number        = result.map["number"];
                                Console.Title = $" address:{address},thread:{thread}, number:{number}, poolUrl:{poolUrl}";
                            }

                            long.TryParse(result.map["height"], out long tempheight);
                            taskid = result.map["taskid"];
                            string temphash = result.map["hashmining"];

                            if (temphash == null || temphash == "" || temphash != hashmining)
                            {
                                if (diff_max != 0)
                                {
                                    calculatePower.Insert(diff_max);
                                }

                                diff_max   = 0;
                                hashmining = temphash;
                                height     = tempheight;
                                random     = "";

                                result.map.TryGetValue("power", out poolPower);
                                changeCallback?.Invoke();
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    Log.Error(e);
                }
                await Task.Delay(intervalTime);
            }
        }
Ejemplo n.º 15
0
        public async Task Submit(HttpMessage quest)
        {
            quest.map.Clear();
            quest.map.Add("cmd", "submit");
            quest.map.Add("version", version);
            quest.map.Add("height", height.ToString());
            quest.map.Add("address", address);
            quest.map.Add("number", number);
            quest.map.Add("random", random);
            quest.map.Add("taskid", taskid);
            quest.map.Add("average", calculatePower.GetPowerDouble().ToString());
            HttpMessage result = null;

            try
            {
                result = await ComponentNetworkHttp.Query($"http://{poolUrl}/mining", quest);
            }
            catch (Exception)
            {
                if (timePassDebug.IsPassSet())
                {
                    Log.Warning($"\n Unable to open the network connection http://{poolUrl}/mining");
                    StopMining();
                    await Task.Delay(15000);
                }
            }
            if (result != null && result.map != null)
            {
                if (result.map.ContainsKey("tips"))
                {
                    Log.Warning($"{result.map["tips"]}");
                    await Task.Delay(5000);
                }

                if (result.map["report"] == "error")
                {
                    Log.Warning($"{result.map["tips"]}");
                    await Task.Delay(5000);
                }

                if (result.map.ContainsKey("minerLimit"))
                {
                    if (timePassDebug.IsPassSet())
                    {
                        Log.Warning($"\n http://{poolUrl}/mining is full");
                        StopMining();
                        await Task.Delay(15000);
                    }
                }
                else
                if (result.map.ContainsKey("taskid"))
                {
                    if (result.map.ContainsKey("number"))
                    {
                        number = result.map["number"];
                        SetTitle($" address:{address},thread:{thread}, number:{number}, poolUrl:{poolUrl}, version:{version}");
                    }

                    long.TryParse(result.map["height"], out long tempheight);
                    taskid = result.map["taskid"];
                    string temphash = result.map["hashmining"];

                    if (temphash == null || temphash == "" || temphash != hashmining)
                    {
                        if (result.map.TryGetValue("power", out string smypower) && double.TryParse(smypower, out double dmypower))
                        {
                            submitCount++;
                            calculatePower.InsertPower(dmypower);
                            if (dmypower != 0)
                            {
                                effectiveShare++;
                            }
                            else
                            {
                                //calculatePower.Clear();
                            }
                        }

                        hashmining          = temphash;
                        hashmining_last     = temphash;
                        height              = tempheight;
                        diff_max            = 0;
                        diff_max_lastSubmit = 0;
                        random              = "";

                        for (int ii = 0; ii < thread; ii++)
                        {
                            lock (ThreadDataList[ii])
                            {
                                ThreadDataList[ii].diff_max   = 0;
                                ThreadDataList[ii].random     = "";
                                ThreadDataList[ii].hashmining = hashmining;
                            }
                        }

                        if (result.map.ContainsKey("nodeTime"))
                        {
                            long.TryParse(result.map["nodeTime"], out nodeTimeOffset);
                        }

                        result.map.TryGetValue("poolPower", out poolPower);
                        changeCallback?.Invoke();
                    }
                }
            }
        }
Ejemplo n.º 16
0
 public override void Start()
 {
     networkHttp = this.entity.GetComponent <ComponentNetworkHttp>();
     Log.Info($"HttpRpc http://{networkHttp.ipEndPoint}/");
     HttpService.ReplaceFunc = ReplaceFunc;
 }