static void TestBlockChain(Block <TestBlockData> validBlock) { const string file = "blochweakdb2.feeawbasfewa"; Console.WriteLine($"--------------------- BlockChain2 --------------------------"); using var sha256 = SHA256.Create(); var blockChain = new BlockChain <TestBlockData>(file, sha256); var sw = Stopwatch.StartNew(); for (int i = 0; i < count; i++) { blockChain.Add(validBlock); } Console.WriteLine($"Write({count}): {sw.ElapsedMilliseconds}"); sw.Restart(); var _ = blockChain.Count(); Console.WriteLine($"Read({_}): {sw.ElapsedMilliseconds}"); sw.Restart(); byte[] timestamp = new byte[] { 17, 104, 230, 94, 127, 183, 215, 8 }; var __ = blockChain.Count(x => ArrayEquals(x.GetBlockHeader().Time, timestamp)); Console.WriteLine($"Search({_}): {sw.ElapsedMilliseconds}"); sw.Restart(); Console.WriteLine($"FileSize f1: {new FileInfo(file).Length}"); Console.WriteLine($"FileSize f2: {new FileInfo(file+".h").Length}"); }
public static void ReplaceChain(List <Block> newBlocks) { if (IsValidChain(newBlocks) && newBlocks.Count() > BlockChain.Count()) { Context db = new Context(); BlockChain = newBlocks; } }