public WorkBlock(JObject obj) { strMidstate = obj["midstate"].ToString(); strData = obj["data"].ToString(); strHash1 = obj["hash1"].ToString(); strTarget = obj["target"].ToString(); //strMidstate = "339a90bcf0bf58637daccc90a8ca591ee9d8c8c3c803014f3687b1961bf91947"; //strData = "000000010000000000000000000000000000000000000000000000000000000000000000fdeda33bb2127b7a3e2cc77a618f7667c31bc87f32518a88aab89f3a4a5e1e4b495fab291d00ffff7c2bac1d000000800000000000000000000000000000000000000000000000000000000000000000000000000000000080020000"; //strTarget = "0000000000000000000000000000000000000000000000000000ffff00000000"; // 2,083,236,893 //strData = "000000022a34cf18f3e954a376d84bfb9665b4f9602e7fc0a90a934b9aa31b1abf7b9d63ade27f84f9d067e70428d2e72d58405fdb42626fe166e0d245efaae46390dbd9532a27ed1c011b0d6bb20500000000800000000000000000000000000000000000000000000000000000000000000000000000000000000080020000"; //strTarget = "000000000000000000000000000000000000000000000000000d1b0100000000"; midstate = Utils.HexStringToByteArray(strMidstate); data = Utils.HexStringToByteArray(strData); hash1 = Utils.HexStringToByteArray(strHash1); target = Utils.HexStringToByteArray(strTarget); data64 = new byte[64]; Buffer.BlockCopy(data, 64, data64, 0, 64); //Utils.ByteSwapIntegers(target); mHashMan = new HashManager(); }
public void GenerateWork() { byte[] en2b = new byte[mExtraNonceSize]; for (int i = 0; i < mExtraNonceSize; i++) { ulong mask = (ulong)0xFF << (i * 8); ulong masked = (mExtraNonceB & mask) >> (i * 8); en2b[mExtraNonceSize - (1 + i)] = (byte)masked; } mExtraNonceB++; mExtraNonce2 = Utils.ByteArrayToHexString(en2b); string coinbase = mCoinBaseA + mExtraNonce + mExtraNonce2 + mCoinBaseB; byte[] cb = Utils.HexStringToByteArray(coinbase); byte[] cbHash = MinerLib_cs.Scrypt.SHA2562(cb); string merkleRoot = Utils.ByteArrayToHexString(cbHash); foreach (string merkle in mMerkleBranch) { byte[] hashData = Utils.HexStringToByteArray(merkleRoot + merkle); byte[] merkleHash = MinerLib_cs.Scrypt.SHA2562(hashData); merkleRoot = Utils.ByteArrayToHexString(merkleHash); } // byteswap the merkle root section byte[] merkleData = Utils.HexStringToByteArray(merkleRoot); Utils.ByteSwapIntegers(merkleData); merkleRoot = Utils.ByteArrayToHexString(merkleData); uint time = (uint)Utils.UnixTime() + 120; mTimeStr = Utils.UIntToHexString(time); strData = mVersion + mPrevHash + merkleRoot + mTimeStr + mDifficulty + "00000000" + "000000800000000000000000000000000000000000000000000000000000000000000000000000000000000080020000"; data = Utils.HexStringToByteArray(strData); }
public void Initialize(ulong serverDiff) { if (serverDiff == 0) { uint diff = Utils.HexStringToUInt(mDifficulty); int diffBytes = ((int)diff >> 24) & 0x000000FF; strTarget = ""; for (int i = 0; i < diffBytes - 3; i++) { strTarget += "00"; } strTarget += string.Format("{0:X2}", (byte)diff); strTarget += string.Format("{0:X2}", (byte)((int)diff >> 8)); strTarget += string.Format("{0:X2}", (byte)((int)diff >> 16)); for (int i = diffBytes; i < 32; i++) { strTarget += "00"; } } else { strTarget = "000000000000000000000000000000000000000000000000"; strTarget += string.Format("{0:X2}", (byte)((long)serverDiff)); strTarget += string.Format("{0:X2}", (byte)((long)serverDiff >> 8)); strTarget += string.Format("{0:X2}", (byte)((long)serverDiff >> 16)); strTarget += string.Format("{0:X2}", (byte)((long)serverDiff >> 24)); strTarget += string.Format("{0:X2}", (byte)((long)serverDiff >> 32)); strTarget += string.Format("{0:X2}", (byte)((long)serverDiff >> 40)); strTarget += string.Format("{0:X2}", (byte)((long)serverDiff >> 48)); strTarget += string.Format("{0:X2}", (byte)((long)serverDiff >> 56)); } target = Utils.HexStringToByteArray(strTarget); //Utils.ByteSwapIntegers(target); mHashMan = new HashManager(); }