69 lines
1.5 KiB
C#
69 lines
1.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using sharp.cryptonote.rpc;
|
|
using sharp.cryptonote;
|
|
using Newtonsoft.Json.Linq;
|
|
namespace SharpMining
|
|
{
|
|
public class MiningPool
|
|
{
|
|
JToken poolConfig;
|
|
List<Daemon> daemons;
|
|
|
|
public Daemon[] Daemons { get { return this.daemons.ToArray(); } }
|
|
public WorkManager WorkManager { get; private set; }
|
|
public CryptoNoteAddress PoolWallet { get; private set; }
|
|
public Dictionary<CryptoNoteCoin, StratumListener> assignedStratums;
|
|
|
|
public MiningPool(JToken poolConfig)
|
|
{
|
|
this.poolConfig = poolConfig;
|
|
|
|
this.daemons = new List<Daemon>();
|
|
this.assignedStratums = new Dictionary<CryptoNoteCoin, StratumListener>();
|
|
|
|
this.Coin = (CryptoNoteCoin)Enum.Parse(typeof(CryptoNoteCoin), poolConfig["pool"]["coin"].ToObject<string>());
|
|
this.PoolWallet = new CryptoNoteAddress(poolConfig["pool"]["wallet"].ToObject<string>());
|
|
|
|
this.WorkManager = new WorkManager(this);
|
|
|
|
CreateDaemonRPC();
|
|
}
|
|
|
|
public CryptoNoteCoin Coin { get; private set; }
|
|
|
|
|
|
public void CreateDaemonRPC()
|
|
{
|
|
|
|
foreach (JToken dc in poolConfig["daemons"])
|
|
{
|
|
Daemon daemon = new Daemon(dc["host"].ToString(), dc["port"].ToObject<int>());
|
|
daemons.Add(daemon);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
public Daemon getCheckedDaemon()
|
|
{
|
|
foreach (Daemon daemon in this.daemons)
|
|
{
|
|
if (daemon.check())
|
|
{
|
|
return daemon;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public override string ToString()
|
|
{
|
|
return string.Format("[MiningPool: Coin={0}, PoolWallet={1}]", Coin, PoolWallet);
|
|
}
|
|
|
|
|
|
}
|
|
|
|
}
|