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); } } }