forked from nwoolls/MultiMiner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ApiContext.cs
73 lines (61 loc) · 2.47 KB
/
ApiContext.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
using MultiMiner.CoinApi;
using MultiMiner.CoinApi.Data;
using MultiMiner.Utility.Net;
using MultiMiner.WhatToMine.Extensions;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
namespace MultiMiner.WhatToMine
{
public class ApiContext : IApiContext
{
public static string ScryptNFactor = "Scrypt-N";
private readonly string urlParms;
public ApiContext(string urlParms = "")
{
this.urlParms = urlParms;
}
public IEnumerable<CoinInformation> GetCoinInformation(string userAgent = "")
{
ApiWebClient client = new ApiWebClient();
if (!string.IsNullOrEmpty(userAgent))
client.Headers.Add("user-agent", userAgent);
//get GPU coin info (scrypt, X11, etc)
string jsonString = client.DownloadString(GetApiUrl());
Data.ApiResponse apiResponse = JsonConvert.DeserializeObject<Data.ApiResponse>(jsonString);
//merge in ASIC coin info (sha-256, scrypt, etc)
jsonString = client.DownloadString(GetAsicApiUrl());
Data.ApiResponse asicApiResponse = JsonConvert.DeserializeObject<Data.ApiResponse>(jsonString);
foreach (string coinName in asicApiResponse.Coins.Keys)
apiResponse.Coins[coinName] = asicApiResponse.Coins[coinName];
List<CoinInformation> result = new List<CoinInformation>();
foreach (string coinName in apiResponse.Coins.Keys)
{
CoinInformation coinInformation = new CoinInformation();
coinInformation.Name = coinName;
coinInformation.PopulateFromJson(apiResponse.Coins[coinName]);
if (coinInformation.Difficulty > 0)
//only add coins with valid info since the user may be basing
//strategies on Difficulty
result.Add(coinInformation);
}
return result;
}
public string GetApiUrl()
{
return String.Format(@"https://www.whattomine.com/coins.json?{0}", urlParms);
}
public string GetAsicApiUrl()
{
return String.Format(@"https://www.whattomine.com/asic.json?{0}", urlParms);
}
public string GetInfoUrl()
{
return "https://www.whattomine.com/";
}
public string GetApiName()
{
return "WhatToMine.com";
}
}
}