Advertisement
Guest User

Untitled

a guest
Nov 14th, 2016
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.76 KB | None | 0 0
  1. Console.WriteLine("result");
  2.  
  3. public class Program
  4. {
  5. static Pool _pool = null;
  6. static Work _work = null;
  7. static uint _nonce = 0;
  8. static long _maxAgeTicks = 20000 * TimeSpan.TicksPerMillisecond;
  9. static uint _batchSize = 100000;
  10.  
  11. public static void Main(string[] args)
  12. {
  13. while (true)
  14. {
  15. try
  16. {
  17. _pool = SelectPool();
  18. _work = GetWork();
  19. while (true)
  20. {
  21. if (_work == null || _work.Age > _maxAgeTicks)
  22. _work = GetWork();
  23.  
  24. if (_work.FindShare(ref _nonce, _batchSize))
  25. {
  26. SendShare(_work.Current);
  27. _work = null;
  28. }
  29. else
  30. PrintCurrentState();
  31. }
  32. }
  33. catch (Exception e)
  34. {
  35. Console.WriteLine();
  36. Console.Write("ERROR: ");
  37. Console.WriteLine(e.Message);
  38. }
  39. Console.WriteLine();
  40. Console.Write("Hit 'Enter' to try again...");
  41. Console.ReadLine();
  42. System.Threading.Thread.Sleep(5000);
  43. }
  44. }
  45.  
  46.  
  47. private static void ClearConsole()
  48. {
  49. Console.Clear();
  50. Console.WriteLine("*****************************");
  51. Console.WriteLine("*** Minimal Bitcoin Miner ***");
  52. Console.WriteLine("*****************************");
  53. Console.WriteLine();
  54. }
  55.  
  56. private static Pool SelectPool()
  57. {
  58. ClearConsole();
  59. Print("Chose a Mining Pool 'user:password@url:port' or leave empty to skip.");
  60. //Console.Write("Select Pool: ");
  61. string login = "";
  62. //string login = ReadLineDefault("lithander_2:foo@btcguild.com:8332");
  63. return new Pool(login);
  64. }
  65.  
  66. private static Work GetWork()
  67. {
  68. ClearConsole();
  69. Print("Requesting Work from Pool...");
  70. Print("Server URL: " + _pool.Url.ToString());
  71. Print("User: " + _pool.User);
  72. Print("Password: " + _pool.Password);
  73. return _pool.GetWork();
  74. }
  75.  
  76. private static void SendShare(byte[] share)
  77. {
  78. ClearConsole();
  79. Print("*** Found Valid Share ***");
  80. Print("Share: " + Utils.ToString(_work.Current));
  81. Print("Nonce: " + Utils.ToString(_nonce));
  82. Print("Hash: " + Utils.ToString(_work.Hash));
  83. Print("Sending Share to Pool...");
  84. if (_pool.SendShare(share))
  85. Print("Server accepted the Share!");
  86. else
  87. Print("Server declined the Share!");
  88.  
  89. Console.Write("Hit 'Enter' to continue...");
  90. Console.ReadLine();
  91. }
  92.  
  93. private static DateTime _lastPrint = DateTime.Now;
  94. private static void PrintCurrentState()
  95. {
  96. ClearConsole();
  97. Print("Data: " + Utils.ToString(_work.Data));
  98. string current = Utils.ToString(_nonce);
  99. string max = Utils.ToString(uint.MaxValue);
  100. double progress = ((double)_nonce / uint.MaxValue) * 100;
  101. Print("Nonce: " + current + "/" + max + " " + progress.ToString("F2") + "%");
  102. Print("Hash: " + Utils.ToString(_work.Hash));
  103. TimeSpan span = DateTime.Now - _lastPrint;
  104. Print("Speed: " + (int)(((_batchSize) / 1000) / span.TotalSeconds) + "Kh/s");
  105. _lastPrint = DateTime.Now;
  106. }
  107.  
  108. private static void Print(string msg)
  109. {
  110. Console.WriteLine(msg);
  111. Console.WriteLine();
  112. }
  113.  
  114. private static string ReadLineDefault(string defaultValue)
  115. {
  116. //Allow Console.ReadLine with a default value
  117. string userInput = Console.ReadLine();
  118. Console.WriteLine();
  119. if (userInput == "")
  120. return defaultValue;
  121. else
  122. return userInput;
  123. }
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement