public void LinearDictionaryCoder() { var testPath = "linearDictionaryUnitTest"; if (File.Exists(testPath)) { File.Delete(testPath); } var linearDictionaryCoder = new LinearDictionaryEncoder(testPath, 32, 32); var expectedDictionary = new Dictionary <byte[], byte[]>(); LargeInteger value = 0; for (int i = 0; i < 1500; i++) { var valueBytes = ByteManipulator.BigEndianTruncate(value.GetBytes(), 32); var key = CryptographyHelper.Sha3256(valueBytes); linearDictionaryCoder.Add(key, valueBytes); expectedDictionary.Add(key, valueBytes); value = value + 1; } foreach (var kvp in expectedDictionary) { var entryValue = linearDictionaryCoder.Get(kvp.Key); Assert.IsTrue(ArrayManipulator.Compare(kvp.Value, entryValue)); } }
public async Task <Block> MineRound(Wallet wallet) { minedBlock.MinerAddress = wallet.PublicKey; var difficultyBytes = minedBlock.Difficulty.GetBytes(); for (int i = 0; i < hashesPerRound; i++) { if (stop) { break; } minedBlock.Nonce = nonce.GetBytes(); numberOfAttempts = numberOfAttempts + 1; if (ArrayManipulator.IsGreater(ByteManipulator.BigEndianTruncate(difficultyBytes, 32), minedBlock.GetHash(), difficultyBytes.Length)) //new block found { stopWatch.Stop(); return(minedBlock); } nonce = nonce + 1; } return(null); }
public async Task <Block> MineRound() { var block = new Block() { Difficulty = difficulty, Height = height, MinerAddress = minerAddress, PreviousBlockHash = previousBlockHash, Timestamp = timestamp, Transactions = transactions }; var difficultyBytes = difficulty.GetBytes(); for (int i = 0; i < hashesPerRound; i++) { block.Nonce = nonce.GetBytes(); numberOfAttempts = numberOfAttempts + 1; if (ArrayManipulator.IsGreater(ByteManipulator.BigEndianTruncate(difficultyBytes, 32), block.GetHash(), difficultyBytes.Length)) //new block found { lock (GateKeeper.ChainManagerLock) { _chainManager.ProcessBlocks(new List <Block>() { block }); } lock (GateKeeper.TransactionPoolLock) { lock (GateKeeper.BalanceLedgerLock) { _transactionPool.Clean(); } } BlockTime = block.Timestamp - lastBlockTimeStamp; return(block); } nonce = nonce + 1; } return(null); }