103 lines
2.2 KiB
C#
103 lines
2.2 KiB
C#
|
using System;
|
|||
|
using sharp.cryptonote.rpc;
|
|||
|
using sharp.cryptonote;
|
|||
|
using Newtonsoft.Json.Linq;
|
|||
|
using System.IO;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
|
|||
|
|
|||
|
namespace SharpMining
|
|||
|
{
|
|||
|
public class SharpMining
|
|||
|
{
|
|||
|
public static void Main(String[] args)
|
|||
|
{
|
|||
|
if (args.Length > 1){
|
|||
|
Console.WriteLine("usage: SharpMining.exe <config.json>");
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
SharpMining sm = new SharpMining(args);
|
|||
|
sm.Run();
|
|||
|
}
|
|||
|
|
|||
|
private String configFileName;
|
|||
|
private JToken config;
|
|||
|
|
|||
|
private List<MiningPool> pools;
|
|||
|
private List<StratumListener> stratums;
|
|||
|
|
|||
|
public SharpMining(String[] args){
|
|||
|
if (args.Length == 0){
|
|||
|
configFileName = "sharpmining.json";
|
|||
|
} else if (args.Length == 1){
|
|||
|
configFileName = args[0];
|
|||
|
};
|
|||
|
this.config = JToken.Parse(File.ReadAllText(configFileName));
|
|||
|
this.pools = new List<MiningPool>();
|
|||
|
this.stratums = new List<StratumListener>();
|
|||
|
}
|
|||
|
|
|||
|
public void Run(){
|
|||
|
CreatePools();
|
|||
|
CreateStratums();
|
|||
|
|
|||
|
foreach (MiningPool pool in this.pools){
|
|||
|
Console.WriteLine("Running Pool for {0} with Pool-Wallet {1}",pool.Coin,pool.PoolWallet.ToString());
|
|||
|
}
|
|||
|
|
|||
|
foreach (StratumListener l in this.stratums){
|
|||
|
Console.WriteLine("Started Stratum Listener [{0}] for Pools:",l.LocalEndpoint.ToString());
|
|||
|
foreach(MiningPool pool in l.AssociatedPools){
|
|||
|
Console.WriteLine(" -> {0}", pool.ToString());
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
public StratumListener[] Stratums { get { return this.stratums.ToArray(); } }
|
|||
|
|
|||
|
public void CreatePools(){
|
|||
|
foreach (JToken pool in config["pools"])
|
|||
|
{
|
|||
|
this.pools.Add(new MiningPool(pool));
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public void CreateStratums(){
|
|||
|
|
|||
|
foreach (JToken dc in config["stratums"]){
|
|||
|
StratumListener stratum = new StratumListener(dc);
|
|||
|
|
|||
|
if (dc["coins"].Equals(JValue.CreateNull())){
|
|||
|
foreach (MiningPool p in this.pools){
|
|||
|
stratum.associatePool(p);
|
|||
|
}
|
|||
|
} else {
|
|||
|
foreach (JToken c in dc["coins"]){
|
|||
|
CryptoNoteCoin coin = c.ToObject<CryptoNoteCoin>();
|
|||
|
stratum.associatePool( findPool(coin) );
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
stratums.Add(stratum);
|
|||
|
stratum.Start();
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
public MiningPool findPool(CryptoNoteCoin coin){
|
|||
|
foreach (MiningPool p in this.pools){
|
|||
|
if (p.Coin.Equals(coin)){
|
|||
|
return p;
|
|||
|
}
|
|||
|
}
|
|||
|
return null;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
}
|