Exemplo n.º 1
0
        public ExplorerConfiguration LoadArgs(IConfiguration config)
        {
            NetworkProvider = new NBXplorerNetworkProvider(DefaultConfiguration.GetChainType(config));
            var defaultSettings = NBXplorerDefaultSettings.GetDefaultSettings(NetworkProvider.ChainType);

            Logs.Configuration.LogInformation("Network: " + NetworkProvider.ChainType.ToString());
            var supportedChains = config.GetOrDefault <string>("chains", "btc")
                                  .Split(',', StringSplitOptions.RemoveEmptyEntries)
                                  .Select(t => t.ToUpperInvariant());
            var validChains = new List <string>();

            foreach (var network in NetworkProvider.GetAll())
            {
                if (supportedChains.Contains(network.CryptoCode))
                {
                    validChains.Add(network.CryptoCode);
                    var chainConfiguration = new ChainConfiguration();
                    chainConfiguration.Rescan     = config.GetOrDefault <bool>($"{network.CryptoCode}.rescan", false);
                    chainConfiguration.CryptoCode = network.CryptoCode;
                    var args = RPCArgs.Parse(config, network.NBitcoinNetwork, network.CryptoCode);
                    chainConfiguration.RPC          = args.ConfigureRPCClient(network);
                    chainConfiguration.NodeEndpoint = DefaultConfiguration.ConvertToEndpoint(config.GetOrDefault <string>($"{network.CryptoCode}.node.endpoint", "127.0.0.1"), network.NBitcoinNetwork.DefaultPort);
                    chainConfiguration.StartHeight  = config.GetOrDefault <int>($"{network.CryptoCode}.startheight", -1);

                    ChainConfigurations.Add(chainConfiguration);
                }
            }
            var invalidChains = String.Join(',', supportedChains.Where(s => !validChains.Contains(s)).ToArray());

            if (!string.IsNullOrEmpty(invalidChains))
            {
                throw new ConfigException($"Invalid chains {invalidChains}");
            }

            Logs.Configuration.LogInformation("Supported chains: " + String.Join(',', supportedChains.ToArray()));
            BaseDataDir = config.GetOrDefault <string>("datadir", Path.GetDirectoryName(defaultSettings.DefaultDataDirectory));
            MinGapSize  = config.GetOrDefault <int>("mingapsize", 20);
            MaxGapSize  = config.GetOrDefault <int>("maxgapsize", 30);
            if (MinGapSize >= MaxGapSize)
            {
                throw new ConfigException("mingapsize should be equal or lower than maxgapsize");
            }
            if (!Directory.Exists(BaseDataDir))
            {
                Directory.CreateDirectory(BaseDataDir);
            }
            DataDir = Path.Combine(BaseDataDir, NetworkProvider.ChainType.ToNetwork().Name);
            if (!Directory.Exists(DataDir))
            {
                Directory.CreateDirectory(DataDir);
            }
            CacheChain       = config.GetOrDefault <bool>("cachechain", true);
            NoAuthentication = config.GetOrDefault <bool>("noauth", false);
            return(this);
        }
Exemplo n.º 2
0
        public ExplorerConfiguration LoadArgs(IConfiguration config)
        {
            Network = DefaultConfiguration.GetNetwork(config);
            if (Network == null)
            {
                throw new ConfigException("Invalid network");
            }

            DataDir = config.GetOrDefault <string>("datadir", Network.DefaultDataDirectory);

            Logs.Configuration.LogInformation("Network: " + Network.Network);

            Rescan = config.GetOrDefault <bool>("rescan", false);

            RPC              = RPCArgs.Parse(config, Network.Network);
            NodeEndpoint     = DefaultConfiguration.ConvertToEndpoint(config.GetOrDefault <string>("node.endpoint", "127.0.0.1"), Network.Network.DefaultPort);
            CacheChain       = config.GetOrDefault <bool>("cachechain", true);
            StartHeight      = config.GetOrDefault <int>("startheight", -1);
            NoAuthentication = config.GetOrDefault <bool>("noauth", false);
            return(this);
        }
