Exemple #1
0
        public QBitNinjaDependencyResolver(QBitNinjaConfiguration configuration, IDependencyResolver defaultResolver)
        {
            _defaultResolver = defaultResolver;
            ContainerBuilder       builder     = new ContainerBuilder();
            ChainSynchronizeStatus chainStatus = new ChainSynchronizeStatus();

            builder.Register(ctx => chainStatus).SingleInstance();
            builder.Register(ctx => configuration).SingleInstance();
            builder.Register(ctx => configuration.Indexer.CreateIndexerClient());
            builder.Register(ctx =>
            {
                var client            = ctx.Resolve <IndexerClient>();
                ConcurrentChain chain = new ConcurrentChain(configuration.Indexer.Network);
                _ = LoadChain(configuration, client, chain, chainStatus);
                return(chain);
            }).SingleInstance();
            builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
            _container = builder.Build();
        }
Exemple #2
0
        private async Task LoadChain(QBitNinjaConfiguration configuration, IndexerClient client, ConcurrentChain chain, ChainSynchronizeStatus status)
        {
            await Task.Delay(1).ConfigureAwait(false);

            LoadCache(chain, configuration.LocalChain, configuration.Indexer.Network);
            status.FileCachedHeight = chain.Height;
            var changes = client.GetChainChangesUntilFork(chain.Tip, false);

            try
            {
                await changes.UpdateChain(chain, _Cts.Token);
            }
            catch (ArgumentException) //Happen when chain in table is corrupted
            {
                client.Configuration.GetChainTable().DeleteIfExists();
                for (int i = 0; i < 20; i++)
                {
                    try
                    {
                        if (client.Configuration.GetChainTable().CreateIfNotExists())
                        {
                            break;
                        }
                    }
                    catch
                    {
                    }
                    await Task.Delay(10000);
                }
                status.ReindexHeaders = true;
                await client.Configuration.CreateIndexer().IndexChain(chain, _Cts.Token);
            }
            status.TableFetchedHeight = chain.Height;
            SaveChainCache(chain, configuration.LocalChain);
            status.Synchronizing = false;
            Interlocked.Decrement(ref _UpdateChain);
        }