예제 #1
0
        public static void ParseTextForCoinNetworkInformation(string text, NetworkCoinInformation coinInformation)
        {
            List <string> responseParts = ParseResponseText(text);

            if (responseParts.Count == 0)
            {
                return;
            }

            foreach (string responsePart in responseParts)
            {
                List <string> textChunks = text.Split('|').ToList();

                Dictionary <string, string> keyValuePairs = GetDictionaryFromTextChunk(textChunks[0]);

                keyValuePairs = GetDictionaryFromTextChunk(textChunks[1]);

                // user reported a network device that does / may not return "Hash Method"
                // see: https://github.com/nwoolls/LiquidHash/issues/336
                const string hashMethodKey = "Hash Method";
                if (keyValuePairs.ContainsKey(hashMethodKey))
                {
                    coinInformation.Algorithm = keyValuePairs[hashMethodKey];
                }
                else
                {
                    coinInformation.Algorithm = NetworkCoinInformation.UnknownAlgorithm;
                }

                coinInformation.CurrentBlockTime  = TryToParseInt(keyValuePairs, "Current Block Time", 0);
                coinInformation.CurrentBlockHash  = keyValuePairs["Current Block Hash"];
                coinInformation.LongPoll          = keyValuePairs["LP"].Equals("true", StringComparison.OrdinalIgnoreCase);
                coinInformation.NetworkDifficulty = TryToParseDouble(keyValuePairs, "Network Difficulty", 0.0);
            }
        }
예제 #2
0
        public NetworkCoinInformation GetCoinInformation()
        {
            string textResponse           = GetResponse(ApiVerb.Coin);
            NetworkCoinInformation result = new NetworkCoinInformation();

            NetworkCoinInformationParser.ParseTextForCoinNetworkInformation(textResponse, result);
            return(result);
        }
예제 #3
0
        public void ParseTextForCoinNetworkInformation_Without_HashMethod_Succeeds()
        {
            // arrange
            var coinInformation = new NetworkCoinInformation();
            var apiText         = @"STATUS=S,When=1516477474,Code=78,Msg=CGMiner coin,Description=cgminer 3.12.0|COIN,Current Block Time=1516477181.246917,Current Block Hash=000000000000000000475404549c265739ae2da0cd176f6a60a3f2cff8c4823c,LP=true,Network Difficulty=2227847638503.62830000|";

            // act
            NetworkCoinInformationParser.ParseTextForCoinNetworkInformation(apiText, coinInformation);

            // assert
            Assert.AreEqual(NetworkCoinInformation.UnknownAlgorithm, coinInformation.Algorithm);
        }
예제 #4
0
        public static void ParseTextForCoinNetworkInformation(string text, NetworkCoinInformation coinInformation)
        {
            List <string> deviceBlob = text.Split('|').ToList();

            deviceBlob.RemoveAt(0);

            foreach (string deviceText in deviceBlob)
            {
                List <string> textChunks = text.Split('|').ToList();

                Dictionary <string, string> keyValuePairs = GetDictionaryFromTextChunk(textChunks[0]);

                keyValuePairs = GetDictionaryFromTextChunk(textChunks[1]);

                coinInformation.Algorithm         = keyValuePairs["Hash Method"].Equals("scrypt", StringComparison.OrdinalIgnoreCase) ? Xgminer.Data.CoinAlgorithm.Scrypt : Xgminer.Data.CoinAlgorithm.SHA256;
                coinInformation.CurrentBlockTime  = TryToParseInt(keyValuePairs, "Current Block Time", 0);
                coinInformation.CurrentBlockHash  = keyValuePairs["Current Block Hash"];
                coinInformation.LongPoll          = keyValuePairs["LP"].Equals("true", StringComparison.OrdinalIgnoreCase);
                coinInformation.NetworkDifficulty = TryToParseDouble(keyValuePairs, "Network Difficulty", 0.0);
            }
        }
예제 #5
0
        public static void ParseTextForCoinNetworkInformation(string text, NetworkCoinInformation coinInformation)
        {
            List <string> responseParts = ParseResponseText(text);

            if (responseParts.Count == 0)
            {
                return;
            }

            foreach (string responsePart in responseParts)
            {
                List <string> textChunks = text.Split('|').ToList();

                Dictionary <string, string> keyValuePairs = GetDictionaryFromTextChunk(textChunks[0]);

                keyValuePairs = GetDictionaryFromTextChunk(textChunks[1]);

                coinInformation.Algorithm         = keyValuePairs["Hash Method"];
                coinInformation.CurrentBlockTime  = TryToParseInt(keyValuePairs, "Current Block Time", 0);
                coinInformation.CurrentBlockHash  = keyValuePairs["Current Block Hash"];
                coinInformation.LongPoll          = keyValuePairs["LP"].Equals("true", StringComparison.OrdinalIgnoreCase);
                coinInformation.NetworkDifficulty = TryToParseDouble(keyValuePairs, "Network Difficulty", 0.0);
            }
        }