void SendVersionPacket() { IPEndPoint remote = (IPEndPoint)mSocket.RemoteEndPoint; IPEndPoint local = (IPEndPoint)mSocket.LocalEndPoint; // Send version packet MemoryStream stream = new MemoryStream(); BinaryWriter w = new BinaryWriter(stream); // -- PAYLOAD -- // version w.Write(0x00011171); // Services Int64 services = 0x0000000000000001; w.Write(services); // Timestamp UInt64 timestamp = Program.UnixTime(); timestamp = 0x52F95D8E; w.Write(timestamp); // addr_recv w.Write(services); w.Write((UInt64)0); w.Write((ushort)0); w.Write((ushort)0xFFFF); byte[] remoteBytes = remote.Address.GetAddressBytes(); w.Write(remoteBytes); w.Write(Program.Byteswap((short)8333)); // addr_from w.Write(services); w.Write((UInt64)0); w.Write((ushort)0); w.Write((ushort)0xFFFF); byte[] localBytes = local.Address.GetAddressBytes(); w.Write(localBytes); w.Write(Program.Byteswap((short)8333)); // nonce w.Write((UInt64)0xC4ACFF3D04805523); // user_agent w.Write((byte)0xF); w.Write("/Satoshi:0.8.6/".ToArray()); // start_height w.Write((int)0x00045768); byte[] packetData = stream.ToArray(); SendPacket("version", packetData); w.Close(); }
uint DoHashes(uint start, uint count) { uint[] hashout = new uint[8]; uint end = start + count; uint hashesDone = 0; for (uint i = start; i < end; i++, hashesDone++) { // Write i into data //i = 2083236893; mData[3] = Program.Byteswap(i); //sha256_block_data_order(hash1, mMidstate, mData); //sha256_block_data_order(hashout, staticHashInit, hash1); SHATransform(hash1, mMidstate, mData); SHATransform(hashout, staticHashInit, hash1); // Check if (hashout[7] == 0) { for (int k = 6; k >= 0; k--) { if (hashout[k] > mTarget[k]) { break; } if (hashout[k] < mTarget[k]) { // Solution found hashesDone++; SendWorkComplete(true, i, mHashesDone + hashesDone); return(hashesDone); } } } } return(hashesDone); }
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"); }