WorkBlock GetWork() { /* * HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://127.0.0.1:8332/"); * req.TransferEncoding = ""; * req.ServicePoint.UseNagleAlgorithm = false; * req.Method = "POST"; * req.ContentType = "application/json"; * req.Expect = ""; * req.Credentials = new NetworkCredential("rpcuser", "rpcpass"); * * StreamWriter sw = new StreamWriter(req.GetRequestStream()); * sw.Write("{\"method\": \"getwork\", \"params\": [], \"id\":0}\r\n"); * sw.Close(); * * HttpWebResponse resp = (HttpWebResponse)req.GetResponse(); * StreamReader sr = new StreamReader(resp.GetResponseStream(), Encoding.Default); * * string str = sr.ReadToEnd(); * Console.WriteLine(str); * WorkBlock work = new WorkBlock(str); * * sr.Close(); */ BitnetClient bc = new BitnetClient("http://127.0.0.1:8332"); bc.Credentials = new NetworkCredential("rpcuser", "rpcpass"); JObject obj = bc.GetWork(); WorkBlock work = new WorkBlock(obj); return(work); }
void DoWork(WorkBlock work) { byte[] data = new byte[64]; Array.Copy(work.data, 64, data, 0, 64); uint[] midstate = ByteArrayToUIntArray(work.midstate, 0); uint[] targetA = ByteArrayToUIntArray(work.target, 0); uint[] targetSwapped = new uint[8]; for( int i = 0; i < 8; i++ ) targetSwapped[i] = targetA[7 - i]; uint max = 0xFFFFFFFF; long start, end, freq; Win32Wrapper.QueryPerformanceFrequency(out freq); Win32Wrapper.QueryPerformanceCounter(out start); for(uint n = 0; n < max; n++) { WriteUIntToByteArray(n, data, 12); uint[] output = new uint[8]; SHATransform(output, data, midstate); byte[] input = new byte[64]; Buffer.BlockCopy(output, 0, input, 0, 32); Buffer.BlockCopy(work.hash1, 32, input, 32, 32); SHATransform(output, input, staticData); if (output[7] == 0) { uint[] swapped = new uint[8]; for (int i = 0; i < 8; i++) { swapped[i] = Program.Byteswap(output[7 - i]); } for (int i = 1; i < 8; i++) { if (swapped[i] < targetSwapped[i]) { // Found a solution WriteUIntToByteArray(n, work.data, 76); // Write the nonce value into the data block return; } if (swapped[i] > targetSwapped[i]) break; } } } Win32Wrapper.QueryPerformanceCounter(out end); long clocks = end - start; double seconds = (double)clocks / (double)freq; double hashesPerSecond = max / seconds; Console.WriteLine(hashesPerSecond.ToString() + " hashes per second"); }
void SubmitWork(WorkBlock work) { //string dataStr = HashToString(work.data) BitnetClient bc = new BitnetClient("http://127.0.0.1:8332"); bc.Credentials = new NetworkCredential("rpcuser", "rpcpass"); //bc. }
void TryToMine() { // Get work from bitcoind //WorkBlock work = GetWork(); // Do the work WorkBlock work = new WorkBlock("{\"result\":{\"midstate\":\"22d199f12b6740fe0e4eb1275ba82bc7b14986d10e6eb0713169af562fb0ed90\",\"data\":\"00000002b99861098395d933f3a8ec454810dc49c8129f21e94f9ccb0000000000000000d879e26cdf479fbf18aa9c39ac6a87e2b14040093fbbbfde1f779577bed7d7ec530d2a2319015f5300000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000080020000\",\"hash1\":\"00000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000010000\",\"target\":\"00000000000000000000000000000000000000000000535f0100000000000000\"},\"error\":null,\"id\":0}"); DoWork(work); // Submit the work //SubmitWork(work); }
WorkBlock GetWork() { /* HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://127.0.0.1:8332/"); req.TransferEncoding = ""; req.ServicePoint.UseNagleAlgorithm = false; req.Method = "POST"; req.ContentType = "application/json"; req.Expect = ""; req.Credentials = new NetworkCredential("rpcuser", "rpcpass"); StreamWriter sw = new StreamWriter(req.GetRequestStream()); sw.Write("{\"method\": \"getwork\", \"params\": [], \"id\":0}\r\n"); sw.Close(); HttpWebResponse resp = (HttpWebResponse)req.GetResponse(); StreamReader sr = new StreamReader(resp.GetResponseStream(), Encoding.Default); string str = sr.ReadToEnd(); Console.WriteLine(str); WorkBlock work = new WorkBlock(str); sr.Close(); */ BitnetClient bc = new BitnetClient("http://127.0.0.1:8332"); bc.Credentials = new NetworkCredential("rpcuser", "rpcpass"); JObject obj = bc.GetWork(); WorkBlock work = new WorkBlock(obj); return work; }
void DoWork(WorkBlock work) { byte[] data = new byte[64]; Array.Copy(work.data, 64, data, 0, 64); uint[] midstate = ByteArrayToUIntArray(work.midstate, 0); uint[] targetA = ByteArrayToUIntArray(work.target, 0); uint[] targetSwapped = new uint[8]; for (int i = 0; i < 8; i++) { targetSwapped[i] = targetA[7 - i]; } uint max = 0xFFFFFFFF; long start, end, freq; Win32Wrapper.QueryPerformanceFrequency(out freq); Win32Wrapper.QueryPerformanceCounter(out start); for (uint n = 0; n < max; n++) { WriteUIntToByteArray(n, data, 12); uint[] output = new uint[8]; SHATransform(output, data, midstate); byte[] input = new byte[64]; Buffer.BlockCopy(output, 0, input, 0, 32); Buffer.BlockCopy(work.hash1, 32, input, 32, 32); SHATransform(output, input, staticData); if (output[7] == 0) { uint[] swapped = new uint[8]; for (int i = 0; i < 8; i++) { swapped[i] = Program.Byteswap(output[7 - i]); } for (int i = 1; i < 8; i++) { if (swapped[i] < targetSwapped[i]) { // Found a solution WriteUIntToByteArray(n, work.data, 76); // Write the nonce value into the data block return; } if (swapped[i] > targetSwapped[i]) { break; } } } } Win32Wrapper.QueryPerformanceCounter(out end); long clocks = end - start; double seconds = (double)clocks / (double)freq; double hashesPerSecond = max / seconds; Console.WriteLine(hashesPerSecond.ToString() + " hashes per second"); }