Example #1
0
        private void DeleteStaleBlocks()
        {
            Stopwatch deleteStaleBlocksWatch = new Stopwatch();

            deleteStaleBlocksWatch.Start();

            Console.Write("Searching for stale blocks in the database...");

            using (BitcoinDataLayer bitcoinDataLayer = new BitcoinDataLayer(this.databaseConnection.ConnectionString))
            {
                List <long> staleBlocksIds = GetStaleBlockIds(bitcoinDataLayer);

                if (staleBlocksIds.Count > 0)
                {
                    // Now delete all stale blocks
                    bitcoinDataLayer.DeleteBlocks(staleBlocksIds);

                    // Update the block IDs after deleting the stale blocks so that the block IDs are forming a consecutive sequence.
                    bitcoinDataLayer.CompactBlockIds(staleBlocksIds);
                }

                deleteStaleBlocksWatch.Stop();

                if (staleBlocksIds.Count == 0)
                {
                    Console.WriteLine("\rNo stale blocks were found. The search took {0:0.000} seconds.", deleteStaleBlocksWatch.Elapsed.TotalSeconds);
                }
                else
                {
                    string format = staleBlocksIds.Count == 1 ?
                                    "\rOne stale block was found and deleted in {1:0.000} seconds" :
                                    "\r{0} stale blocks were found and deleted in {1:0.000} seconds.";

                    Console.WriteLine(format, staleBlocksIds.Count, deleteStaleBlocksWatch.Elapsed.TotalSeconds);
                }
            }
        }
        private void DeleteStaleBlocks()
        {
            Stopwatch deleteStaleBlocksWatch = new Stopwatch();
            deleteStaleBlocksWatch.Start();

            Console.Write("Searching for stale blocks in the database...");

            using (BitcoinDataLayer bitcoinDataLayer = new BitcoinDataLayer(this.databaseConnection.ConnectionString))
            {
                List<long> staleBlocksIds = GetStaleBlockIds(bitcoinDataLayer);

                if (staleBlocksIds.Count > 0)
                {
                    // Now delete all stale blocks
                    bitcoinDataLayer.DeleteBlocks(staleBlocksIds);

                    // Update the block IDs after deleting the stale blocks so that the block IDs are forming a consecutive sequence.
                    bitcoinDataLayer.CompactBlockIds(staleBlocksIds);
                }

                deleteStaleBlocksWatch.Stop();

                if (staleBlocksIds.Count == 0)
                {
                    Console.WriteLine("\rNo stale blocks were found. The search took {0:0.000} seconds.", deleteStaleBlocksWatch.Elapsed.TotalSeconds);
                }
                else
                {
                    string format = staleBlocksIds.Count == 1 ?
                        "\rOne stale block was found and deleted in {1:0.000} seconds" :
                        "\r{0} stale blocks were found and deleted in {1:0.000} seconds.";

                    Console.WriteLine(format, staleBlocksIds.Count, deleteStaleBlocksWatch.Elapsed.TotalSeconds);
                }
            }
        }