/// <summary> /// Initializes a new instance of the <see cref="SyncServer"/> class. /// </summary> public SyncServer(ILogger <SyncServer> logger, IOptions <IndexerConfiguration> configuration, IOptions <ChainConfiguration> chainConfiguration, IServiceScopeFactory scopeFactory) { log = logger; this.configuration = configuration.Value; this.chainConfiguration = chainConfiguration.Value; this.scopeFactory = scopeFactory; }
public BitcoinDWaiter( RPCClient rpc, ExplorerConfiguration configuration, NBXplorerNetwork network, SlimChain chain, Repository repository, AddressPoolService addressPoolService, EventAggregator eventAggregator) { if (addressPoolService == null) { throw new ArgumentNullException(nameof(addressPoolService)); } _OriginalRPC = rpc; _RPCWithTimeout = rpc.Clone(); _RPCWithTimeout.RequestTimeout = TimeSpan.FromMinutes(1.0); _Configuration = configuration; _Network = network; _Chain = chain; State = BitcoinDWaiterState.NotStarted; _EventAggregator = eventAggregator; _ChainConfiguration = _Configuration.ChainConfigurations.First(c => c.CryptoCode == _Network.CryptoCode); _ExplorerPrototype = new ExplorerBehavior(repository, chain, addressPoolService, eventAggregator) { StartHeight = _ChainConfiguration.StartHeight }; RPCReadyFile = Path.Combine(configuration.SignalFilesDir, $"{network.CryptoCode.ToLowerInvariant()}_fully_synched"); }
/// <summary> /// Initializes a new instance of the <see cref="StatsHandler"/> class. /// </summary> public StatsHandler(SyncConnection connection, IStorage storage, IOptions <IndexerConfiguration> configuration, IOptions <ChainConfiguration> chainConfiguration) { this.storage = storage; syncConnection = connection; this.configuration = configuration.Value; this.chainConfiguration = chainConfiguration.Value; }
public void Instance_Is_CreatorConfiguration_Of_Chain() { //Arrange var type = typeof(PropertyConfiguration <Chain>); //Act var configuration = new ChainConfiguration(); //Assert Assert.IsInstanceOf(type, configuration); }
public void Instance_Is_TravelTypeConfiguration_Of_Chain() { //Arrange var type = typeof(TravelTypeConfiguration <Chain>); //Act var configuration = new ChainConfiguration(); //Assert Assert.IsInstanceOf(type, configuration); }
/// <summary> /// Initializes a new instance of the <see cref="Notifier"/> class. /// </summary> public Notifier(IOptions <IndexerConfiguration> configuration, IOptions <ChainConfiguration> chainConfiguration, ILogger <Notifier> logger, IStorage storage) : base(configuration, logger) { this.configuration = configuration.Value; this.chainConfiguration = chainConfiguration.Value; log = logger; this.storage = storage; watch = Stopwatch.Start(); client = new Lazy <HttpClient>(() => new HttpClient(new HttpClientHandler { ServerCertificateCustomValidationCallback = (sender, certificate, chain, errors) => errors == SslPolicyErrors.None || errors == SslPolicyErrors.RemoteCertificateNameMismatch })); }
public MongoData(ILogger <MongoStorageOperations> logger, SyncConnection connection, IOptions <IndexerConfiguration> nakoConfiguration, IOptions <ChainConfiguration> chainConfiguration) { configuration = nakoConfiguration.Value; this.chainConfiguration = chainConfiguration.Value; syncConnection = connection; log = logger; mongoClient = new MongoClient(configuration.ConnectionString.Replace("{Symbol}", this.chainConfiguration.Symbol.ToLower())); string dbName = configuration.DatabaseNameSubfix ? "Blockchain" + this.chainConfiguration.Symbol : "Blockchain"; mongoDatabase = mongoClient.GetDatabase(dbName); MemoryTransactions = new ConcurrentDictionary <string, NBitcoin.Transaction>(); // Make sure we only create a single instance of the watcher. watch = Stopwatch.Start(); }
public void DispatchRequestInvalidConfig() { ClientConfiguration config = _client.Configuration; ChainConfiguration nodeConfig = new ChainConfiguration(Chain.Goerli, config) { NeedsUpdate = false, RegistryId = "0x23d5345c5c13180a8080bd5ddbe7cde64683755dcce6e734d95b7b573845facb", Contract = "0xdd80249a0631cf0f1593c7a9c9f9b8545e6c88ab", WhiteListContract = "0xdd80249a0631cf0f1593c7a9c9f9b8545e6c88ab", WhiteList = new[] { "0x0123456789012345678901234567890123456789", "0x1234567890123456789012345678901234567890" } }; Assert.ThrowsAsync <ArgumentException>(() => _client.Eth1.GetGasPrice()); }
public NetworkConfig(IndexerConfiguration config, ChainConfiguration chainConfig, NetworkConfiguration networkConfig) { CoinTicker = chainConfig.Symbol; var consensusFactory = (ConsensusFactory)Activator.CreateInstance(Type.GetType(networkConfig.NetworkConsensusFactoryType)); Consensus = new ConsensusConfig(config, consensusFactory); Base58Prefixes = new byte[12][]; Base58Prefixes[(int)Base58Type.PUBKEY_ADDRESS] = new byte[] { (networkConfig.NetworkPubkeyAddressPrefix) }; Base58Prefixes[(int)Base58Type.SCRIPT_ADDRESS] = new byte[] { (networkConfig.NetworkScriptAddressPrefix) }; Bech32Encoders = new Bech32Encoder[2]; var encoder = new Bech32Encoder(networkConfig.NetworkWitnessPrefix); Bech32Encoders[(int)Bech32Type.WITNESS_PUBKEY_ADDRESS] = encoder; Bech32Encoders[(int)Bech32Type.WITNESS_SCRIPT_ADDRESS] = encoder; // TODO //StandardScripts.RegisterStandardScriptTemplate(ColdStakingScriptTemplate); }
public void BuildConfig() { ClientConfiguration clientConfig = _client.Configuration; ChainConfiguration mainNetConfiguration = new ChainConfiguration(Chain.Mainnet, clientConfig); mainNetConfiguration.NeedsUpdate = false; mainNetConfiguration.Contract = "0xac1b824795e1eb1f6e609fe0da9b9af8beaab60f"; mainNetConfiguration.RegistryId = "0x23d5345c5c13180a8080bd5ddbe7cde64683755dcce6e734d95b7b573845facb"; ChainConfiguration ipfsConfiguration = new ChainConfiguration(Chain.Ipfs, clientConfig); ipfsConfiguration.NeedsUpdate = false; ipfsConfiguration.Contract = "0xac1b824795e1eb1f6e609fe0da9b9af8beaab60f"; ipfsConfiguration.RegistryId = "0x23d5345c5c13180a8080bd5ddbe7cde64683755dcce6e734d95b7b573845facb"; clientConfig.RequestCount = 1; clientConfig.AutoUpdateList = false; clientConfig.Proof = Proof.None; clientConfig.MaxAttempts = 10; clientConfig.SignatureCount = 0; }
public BitcoinDWaiter( RPCClient rpc, ExplorerConfiguration configuration, NBXplorerNetwork network, SlimChain chain, Repository repository, AddressPoolService addressPoolService, EventAggregator eventAggregator) { if (addressPoolService == null) { throw new ArgumentNullException(nameof(addressPoolService)); } _RPC = rpc; _Configuration = configuration; _AddressPoolService = addressPoolService; _Network = network; _Chain = chain; _Repository = repository; State = BitcoinDWaiterState.NotStarted; _EventAggregator = eventAggregator; _ChainConfiguration = _Configuration.ChainConfigurations.First(c => c.CryptoCode == _Network.CryptoCode); }
/// <summary> /// Initializes a new instance of the <see cref="SyncConnection"/> class. /// </summary> public SyncConnection(IOptions <IndexerConfiguration> config, IOptions <ChainConfiguration> chainConfig, IOptions <NetworkConfiguration> networkConfig) { IndexerConfiguration configuration = config.Value; ChainConfiguration chainConfiguration = chainConfig.Value; NetworkConfiguration networkConfiguration = networkConfig.Value; Symbol = chainConfiguration.Symbol; Password = configuration.RpcPassword; // Take the RPC Port from the Indexer configuration, if it is specified. Otherwise we'll use the default for this chain. RpcAccessPort = configuration.RpcAccessPort != 0 ? configuration.RpcAccessPort : networkConfiguration.RPCPort; ServerDomain = configuration.RpcDomain.Replace("{Symbol}", chainConfiguration.Symbol.ToLower()); User = configuration.RpcUser; Secure = configuration.RpcSecure; StartBlockIndex = configuration.StartBlockIndex; // This can be replaced with a specific the network class of a specific coin // Or use the config values to simulate the network class. Network = new NetworkConfig(configuration, chainConfiguration, networkConfiguration); RecentItems = new Buffer <(DateTime Inserted, TimeSpan Duration, long Size)>(5000); }
public void ObjectHierarchy() { string nodeConfigOutputKey = "nodes"; ClientConfiguration clientConfig = _client.Configuration; ChainConfiguration chainConfig = new ChainConfiguration(Chain.Goerli, clientConfig) { NeedsUpdate = false, RegistryId = "0x23d5345c5c13180a8080bd5ddbe7cde64683755dcce6e734d95b7b573845facb", Contract = "0xdd80249a0631cf0f1593c7a9c9f9b8545e6c88ab", WhiteListContract = "0xdd80249a0631cf0f1593c7a9c9f9b8545e6c88ab" }; string jsonConfiguration1 = clientConfig.ToJson(); JsonDocument jsonObject1 = JsonDocument.Parse(jsonConfiguration1); var propertiesName = jsonObject1.RootElement.EnumerateObject().Select(prop => prop.Name); Assert.That(propertiesName.Contains(nodeConfigOutputKey)); NodeConfiguration nodeListConfig = new NodeConfiguration(chainConfig) { Props = 0x0, Url = "scheme://userinfo@host:port/path?query#fragment", Address = "0x0" }; string jsonConfiguration2 = clientConfig.ToJson(); JsonDocument jsonObject2 = JsonDocument.Parse(jsonConfiguration2); Assert.DoesNotThrow(() => jsonObject2 .RootElement .GetProperty(nodeConfigOutputKey) .GetProperty("0x5")); }
public BitcoinDWaiter( RPCClient rpc, ExplorerConfiguration configuration, NBXplorerNetwork network, SlimChain chain, Repository repository, AddressPoolService addressPoolService, EventAggregator eventAggregator) { if (addressPoolService == null) { throw new ArgumentNullException(nameof(addressPoolService)); } _RPC = rpc; _Configuration = configuration; _AddressPoolService = addressPoolService; _Network = network; _Chain = chain; _Repository = repository; State = BitcoinDWaiterState.NotStarted; _EventAggregator = eventAggregator; _ChainConfiguration = _Configuration.ChainConfigurations.First(c => c.CryptoCode == _Network.CryptoCode); RPCReadyFile = Path.Combine(configuration.DataDir, $"{network.CryptoCode.ToLowerInvariant()}_fully_synched"); }
/// <summary> /// Initializes a new instance of the <see cref="QueryHandler"/> class. /// </summary> public QueryHandler(IOptions <IndexerConfiguration> configuration, IOptions <ChainConfiguration> chainConfiguration, IStorage storage) { this.storage = storage; this.configuration = configuration.Value; this.chainConfiguration = chainConfiguration.Value; }
public Config LoadArgs(IConfiguration config, ILogger logger) { var networkType = config.GetNetworkType(); logger.LogInformation($"Network type: {networkType}"); NetworkProvider = new NRustLightningNetworkProvider(networkType); var defaultSettings = NRustLightningDefaultSettings.GetDefaultSettings(NetworkProvider.NetworkType); DataDir = config.GetOrDefault <string>("datadir", null); if (DataDir is null) { DataDir = Path.GetDirectoryName(defaultSettings.DefaultDataDir); if (!Directory.Exists(DataDir)) { Directory.CreateDirectory(DataDir); } if (!Directory.Exists(defaultSettings.DefaultDataDir)) { Directory.CreateDirectory(defaultSettings.DefaultDataDir); } } var nbxConfig = config.GetSection("nbx"); var nbxCookieFile = nbxConfig.GetOrDefault("cookiefile", Constants.DefaultNBXplorerCookieFile(NetworkProvider.NetworkType)); NBXplorerUri = new Uri(nbxConfig.GetOrDefault("rpcurl", Constants.DefaultNBXplorerUri)); if (!File.Exists(nbxCookieFile)) { logger.LogWarning($"cookie file for nbxplorer does not exist in {nbxCookieFile}" + " Make sure you are running nbx with --noauth."); } logger.LogInformation($"nbxplorer url {NBXplorerUri}"); NBXCookieFile = nbxCookieFile; var p2pExternalIp = config.GetOrDefault("externalip", Constants.DefaultP2PExternalIpStr); if (IPEndPoint.TryParse(p2pExternalIp, out var ip)) { P2PExternalIp = ip; } else if (p2pExternalIp.Contains(":")) { var s = p2pExternalIp.Split(":", StringSplitOptions.RemoveEmptyEntries); if (s.Length != 2) { throw new ConfigException($"Invalid external ip {p2pExternalIp}"); } if (Int32.TryParse(s[1], out var port)) { P2PExternalIp = new DnsEndPoint(s[0], port); } else { throw new ConfigException($"Invalid external ip {p2pExternalIp}"); } } else { throw new ConfigException($"Invalid external ip {p2pExternalIp}"); } logger.LogInformation($"Advertising external ip: {P2PExternalIp.ToEndpointString()}"); logger.LogDebug($"Network: {NetworkProvider.NetworkType.ToString()}"); var supportedChains = config.GetOrDefault <string>("chains", "BTC") .Split(',', StringSplitOptions.RemoveEmptyEntries) .Select(t => t.ToLowerInvariant()); var validChains = new List <string>(); foreach (var n in NetworkProvider.GetAll()) { if (supportedChains.Contains(n.CryptoCode)) { validChains.Add(n.CryptoCode); var chainConfiguration = new ChainConfiguration(); chainConfiguration.CryptoCode = n.CryptoCode; var args = RPCArgs.Parse(config, n.NBitcoinNetwork, n.CryptoCode); chainConfiguration.Rpc = args.ConfigureRPCClient(n, logger); if (chainConfiguration.Rpc.Address.Port == n.NBitcoinNetwork.DefaultPort) { logger.LogWarning($"{n.CryptoCode}: It seems that the1 RPC port ({chainConfiguration.Rpc.Address.Port}) is equal to the default P2P port ({n.NBitcoinNetwork.DefaultPort}, this is probably a misconfiguration)"); } if ((chainConfiguration.Rpc.CredentialString.CookieFile != null || chainConfiguration.Rpc.CredentialString.UseDefault) && !n.SupportCookieAuthentication) { throw new ConfigException($"Chain {n.CryptoCode} does not support cookie file authentication,\n" + $"Please use {n.CryptoCode.ToLowerInvariant()}rpcuser and {n.CryptoCode.ToLowerInvariant()}rpcpassword settings in NRustLightning" + $"And configure rpcuser and rpcpassword in the configuration file or in commandline or your node"); } ChainConfiguration.Add(chainConfiguration); } } var invalidChains = String.Join(',', supportedChains.Where(s => !validChains.Contains(s))); if (!string.IsNullOrEmpty(invalidChains)) { throw new ConfigException($"Invalid chains {invalidChains}"); } config.GetSection("ln").Bind(RustLightningConfig); string?seed = null; var filePath = Path.Join(DataDir, "node_secret"); if (File.Exists(filePath)) { logger.LogDebug($"reading seed from {filePath}"); seed = File.ReadAllText(filePath); } if (seed is null) { seed = config.GetOrDefault("seed", String.Empty); } if (String.IsNullOrEmpty(seed)) { logger.LogWarning($"seed not found in {filePath}! You can specify it with --seed option."); logger.LogInformation("generating new seed..."); seed = RandomUtils.GetUInt256().ToString(); } InvoiceDBFilePath = Path.Combine(DataDir, "InvoiceDb"); if (!Directory.Exists(InvoiceDBFilePath)) { Directory.CreateDirectory(InvoiceDBFilePath); } var h = new HexEncoder(); if (!(h.IsValid(seed) && seed.Length == 64)) { throw new NRustLightningException($"Seed corrupted {seed}"); } File.WriteAllText(filePath, seed); GetSeed = async() => { var s = await File.ReadAllTextAsync(filePath); return(h.DecodeData(s)); }; PaymentTimeoutSec = config.GetOrDefault("paymenttimeout", Constants.DefaultPaymentTimeoutSec); DBCacheMB = config.GetOrDefault("dbcache", Constants.DefaultDBCacheMB); return(this); }
public Config LoadArgs(IConfiguration config, ILogger?logger) { _logger = logger; var networkType = config.GetNetworkType(); logger?.LogInformation($"Network type: {networkType}"); NetworkProvider = new NRustLightningNetworkProvider(networkType); var defaultSettings = NRustLightningDefaultSettings.GetDefaultSettings(NetworkProvider.NetworkType); var d = config.GetOrDefault <string>("datadir", null); DataDir = d is null?Path.GetDirectoryName(defaultSettings.DefaultDataDir) : Path.Join(d, NRustLightningDefaultSettings.GetFolderName(networkType)); if (!Directory.Exists(DataDir)) { Directory.CreateDirectory(DataDir ?? throw new Exception("Unreachable")); } var nbxConfig = config.GetSection("nbx"); var nbxCookieFile = nbxConfig.GetOrDefault("cookiefile", Constants.DefaultNbXplorerCookieFile(NetworkProvider.NetworkType)); NBXplorerUri = new Uri(nbxConfig.GetOrDefault("rpcurl", Constants.DefaultNBXplorerUri)); if (!File.Exists(nbxCookieFile)) { logger?.LogWarning($"cookie file for nbxplorer does not exist in {nbxCookieFile}" + " Make sure you are running nbx with --noauth."); } logger?.LogInformation($"nbxplorer url {NBXplorerUri}"); NBXCookieFile = nbxCookieFile; var p2pExternalIp = config.GetOrDefault("externalip", Constants.DefaultP2PExternalIpStr); if (NBitcoin.Utils.TryParseEndpoint(p2pExternalIp, Constants.DefaultP2PPort, out var ip)) { P2PExternalIp = ip; } else if (p2pExternalIp.Contains(":")) { var s = p2pExternalIp.Split(":", StringSplitOptions.RemoveEmptyEntries); if (s.Length != 2) { throw new ConfigException($"Invalid external ip {p2pExternalIp}"); } if (Int32.TryParse(s[1], out var port)) { P2PExternalIp = new DnsEndPoint(s[0], port); } else { throw new ConfigException($"Invalid external ip {p2pExternalIp}"); } } else { throw new ConfigException($"Invalid external ip {p2pExternalIp}"); } logger?.LogInformation($"Advertising external ip: {P2PExternalIp.ToEndpointString()}"); logger?.LogDebug($"Network: {NetworkProvider.NetworkType.ToString()}"); var supportedChains = config.GetOrDefault <string>("chains", "BTC") .Split(',', StringSplitOptions.RemoveEmptyEntries) .Select(t => t.ToLowerInvariant()); var validChains = new List <string>(); foreach (var n in NetworkProvider.GetAll()) { if (supportedChains.Contains(n.CryptoCode)) { validChains.Add(n.CryptoCode); var chainConfiguration = new ChainConfiguration(); chainConfiguration.CryptoCode = n.CryptoCode; var args = RPCArgs.Parse(config, n.NBitcoinNetwork, n.CryptoCode); chainConfiguration.Rpc = args.ConfigureRPCClient(n, logger); if (chainConfiguration.Rpc.Address.Port == n.NBitcoinNetwork.DefaultPort) { logger?.LogWarning($"{n.CryptoCode}: It seems that the1 RPC port ({chainConfiguration.Rpc.Address.Port}) is equal to the default P2P port ({n.NBitcoinNetwork.DefaultPort}, this is probably a misconfiguration)"); } if ((chainConfiguration.Rpc.CredentialString.CookieFile != null || chainConfiguration.Rpc.CredentialString.UseDefault) && !n.SupportCookieAuthentication) { throw new ConfigException($"Chain {n.CryptoCode} does not support cookie file authentication,\n" + $"Please use {n.CryptoCode.ToLowerInvariant()}rpcuser and {n.CryptoCode.ToLowerInvariant()}rpcpassword settings in NRustLightning" + $"And configure rpcuser and rpcpassword in the configuration file or in commandline or your node"); } ChainConfiguration.Add(chainConfiguration); } } var invalidChains = String.Join(',', supportedChains.Where(s => !validChains.Contains(s))); if (!string.IsNullOrEmpty(invalidChains)) { throw new ConfigException($"Invalid chains {invalidChains}"); } config.GetSection("ln").Bind(RustLightningConfig); DBFilePath = Path.Combine(DataDir, "Db.dat"); if (!Directory.Exists(DBFilePath)) { Directory.CreateDirectory(DBFilePath); } PaymentTimeoutSec = config.GetOrDefault("paymenttimeout", Constants.DefaultPaymentTimeoutSec); DBCacheMB = config.GetOrDefault("dbcache", Constants.DefaultDBCacheMB); _seedFromConfig = config.GetOrDefault("seed", string.Empty); _pin = config.GetOrDefault("pin", string.Empty); SeedFilePath = Path.Join(DataDir, "node_secret"); return(this); }