예제 #1
0
        /// <param name="scriptPubKey">BitcoinAddress.ScriptPubKey</param>
        /// <param name="searchFullBlockBuffer">If true: it look for transactions in the buffered full blocks in memory</param>
        public void Track(Script scriptPubKey, bool searchFullBlockBuffer = false)
        {
            TrackedScriptPubKeys.Add(scriptPubKey);

            foreach (var block in FullBlockBuffer)
            {
                TrackIfFindRelatedTransactions(scriptPubKey, block.Key, block.Value);
            }
        }
예제 #2
0
        public async Task LoadAsync(string trackerFolderPath)
        {
            await Saving.WaitAsync().ConfigureAwait(false);

            try
            {
                if (!Directory.Exists(trackerFolderPath))
                {
                    throw new DirectoryNotFoundException($"No Blockchain found at {trackerFolderPath}");
                }

                var tspb = Path.Combine(trackerFolderPath, TrackedScriptPubKeysFileName);
                if (File.Exists(tspb) && new FileInfo(tspb).Length != 0)
                {
                    foreach (var line in File.ReadAllLines(tspb))
                    {
                        TrackedScriptPubKeys.Add(new Script(line));
                    }
                }

                var tt = Path.Combine(trackerFolderPath, TrackedTransactionsFileName);
                if (File.Exists(tt) && new FileInfo(tt).Length != 0)
                {
                    foreach (var line in File.ReadAllLines(tt))
                    {
                        var pieces = line.Split(':');
                        //ProcessTransaction(new SmartTransaction(new Transaction(pieces[0]), new Height(pieces[1])));
                    }
                }

                var pbc = Path.Combine(trackerFolderPath, MerkleChainFileName);
                if (File.Exists(pbc) && new FileInfo(pbc).Length != 0)
                {
                    foreach (var block in Util.Separate(File.ReadAllBytes(pbc), blockSep))
                    {
                        try
                        {
                            SmartMerkleBlock smartMerkleBlock = SmartMerkleBlock.FromBytes(block);
                            MerkleChain.Add(smartMerkleBlock);
                        }
                        catch (EndOfStreamException)
                        {
                            // Some corruption is fine, the software will self correct and save the right data
                        }
                    }
                    if (MerkleChain.Count != 0)
                    {
                        BestHeight = MerkleChain.Max().Height;
                    }
                }
            }
            finally
            {
                Saving.Release();
            }
        }
예제 #3
0
        public async Task LoadAsync(string partialChainFolderPath)
        {
            await Saving.WaitAsync().ConfigureAwait(false);

            try
            {
                if (!Directory.Exists(partialChainFolderPath))
                {
                    throw new DirectoryNotFoundException($"No Blockchain found at {partialChainFolderPath}");
                }

                var tspb = Path.Combine(partialChainFolderPath, FilesNames.TrackedScriptPubKeys.ToString());
                if (File.Exists(tspb) && new FileInfo(tspb).Length != 0)
                {
                    foreach (var line in File.ReadAllLines(tspb))
                    {
                        TrackedScriptPubKeys.Add(new Script(line));
                    }
                }

                var tt = Path.Combine(partialChainFolderPath, FilesNames.TrackedTransactions.ToString());
                if (File.Exists(tt) && new FileInfo(tt).Length != 0)
                {
                    foreach (var line in File.ReadAllLines(tt))
                    {
                        var pieces = line.Split(':');
                        TrackedTransactions.TryAdd(new uint256(pieces[0]), int.Parse(pieces[1]));
                    }
                }

                var pbc = Path.Combine(partialChainFolderPath, FilesNames.PartialBlockChain.ToString());
                if (File.Exists(pbc) && new FileInfo(pbc).Length != 0)
                {
                    foreach (var block in Help.Separate(File.ReadAllBytes(pbc), blockSep))
                    {
                        PartialBlock pb = new PartialBlock().FromBytes(block);

                        Chain.TryAdd(pb.Height, pb);
                    }
                }
            }
            finally
            {
                Saving.Release();
            }
        }