コード例 #1
0
ファイル: BlockHeader.cs プロジェクト: GarageGames/Bitcoin
        public void ComputeHash(bool useScrypt)
        {
            MemoryStream ms = new MemoryStream();
            BinaryWriter bw = new BinaryWriter(ms);
            bw.Write(mVersion);
            bw.Write(mPrevBlock);
            bw.Write(mMerkleRoot);
            bw.Write(mTimestamp);
            bw.Write(mDifficultyBits);
            bw.Write(mNOnce);
            byte[] data = ms.ToArray();
            bw.Close();

            if (useScrypt)
            {
                Work work = new Work();
                Buffer.BlockCopy(data, 0, work.data, 0, 80);
                for (int i = 0; i < 20; i++)
                    work.data[i] = Program.Byteswap(work.data[i]);

                Scrypt scrypt = new Scrypt(work);
                mHash = scrypt.GetHash();
            }
            else
            {
                // SHA 256
                mHash = Scrypt.SHA2562(data);
            }
        }
コード例 #2
0
ファイル: UnitTests.cs プロジェクト: GarageGames/Bitcoin
        public static bool TestStandard()
        {
            Work work = new Work();
            Array.Copy(sData, work.data, 32);
            Array.Copy(sTarget, work.target, 8);

            Scrypt scrypt = new Scrypt(work);
            bool result = scrypt.Hash(sNOnce);

            return result;
        }
コード例 #3
0
        public static bool TestStandard()
        {
            Work work = new Work();

            Array.Copy(sData, work.data, 32);
            Array.Copy(sTarget, work.target, 8);

            Scrypt scrypt = new Scrypt(work);
            bool   result = scrypt.Hash(sNOnce);


            return(result);
        }
コード例 #4
0
ファイル: WorkThread.cs プロジェクト: GarageGames/Bitcoin
 void ScryptHashes()
 {
     ulong end = mHashStart + mHashCount;
     Scrypt scryptData = new Scrypt(mWork);
     for( ulong i = mHashStart; i < end; i++ )
     {
         mHashesDone++;
         bool success = scryptData.Hash((uint)i);
         if( success )
         {
             mSolution = (uint)i;
             mSolutionFound = true;
             break;
         }
     }
 }
コード例 #5
0
        void ScryptHashes()
        {
            ulong  end        = mHashStart + mHashCount;
            Scrypt scryptData = new Scrypt(mWork);

            for (ulong i = mHashStart; i < end; i++)
            {
                mHashesDone++;
                bool success = scryptData.Hash((uint)i);
                if (success)
                {
                    mSolution      = (uint)i;
                    mSolutionFound = true;
                    break;
                }
            }
        }
コード例 #6
0
        public void Update(Connection conn)
        {
            if (mCurrentWork != null)
            {
                bool threadsAllDone = true;
                foreach (WorkThread t in mThreads)
                {
                    if (!t.IsWorkDone())
                    {
                        threadsAllDone = false;
                        break;
                    }
                }

                if (threadsAllDone)
                {
                    uint hashes        = 0;
                    uint solution      = 0;
                    bool solutionFound = false;

                    foreach (WorkThread t in mThreads)
                    {
                        hashes += t.HashesDone;
                        if (t.SolutionFound)
                        {
                            solutionFound = true;
                            solution      = t.Solution;
                        }
                    }

                    conn.SendWorkComplete(solutionFound, Scrypt.ByteReverse(solution), hashes);
                    mCurrentWork = null;
                    mTimer.Stop();
                    mHashRate = (uint)((double)hashes / mTimer.GetDuration());
                }
            }
        }