BitMaker.Miner.Managed.ManagedMiner.Search C# (CSharp) Method

Search() public method

Implements the search function in managed code.
public Search ( Work work, uint round1State, byte round1Block2, uint round2State, byte round2Block1 ) : uint?
work Work
round1State uint
round1Block2 byte
round2State uint
round2Block1 byte
return uint?
        public unsafe override uint? Search(Work work, uint* round1State, byte* round1Block2, uint* round2State, byte* round2Block1)
        {
            // starting nonce
            uint nonce = 0;

            // output for final hash
            uint* round2State2 = stackalloc uint[Sha256.SHA256_STATE_SIZE];

            while (true)
            {
                // update the nonce value
                ((uint*)round1Block2)[3] = nonce;

                // transform variable second half of block using saved state from first block, into pre-padded round 2 block (end of first hash)
                Sha256.Transform(round1State, round1Block2, (uint*)round2Block1);

                // transform round 2 block into round 2 state (second hash)
                Sha256.Transform(round2State, round2Block1, round2State2);

                // test for potentially valid hash
                if (round2State2[7] == 0U)
                    // actual nonce is flipped
                    return Memory.ReverseEndian(nonce);

                // only report and check for exit conditions every so often
                if ((++nonce % 65536) == 0)
                    if (!Progress(work, 65536) || nonce == 0)
                        break;
            }

            return null;
        }