Exemple #1
0
        public async Task Sync(ExplorerDbContext context)
        {
            SyncAdditionalDataCounter++;

            foreach (var chain in context.Chains)
            {
                while (await _phantasmaRpcService.GetBlockHeight.SendRequestAsync(chain.Address) > chain.Height)
                {
                    if (ContinueSync)
                    {
                        Console.WriteLine($"NEW BLOCK: Chain: {chain.Name}, block: {chain.Height + 1}");
                        var block = await _phantasmaRpcService.GetBlockByHeight.SendRequestAsync(chain.Address, (int)(chain.Height + 1));

                        await SyncBlock(context, chain, block);
                    }
                    else
                    {
                        Console.WriteLine("Sync has stopped");
                        return;
                    }
                }
            }
            //todo find smarter way to do this
            await UpdateAccountBalances(context, _addressChanged);

            _addressChanged.Clear();

            if (SyncAdditionalDataCounter >= 5)
            {
                Console.WriteLine("Sync new chains?");
                await SyncChains(context);

                Console.WriteLine("Sync new apps?");
                var appList = await _phantasmaRpcService.GetApplications.SendRequestAsync();

                await SyncUtils.SyncApps(context, appList);

                Console.WriteLine("Sync new tokens?");
                var tokenList = await _phantasmaRpcService.GetTokens.SendRequestAsync();

                await SyncUtils.SyncToken(context, tokenList);

                SyncAdditionalDataCounter = 0;
            }
        }
Exemple #2
0
        public async Task SeedEverythingAsync(ExplorerDbContext context)
        {
            try
            {
                var sw = new Stopwatch();
                sw.Start();
                context.Database.EnsureCreated();
                _phantasmaRpcService = (IPhantasmaRpcService)Explorer.AppServices.GetService(typeof(IPhantasmaRpcService));

                if (!context.Apps.Any())
                {
                    var appList = await _phantasmaRpcService.GetApplications.SendRequestAsync();

                    await SyncUtils.SyncApps(context, appList);
                }

                if (!context.Tokens.Any())
                {
                    var tokenList = await _phantasmaRpcService.GetTokens.SendRequestAsync();

                    await SyncUtils.SyncToken(context, tokenList);
                }

                if (!context.Chains.Any())
                {
                    await SeedChains(context);
                }

                if (!context.Blocks.Any())
                {
                    await SeedBlocks(context);
                }

                sw.Stop();
                Console.WriteLine("Elapsed time to initializing db = {0}", sw.Elapsed);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                Console.WriteLine("Exception occurred during DB initialization, explorer cannot start");
            }
        }