From 39730af42aa09d9d056d5b83eada544269347642 Mon Sep 17 00:00:00 2001 From: Harald Wolff Date: Mon, 18 Sep 2017 11:28:07 +0200 Subject: [PATCH] Initial Commit --- .gitignore | 40 ++++++++++++++++++++++++ README.md | 5 +++ SharpMining.cs | 77 ++++++++++++++++++++++++++++++++++++++++++++++ SharpMining.csproj | 69 +++++++++++++++++++++++++++++++++++++++++ StratumListener.cs | 26 ++++++++++++++++ WorkManager.cs | 46 +++++++++++++++++++++++++++ daemon.cs | 10 ++++++ packages.config | 4 +++ sharpmining.json | 23 ++++++++++++++ 9 files changed, 300 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 SharpMining.cs create mode 100644 SharpMining.csproj create mode 100644 StratumListener.cs create mode 100644 WorkManager.cs create mode 100644 daemon.cs create mode 100644 packages.config create mode 100644 sharpmining.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4e82d27 --- /dev/null +++ b/.gitignore @@ -0,0 +1,40 @@ +# Autosave files +*~ + +# build +[Oo]bj/ +[Bb]in/ +packages/ +TestResults/ + +# globs +Makefile.in +*.DS_Store +*.sln.cache +*.suo +*.cache +*.pidb +*.userprefs +*.usertasks +config.log +config.make +config.status +aclocal.m4 +install-sh +autom4te.cache/ +*.user +*.tar.gz +tarballs/ +test-results/ +Thumbs.db + +# Mac bundle stuff +*.dmg +*.app + +# resharper +*_Resharper.* +*.Resharper + +# dotCover +*.dotCover diff --git a/README.md b/README.md new file mode 100644 index 0000000..93e64be --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ +# SharpMining +Mono/.NET Implementation of Monero Mining Pool + +more information to come... + diff --git a/SharpMining.cs b/SharpMining.cs new file mode 100644 index 0000000..52be8c6 --- /dev/null +++ b/SharpMining.cs @@ -0,0 +1,77 @@ +using System; +using cryptonote.rpc; +using 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 "); + return; + } + + SharpMining sm = new SharpMining(args); + sm.Run(); + } + + private String configFileName; + private JToken config; + + List daemons; + + 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.daemons = new List(); + + } + + public void Run(){ + CreateDaemonRPC(); + + WorkManager = new WorkManager(this); + + } + + public void CreateDaemonRPC(){ + + foreach (JToken dc in config["daemons"]){ + Daemon daemon = new Daemon(dc["host"].ToString(), dc["port"].ToObject()); + daemons.Add(daemon); + } + + } + + public Daemon[] Daemons { get { return this.daemons.ToArray(); } } + public WorkManager WorkManager { get; private set; } + + public Daemon getCheckedDaemon(){ + foreach (Daemon daemon in this.daemons){ + if (daemon.check()){ + return daemon; + } + } + return null; + } + + public String getPoolWalletAddress(){ + return config["pool"]["wallet"].ToObject(); + } + + + } +} diff --git a/SharpMining.csproj b/SharpMining.csproj new file mode 100644 index 0000000..f45cd95 --- /dev/null +++ b/SharpMining.csproj @@ -0,0 +1,69 @@ + + + + Debug + x86 + {5AE4E72A-253B-4FBD-AD5E-C038D57571D0} + Exe + SharpMining + SharpMining + v4.5 + + + true + full + true + bin\Debug + DEBUG; + prompt + 4 + x86 + + + true + bin\Release + prompt + 4 + x86 + + + + + + + + + ..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll + + + + + + + + + PreserveNewest + + + + + + {52C68C13-2DC2-438A-9EC1-E8C4953B07DF} + cryptonote + + + {DCE6066E-9709-4D12-8994-F7879C3557D6} + JSONRPC + + + + + + + + + + + + + \ No newline at end of file diff --git a/StratumListener.cs b/StratumListener.cs new file mode 100644 index 0000000..9e210c7 --- /dev/null +++ b/StratumListener.cs @@ -0,0 +1,26 @@ +using System; +using System.Net; +namespace SharpMining +{ + public class StratumListener + { + IPEndPoint endpoint; + + + public StratumListener(IPEndPoint endpoint) + { + this.endpoint = endpoint; + this.initialize(); + } + + public StratumListener(IPAddress bind,int port){ + this.endpoint = new IPEndPoint(bind, port); + this.initialize(); + } + + private void initialize(){ + + } + + } +} diff --git a/WorkManager.cs b/WorkManager.cs new file mode 100644 index 0000000..00f2856 --- /dev/null +++ b/WorkManager.cs @@ -0,0 +1,46 @@ +using System; +using System.Threading; +using cryptonote; +using cryptonote.rpc; +namespace SharpMining +{ + public class WorkManager + { + SharpMining sharpMining; + Thread thread; + + BlockTemplate currentTemplate; + + public WorkManager(SharpMining sharpMining) + { + this.sharpMining = sharpMining; + this.thread = new Thread(() => Run()); + this.thread.Start(); + } + + private void Run(){ + while (true){ + Thread.Sleep(2000); + Console.WriteLine("Checking for new work..."); + + Daemon daemon = sharpMining.getCheckedDaemon(); + if (daemon == null){ + Console.WriteLine("WorkManager: now Daemon available"); + } else { + BlockTemplate newTemplate = daemon.getBlockTemplate(sharpMining.getPoolWalletAddress(), 128); + Console.WriteLine("current target height is {0}",newTemplate.Height); + + if ((currentTemplate == null) || (currentTemplate.Height != newTemplate.Height)){ + changeCurrentBlock(newTemplate); + } + } + } + } + + public void changeCurrentBlock(BlockTemplate blockTemplate){ + currentTemplate = blockTemplate; + Console.WriteLine("new block target height: {0} target difficulty: {1} [0x{1:x}]",blockTemplate.Height,blockTemplate.Difficulty,blockTemplate.Difficulty); + } + + } +} diff --git a/daemon.cs b/daemon.cs new file mode 100644 index 0000000..517c39e --- /dev/null +++ b/daemon.cs @@ -0,0 +1,10 @@ +using System; +namespace SharpMining +{ + public class daemon + { + public daemon() + { + } + } +} diff --git a/packages.config b/packages.config new file mode 100644 index 0000000..e157ba1 --- /dev/null +++ b/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/sharpmining.json b/sharpmining.json new file mode 100644 index 0000000..ec2a6fa --- /dev/null +++ b/sharpmining.json @@ -0,0 +1,23 @@ +{ + daemons: [ + { host: "10.0.0.1", port: 18081 }, + { host: "10.118.0.1", port: 18081 } + ], + + wallets: [ + { host: "10.0.0.1", port: 18082 }, + ], + + rpc: { + bind: "127.0.0.1", + port: "8880" + }, + + pool: { +// wallet: null + wallet: "45YKUs6Lr8562D1vwUfVGPZR7RZp4vqnL95XMvZJEnjREiwEjs8RscC8Djxg5jRzbDAnbK6A9Z9M9VTeMjn9EG1D4Ly7U4i" + }, + + + contact: "info@lupus-nobilis.de" +} \ No newline at end of file