Beispiel #1
0
        public async Task InitializeAsync(CancellationToken cancel)
        {
            if (!IndexDownloader.IsRunning)
            {
                throw new NotSupportedException($"{nameof(IndexDownloader)} is not running.");
            }

            using (HandleFiltersLock.Lock())
                using (WalletBlocksLock.Lock())
                {
                    // Go through the filters and que to download the matches.
                    var filters = IndexDownloader.GetFiltersIncluding(IndexDownloader.StartingFilter.BlockHeight);

                    foreach (var filterModel in filters.Where(x => x.Filter != null && !WalletBlocks.ContainsValue(x.BlockHash)))             // Filter can be null if there is no bech32 tx.
                    {
                        await ProcessFilterModelAsync(filterModel, cancel);
                    }
                }
        }
Beispiel #2
0
        public WalletService(KeyManager keyManager, IndexDownloader indexDownloader, MemPoolService memPool, NodesGroup nodes, string blocksFolderPath)
        {
            KeyManager      = Guard.NotNull(nameof(keyManager), keyManager);
            Nodes           = Guard.NotNull(nameof(nodes), nodes);
            IndexDownloader = Guard.NotNull(nameof(indexDownloader), indexDownloader);
            MemPool         = Guard.NotNull(nameof(memPool), memPool);

            WalletBlocks      = new SortedDictionary <Height, uint256>();
            ProcessedBlocks   = new HashSet <uint256>();
            WalletBlocksLock  = new AsyncLock();
            HandleFiltersLock = new AsyncLock();

            Coins = new ConcurrentHashSet <SmartCoin>();

            BlocksFolderPath  = Guard.NotNullOrEmptyOrWhitespace(nameof(blocksFolderPath), blocksFolderPath, trim: true);
            BlockFolderLock   = new AsyncLock();
            BlockDownloadLock = new AsyncLock();

            AssertCleanKeysIndexed(21);

            _running = 0;

            if (Directory.Exists(BlocksFolderPath))
            {
                if (IndexDownloader.Network == Network.RegTest)
                {
                    Directory.Delete(BlocksFolderPath, true);
                    Directory.CreateDirectory(BlocksFolderPath);
                }
            }
            else
            {
                Directory.CreateDirectory(BlocksFolderPath);
            }

            IndexDownloader.NewFilter   += IndexDownloader_NewFilterAsync;
            IndexDownloader.Reorged     += IndexDownloader_ReorgedAsync;
            MemPool.TransactionReceived += MemPool_TransactionReceived;
        }
Beispiel #3
0
 public static FilterModel GetStartingFilter(Network network) => IndexDownloader.GetStartingFilter(network);