Example #1
0
        public static void UpdateAllAddressBalances()
        {
            var explorerSync = new ExplorerSync();

            new Thread(async() =>
            {
                Thread.CurrentThread.IsBackground = true;
                var context = Explorer.AppServices.GetService <ExplorerDbContext>();

                await explorerSync.UpdateAccountBalances(context, context.Accounts.Select(p => p.Address).ToList());

                Console.WriteLine("Account balances are updated");
            }).Start();
        }
        public static void StartSync(ExplorerDbContext context)
        {
            var explorerSync = new ExplorerSync();

            new Thread(async() =>
            {
                Thread.CurrentThread.IsBackground = true;
                try
                {
                    if (_retries >= MaxRetries)
                    {
                        Console.WriteLine("There are no new blocks to sync.");
                        _retries = 0;
                        return;
                    }
                    while (ContinueSync)
                    {
                        Console.WriteLine("Remember, to stop sync process safely, press 3");
                        Console.WriteLine("It may take a while to stop");
                        Console.WriteLine("\n\n");

                        await explorerSync.Sync(context);
                        Thread.Sleep(AppSettings.SyncTime);
                    }

                    Console.WriteLine("Sync has stopped!");

                    _retries = 0;
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    StartSync(context);
                    _retries++;
                }
            }).Start();
        }