Skip to content
Permalink
Browse files

Work around Network Devices that do not return a "Hash Method" key in…

… their response to the "COIN" API request

* see: #336
* see: https://github.com/ckolivas/cgminer/blob/master/API-README
  • Loading branch information...
nwoolls committed Jan 20, 2018
1 parent 04a7855 commit 59098de442d78efa9c7dc3280fec55f29c544510
@@ -53,6 +53,7 @@
<ItemGroup>
<Compile Include="DeviceInformationParserTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="NetworkCoinInformationParserTests.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\MultiMiner.Xgminer.Api\MultiMiner.Xgminer.Api.csproj">
@@ -0,0 +1,24 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MultiMiner.Xgminer.Api.Data;
using MultiMiner.Xgminer.Api.Parsers;

namespace MultiMiner.Xgminer.Api.Tests
{
[TestClass]
public class NetworkCoinInformationParserTests
{
[TestMethod]
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,6 +4,8 @@ namespace MultiMiner.Xgminer.Api.Data
{
public class NetworkCoinInformation
{
public const string UnknownAlgorithm = "unknown";

public string Algorithm { get; set; }
public long CurrentBlockTime { get; set; }
public string CurrentBlockHash { get; set; }
@@ -5,7 +5,7 @@

namespace MultiMiner.Xgminer.Api.Parsers
{
class NetworkCoinInformationParser : ResponseTextParser
public class NetworkCoinInformationParser : ResponseTextParser
{
public static void ParseTextForCoinNetworkInformation(string text, NetworkCoinInformation coinInformation)
{
@@ -21,7 +21,18 @@ public static void ParseTextForCoinNetworkInformation(string text, NetworkCoinIn

keyValuePairs = GetDictionaryFromTextChunk(textChunks[1]);

coinInformation.Algorithm = keyValuePairs["Hash Method"];
// user reported a network device that does / may not return "Hash Method"
// see: https://github.com/nwoolls/MultiMiner/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);

0 comments on commit 59098de

Please sign in to comment.
You can’t perform that action at this time.