using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Threading.Tasks; using BTCPayServer.Services.Rates; using Microsoft.Extensions.Caching.Memory; using NBitcoin; using NBitpayClient; using NBXplorer; namespace BTCPayServer { public partial class BTCPayNetworkProvider { Dictionary _Networks = new Dictionary(); private readonly NBXplorerNetworkProvider _NBXplorerNetworkProvider; public NBXplorerNetworkProvider NBXplorerNetworkProvider { get { return _NBXplorerNetworkProvider; } } BTCPayNetworkProvider(BTCPayNetworkProvider filtered, string[] cryptoCodes) { ChainType = filtered.ChainType; _NBXplorerNetworkProvider = new NBXplorerNetworkProvider(filtered.ChainType); _Networks = new Dictionary(); cryptoCodes = cryptoCodes.Select(c => c.ToUpperInvariant()).ToArray(); foreach (var network in filtered._Networks) { if(cryptoCodes.Contains(network.Key)) { _Networks.Add(network.Key, network.Value); } } } public ChainType ChainType { get; set; } public BTCPayNetworkProvider(ChainType chainType) { _NBXplorerNetworkProvider = new NBXplorerNetworkProvider(chainType); ChainType = chainType; InitBitcoin(); InitLitecoin(); } /// /// Keep only the specified crypto /// /// Crypto to support /// public BTCPayNetworkProvider Filter(string[] cryptoCodes) { return new BTCPayNetworkProvider(this, cryptoCodes); } [Obsolete("To use only for legacy stuff")] public BTCPayNetwork BTC { get { return GetNetwork("BTC"); } } public void Add(BTCPayNetwork network) { _Networks.Add(network.CryptoCode.ToUpperInvariant(), network); } public IEnumerable GetAll() { return _Networks.Values.ToArray(); } public bool Support(string cryptoCode) { return _Networks.ContainsKey(cryptoCode.ToUpperInvariant()); } public BTCPayNetwork GetNetwork(string cryptoCode) { _Networks.TryGetValue(cryptoCode.ToUpperInvariant(), out BTCPayNetwork network); return network; } } }