Exemplo n.º 3
0
        public ExplorerConfiguration LoadArgs(IConfiguration config)
        {
            NetworkProvider = new NBXplorerNetworkProvider(DefaultConfiguration.GetNetworkType(config));
            var defaultSettings = NBXplorerDefaultSettings.GetDefaultSettings(NetworkProvider.NetworkType);

            BaseDataDir = config.GetOrDefault <string>("datadir", null);
            if (BaseDataDir == null)
            {
                BaseDataDir = Path.GetDirectoryName(defaultSettings.DefaultDataDirectory);
                if (!Directory.Exists(BaseDataDir))
                {
                    Directory.CreateDirectory(BaseDataDir);
                }
                if (!Directory.Exists(defaultSettings.DefaultDataDirectory))
                {
                    Directory.CreateDirectory(defaultSettings.DefaultDataDirectory);
                }
            }

            Logs.Configuration.LogInformation("Network: " + NetworkProvider.NetworkType.ToString());
            var supportedChains = config.GetOrDefault <string>("chains", "btc")
                                  .Split(',', StringSplitOptions.RemoveEmptyEntries)
                                  .Select(t => t.ToUpperInvariant());
            var validChains = new List <string>();

            foreach (var network in NetworkProvider.GetAll())
            {
                if (supportedChains.Contains(network.CryptoCode))
                {
                    validChains.Add(network.CryptoCode);
                    var chainConfiguration = new ChainConfiguration();
                    chainConfiguration.Rescan     = config.GetOrDefault <bool>($"{network.CryptoCode}.rescan", false);
                    chainConfiguration.CryptoCode = network.CryptoCode;

                    var args = RPCArgs.Parse(config, network.NBitcoinNetwork, network.CryptoCode);

                    chainConfiguration.RPC = args.ConfigureRPCClient(network);
                    if (chainConfiguration.RPC.Address.Port == network.NBitcoinNetwork.DefaultPort)
                    {
                        Logs.Configuration.LogWarning($"{network.CryptoCode}: It seems that the RPC port ({chainConfiguration.RPC.Address.Port}) is equal to the default P2P port ({network.NBitcoinNetwork.DefaultPort}), this is probably a misconfiguration.");
                    }
                    if ((chainConfiguration.RPC.CredentialString.CookieFile != null || chainConfiguration.RPC.CredentialString.UseDefault) && !network.SupportCookieAuthentication)
                    {
                        throw new ConfigException($"Chain {network.CryptoCode} does not support cookie file authentication,\n" +
                                                  $"Please use {network.CryptoCode.ToLowerInvariant()}rpcuser and {network.CryptoCode.ToLowerInvariant()}rpcpassword settings in NBXplorer" +
                                                  $"And configure rpcuser and rpcpassword in the configuration file or in commandline or your node");
                    }
                    chainConfiguration.NodeEndpoint = NBitcoin.Utils.ParseEndpoint(config.GetOrDefault <string>($"{network.CryptoCode}.node.endpoint", "127.0.0.1"), network.NBitcoinNetwork.DefaultPort);

                    if (GetPort(chainConfiguration.NodeEndpoint) == network.NBitcoinNetwork.RPCPort)
                    {
                        Logs.Configuration.LogWarning($"{network.CryptoCode}: It seems that the node endpoint port ({GetPort(chainConfiguration.NodeEndpoint)}) is equal to the default RPC port ({network.NBitcoinNetwork.RPCPort}), this is probably a misconfiguration.");
                    }

                    chainConfiguration.StartHeight = config.GetOrDefault <int>($"{network.CryptoCode}.startheight", -1);
                    chainConfiguration.HasTxIndex  = config.GetOrDefault <bool>($"{network.CryptoCode}.hastxindex", false);

                    ChainConfigurations.Add(chainConfiguration);
                }
            }
            var invalidChains = String.Join(',', supportedChains.Where(s => !validChains.Contains(s)).ToArray());

            if (!string.IsNullOrEmpty(invalidChains))
            {
                throw new ConfigException($"Invalid chains {invalidChains}");
            }

            Logs.Configuration.LogInformation("Supported chains: " + String.Join(',', supportedChains.ToArray()));
            MinGapSize = config.GetOrDefault <int>("mingapsize", 20);
            MaxGapSize = config.GetOrDefault <int>("maxgapsize", 30);
            if (MinGapSize >= MaxGapSize)
            {
                throw new ConfigException("mingapsize should be equal or lower than maxgapsize");
            }
            if (!Directory.Exists(BaseDataDir))
            {
                Directory.CreateDirectory(BaseDataDir);
            }
            DataDir = Path.Combine(BaseDataDir, NBXplorerDefaultSettings.GetFolderName(NetworkProvider.NetworkType));
            if (!Directory.Exists(DataDir))
            {
                Directory.CreateDirectory(DataDir);
            }
            SignalFilesDir = config.GetOrDefault <string>("signalfilesdir", null);
            SignalFilesDir = SignalFilesDir ?? DataDir;
            if (!Directory.Exists(SignalFilesDir))
            {
                Directory.CreateDirectory(SignalFilesDir);
            }
            CacheChain       = config.GetOrDefault <bool>("cachechain", true);
            NoAuthentication = config.GetOrDefault <bool>("noauth", false);

            var customKeyPathTemplate = config.GetOrDefault <string>("customkeypathtemplate", null);

            if (!string.IsNullOrEmpty(customKeyPathTemplate))
            {
                if (!KeyPathTemplate.TryParse(customKeyPathTemplate, out var v))
                {
                    throw new ConfigException("Invalid customKeyPathTemplate");
                }
                if (v.PostIndexes.IsHardened || v.PreIndexes.IsHardened)
                {
                    throw new ConfigException("customKeyPathTemplate should not be an hardened path");
                }
                CustomKeyPathTemplate = v;
            }

            AzureServiceBusConnectionString = config.GetOrDefault <string>("asbcnstr", "");
            AzureServiceBusBlockQueue       = config.GetOrDefault <string>("asbblockq", "");
            AzureServiceBusTransactionQueue = config.GetOrDefault <string>("asbtranq", "");
            AzureServiceBusBlockTopic       = config.GetOrDefault <string>("asbblockt", "");
            AzureServiceBusTransactionTopic = config.GetOrDefault <string>("asbtrant", "");

            return(this);
        }
