Exemplo n.º 1
0
        static async Task <int> Main(string[] args)
        {
            var validChains = string.Join(",", new NBXplorerNetworkProvider(NetworkType.Mainnet).GetAll().Select(n => n.CryptoCode.ToLowerInvariant()).ToArray());

            using (CancellationTokenSource stop = new CancellationTokenSource())
                using (CancelOnExit(stop))
                {
                    var provider = new CommandLineExConfigurationProvider(args, CreateCommandLineApplication);
                    provider.Load();

                    if (provider.TryGet("help", out var unused))
                    {
                        return(1);
                    }
                    if (!provider.TryGet("chains", out var chains))
                    {
                        chains = "btc";
                    }
                    if (!provider.TryGet("network", out var network))
                    {
                        network = "mainnet";
                    }

                    var networkType     = GetNetworkType(network);
                    var networkProvider = new NBXplorerNetworkProvider(networkType);

                    var supportedChains = chains
                                          .Split(',', StringSplitOptions.RemoveEmptyEntries)
                                          .Select(t => GetNetwork(provider, networkProvider, t, validChains))
                                          .ToList();

                    var wait = TimeSpan.FromSeconds(1);
                    while (true)
                    {
                        if (await AreSynchedAndStarted(supportedChains, stop.Token))
                        {
                            return(0);
                        }
                        Write($"-----trying again in {(int)wait.TotalSeconds} seconds-----");
                        await Task.Delay(wait, stop.Token);

                        wait = TimeSpan.FromTicks(2 * wait.Ticks);
                        if (wait > TimeSpan.FromMinutes(5))
                        {
                            wait = TimeSpan.FromMinutes(5);
                        }
                    }
                }
        }
Exemplo n.º 2
0
        static async Task <int> Main(string[] args)
        {
            var childProcessArgSeparatorPos = Array.IndexOf(args, "--");
            var waiterArgs = args;

            string[] childProcessArgs = null;
            string   childProcess     = null;

            if (childProcessArgSeparatorPos != -1)
            {
                waiterArgs = args.Take(childProcessArgSeparatorPos).ToArray();
                if (childProcessArgSeparatorPos != args.Length - 1)
                {
                    childProcess     = args.Skip(childProcessArgSeparatorPos + 1).First();
                    childProcessArgs = args.Skip(childProcessArgSeparatorPos + 2).ToArray();
                }
            }


            var validChains = string.Join(",", new NBXplorerNetworkProvider(NetworkType.Mainnet).GetAll().Select(n => n.CryptoCode.ToLowerInvariant()).ToArray());

            using (CancellationTokenSource stop = new CancellationTokenSource())
            {
                var provider = new CommandLineExConfigurationProvider(waiterArgs, CreateCommandLineApplication);
                provider.Load();

                if (!provider.TryGet("explorerurl", out var unused) || unused == string.Empty)
                {
                    Console.WriteLine("explorerurl not configued, skipping waiting");
                    return(RunChildProcess(childProcess, childProcessArgs));
                }

                if (provider.TryGet("help", out unused))
                {
                    return(1);
                }
                if (!provider.TryGet("chains", out var chains))
                {
                    chains = "btc";
                }
                if (!provider.TryGet("network", out var network))
                {
                    network = "mainnet";
                }

                var networkType     = GetNetworkType(network);
                var networkProvider = new NBXplorerNetworkProvider(networkType);

                var supportedChains = chains
                                      .Split(',', StringSplitOptions.RemoveEmptyEntries)
                                      .Select(t => GetNetwork(provider, networkProvider, t, validChains))
                                      .ToList();

                var wait = TimeSpan.FromSeconds(1);
                while (true)
                {
                    if (await AreSynchedAndStarted(supportedChains, stop.Token))
                    {
                        return(RunChildProcess(childProcess, childProcessArgs));
                    }
                    Write($"-----trying again in {(int)wait.TotalSeconds} seconds-----");
                    await Task.Delay(wait, stop.Token);

                    wait = TimeSpan.FromTicks(2 * wait.Ticks);
                    if (wait > TimeSpan.FromMinutes(5))
                    {
                        wait = TimeSpan.FromMinutes(5);
                    }
                }
            }
        }