public ExplorerConfiguration LoadArgs(String[] args)
        {
            ConfigurationFile = args.Where(a => a.StartsWith("-conf=", StringComparison.Ordinal)).Select(a => a.Substring("-conf=".Length).Replace("\"", "")).FirstOrDefault();
            DataDir           = args.Where(a => a.StartsWith("-datadir=", StringComparison.Ordinal)).Select(a => a.Substring("-datadir=".Length).Replace("\"", "")).FirstOrDefault();
            if (DataDir != null && ConfigurationFile != null)
            {
                var isRelativePath = Path.GetFullPath(ConfigurationFile).Length > ConfigurationFile.Length;
                if (isRelativePath)
                {
                    ConfigurationFile = Path.Combine(DataDir, ConfigurationFile);
                }
            }

            Network = args.Contains("-testnet", StringComparer.OrdinalIgnoreCase) ? Network.TestNet :
                      args.Contains("-regtest", StringComparer.OrdinalIgnoreCase) ? Network.RegTest :
                      Network.DefaultMain;

            if (ConfigurationFile != null)
            {
                AssetConfigFileExists();
                var configTemp = TextFileConfiguration.Parse(File.ReadAllText(ConfigurationFile));
                Network = configTemp.GetOrDefault <bool>("testnet", false) ? Network.TestNet :
                          configTemp.GetOrDefault <bool>("regtest", false) ? Network.RegTest :
                          Network.DefaultMain;
            }
            if (DataDir == null)
            {
                DataDir = DefaultDataDirectory.GetDefaultDirectory("ElementExplorer", Network);
            }

            if (ConfigurationFile == null)
            {
                ConfigurationFile = GetDefaultConfigurationFile();
            }

            if (!Directory.Exists(DataDir))
            {
                throw new ConfigurationException("Data directory does not exists");
            }

            var consoleConfig = new TextFileConfiguration(args);
            var config        = TextFileConfiguration.Parse(File.ReadAllText(ConfigurationFile));

            consoleConfig.MergeInto(config, true);

            if (Network == Network.DefaultMain || Network == Network.RegTest)
            {
                var rpc = RPCArgs.Parse(config, Network).ConfigureRPCClient(Network);
                Network = CreateNetwork(Network, rpc.GetBlock(0));
                RPCArgs.CheckNetwork(Network, rpc);
            }

            Logs.Configuration.LogInformation("Network: " + Network);
            Logs.Configuration.LogInformation("Data directory set to " + DataDir);
            Logs.Configuration.LogInformation("Configuration file set to " + ConfigurationFile);

            Rescan = config.GetOrDefault <bool>("rescan", false);
            var defaultPort = config.GetOrDefault <int>("port", 37123);

            Listen = config
                     .GetAll("bind")
                     .Select(p => ConvertToEndpoint(p, defaultPort))
                     .ToList();
            if (Listen.Count == 0)
            {
                Listen.Add(new IPEndPoint(IPAddress.Any, defaultPort));
            }

            RPC          = RPCArgs.Parse(config, Network);
            NodeEndpoint = ConvertToEndpoint(config.GetOrDefault <string>("node.endpoint", "127.0.0.1"), Network.DefaultPort);
            CacheChain   = config.GetOrDefault <bool>("cachechain", true);
            StartHeight  = config.GetOrDefault <int>("startheight", 0);
            return(this);
        }
Example #2
0
        public static RPCClient ConfigureRPCClient(TextFileConfiguration confArgs, Network network, string prefix = null)
        {
            RPCArgs args = Parse(confArgs, network, prefix);

            return(args.ConfigureRPCClient(network));
        }