Advertisement
Guest User

Untitled

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