Exemplo n.º 4
0
        public ExplorerConfiguration LoadArgs(IConfiguration config)
        {
            NetworkProvider = new NBXplorerNetworkProvider(DefaultConfiguration.GetNetworkType(config));
            var defaultSettings = NBXplorerDefaultSettings.GetDefaultSettings(NetworkProvider.NetworkType);

            BaseDataDir = config.GetOrDefault <string>("datadir", null);
            if (BaseDataDir == null)
            {
                BaseDataDir = Path.GetDirectoryName(defaultSettings.DefaultDataDirectory);
                if (!Directory.Exists(BaseDataDir))
                {
                    Directory.CreateDirectory(BaseDataDir);
                }
                if (!Directory.Exists(defaultSettings.DefaultDataDirectory))
                {
                    Directory.CreateDirectory(defaultSettings.DefaultDataDirectory);
                }
            }

            Logs.Configuration.LogInformation("Network: " + NetworkProvider.NetworkType.ToString());
            var supportedChains = config.GetOrDefault <string>("chains", "btc")
                                  .Split(',', StringSplitOptions.RemoveEmptyEntries)
                                  .Select(t => t.ToUpperInvariant());
            var validChains = new List <string>();

            foreach (var network in NetworkProvider.GetAll())
            {
                if (supportedChains.Contains(network.CryptoCode))
                {
                    validChains.Add(network.CryptoCode);
                    var chainConfiguration = new ChainConfiguration();
                    chainConfiguration.Rescan     = config.GetOrDefault <bool>($"{network.CryptoCode}.rescan", false);
                    chainConfiguration.CryptoCode = network.CryptoCode;

                    var args = RPCArgs.Parse(config, network.NBitcoinNetwork, network.CryptoCode);
                    chainConfiguration.RPC = args.ConfigureRPCClient(network);
                    if ((chainConfiguration.RPC.CredentialString.CookieFile != null || chainConfiguration.RPC.CredentialString.UseDefault) && !network.SupportCookieAuthentication)
                    {
                        throw new ConfigException($"Chain {network.CryptoCode} does not support cookie file authentication,\n" +
                                                  $"Please use {network.CryptoCode.ToLowerInvariant()}rpcuser and {network.CryptoCode.ToLowerInvariant()}rpcpassword settings in NBXplorer" +
                                                  $"And configure rpcuser and rpcpassword in the configuration file or in commandline or your node");
                    }
                    chainConfiguration.NodeEndpoint = DefaultConfiguration.ConvertToEndpoint(config.GetOrDefault <string>($"{network.CryptoCode}.node.endpoint", "127.0.0.1"), network.NBitcoinNetwork.DefaultPort);
                    chainConfiguration.StartHeight  = config.GetOrDefault <int>($"{network.CryptoCode}.startheight", -1);

                    ChainConfigurations.Add(chainConfiguration);
                }
            }
            var invalidChains = String.Join(',', supportedChains.Where(s => !validChains.Contains(s)).ToArray());

            if (!string.IsNullOrEmpty(invalidChains))
            {
                throw new ConfigException($"Invalid chains {invalidChains}");
            }

            Logs.Configuration.LogInformation("Supported chains: " + String.Join(',', supportedChains.ToArray()));
            AutoPruningTime = TimeSpan.FromSeconds(config.GetOrDefault <int>("autopruning", -1));
            if (AutoPruningTime.Value < TimeSpan.Zero)
            {
                AutoPruningTime = null;
            }
            MinGapSize = config.GetOrDefault <int>("mingapsize", 20);
            MaxGapSize = config.GetOrDefault <int>("maxgapsize", 30);
            if (MinGapSize >= MaxGapSize)
            {
                throw new ConfigException("mingapsize should be equal or lower than maxgapsize");
            }
            if (!Directory.Exists(BaseDataDir))
            {
                Directory.CreateDirectory(BaseDataDir);
            }
            DataDir = Path.Combine(BaseDataDir, NBXplorerDefaultSettings.GetFolderName(NetworkProvider.NetworkType));
            if (!Directory.Exists(DataDir))
            {
                Directory.CreateDirectory(DataDir);
            }
            CacheChain       = config.GetOrDefault <bool>("cachechain", true);
            NoAuthentication = config.GetOrDefault <bool>("noauth", false);

            AzureServiceBusConnectionString = config.GetOrDefault <string>("asbcnstr", "");
            AzureServiceBusBlockQueue       = config.GetOrDefault <string>("asbblockq", "");
            AzureServiceBusTransactionQueue = config.GetOrDefault <string>("asbtranq", "");
            AzureServiceBusBlockTopic       = config.GetOrDefault <string>("asbblockt", "");
            AzureServiceBusTransactionTopic = config.GetOrDefault <string>("asbtrant", "");

            return(this);
        }
Exemplo n.º 5
0
        public static RPCClient ConfigureRPCClient(IConfiguration confArgs, Network network, string prefix = null)
        {
            RPCArgs args = Parse(confArgs, network, prefix);

            return(args.ConfigureRPCClient(network));
        }