public StratumHeaderBuilder(StratumJob job, string extraNonce1, string extraNonce2)
 {
     Job = job;
     ExtraNonce1 = extraNonce1;
     ExtraNonce2 = extraNonce2;
     _extraNonce2 = extraNonce2.ParseHex();
     UpdateTime();
 }
        private void OnMiningJob(SimpleJson.JsonArray array)
        {
            var merkleBranchJSon = (SimpleJson.JsonArray)array[4]; // List of hashes, will be used for calculation of merkle root. This is not a list of all transactions, it only contains prepared hashes of steps of merkle tree algorithm. Please read some materials for understanding how merkle trees calculation works. Unfortunately this example don't have any step hashes included, my bad!
            var merkleBranch = new string[merkleBranchJSon.Count];
            for (int i = 0; i < merkleBranch.Length; i++)
                merkleBranch[i] = (string)merkleBranchJSon[i];

            var prevHashBytes = ((string)array[1]).ParseHex();
            prevHashBytes.ByteReverse();
            var prevHash = prevHashBytes.ToHexString();

            var nTimeString = ReverseEndian((string)array[7]);
            var nTimeInt = BitConverter.ToUInt32(nTimeString.ParseHex(), 0);

            //DateTime nTimeDT = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
            //nTimeDT = nTimeDT.AddSeconds(nTimeInt);

            StratumJob job = new StratumJob
            {
                JobId = (string)array[0], // ID of the job. Use this ID while submitting share generated from this job.
                PrevHash = prevHash, // Hash of previous block.
                CoinB1 = (string)array[2], // Initial part of coinbase transaction.
                CoinB2 = (string)array[3], // Final part of coinbase transaction.
                MerkleBranch = merkleBranch,
                Version = ReverseEndian((string)array[5]), // Bitcoin block version.
                NBits = ReverseEndian((string)array[6]), // Encoded current network difficulty
                NTime = nTimeInt, // Current ntime/
                ReceiveTime = DateTime.UtcNow,
                Target = GetHashTarget(),
            };

            bool cleanJobs = (bool)array[8]; // When true, server indicates that submitting shares from previous jobs don't have a sense and such shares will be rejected. When this flag is set, miner should also drop all previous jobs, so job_ids can be eventually rotated.

            CurrentJob = job;
        }