Пример #1
0
        public CurrencyData GetCurrencyData(string currency, bool useFallback)
        {
            CurrencyData result;

            if (!_Currencies.TryGetValue(currency.ToUpperInvariant(), out result))
            {
                if (useFallback)
                {
                    var usd = GetCurrencyData("USD", false);
                    result = new CurrencyData()
                    {
                        Code         = currency,
                        Crypto       = true,
                        Name         = currency,
                        Divisibility = usd.Divisibility
                    };
                }
            }
            return(result);
        }
Пример #2
0
        static CurrencyData[] LoadCurrency()
        {
            var    stream  = Assembly.GetExecutingAssembly().GetManifestResourceStream("BTCPayServer.Currencies.txt");
            string content = null;

            using (var reader = new StreamReader(stream, Encoding.UTF8))
            {
                content = reader.ReadToEnd();
            }
            var currencies = content.Split(new[] { "\r\n", "\n" }, StringSplitOptions.RemoveEmptyEntries);
            Dictionary <string, CurrencyData> dico = new Dictionary <string, CurrencyData>();

            foreach (var currency in currencies)
            {
                var splitted = currency.Split(new[] { '\t' }, StringSplitOptions.RemoveEmptyEntries);
                if (splitted.Length < 3)
                {
                    continue;
                }
                CurrencyData info = new CurrencyData();
                info.Name = splitted[0];
                info.Code = splitted[1];
                int divisibility;
                if (!int.TryParse(splitted[2], out divisibility))
                {
                    continue;
                }
                info.Divisibility = divisibility;
                if (!dico.ContainsKey(info.Code))
                {
                    dico.Add(info.Code, info);
                }
                if (splitted.Length >= 4)
                {
                    info.Symbol = splitted[3];
                }
            }
            return(dico.Values.ToArray());
        }
        static CurrencyData[] LoadCurrency()
        {
            var    stream  = Assembly.GetExecutingAssembly().GetManifestResourceStream("BTCPayServer.Currencies.txt");
            string content = null;

            using (var reader = new StreamReader(stream, Encoding.UTF8))
            {
                content = reader.ReadToEnd();
            }
            var currencies = content.Split(new[] { "\r\n", "\n" }, StringSplitOptions.RemoveEmptyEntries);
            Dictionary <string, CurrencyData> dico = new Dictionary <string, CurrencyData>();

            foreach (var currency in currencies)
            {
                var splitted = currency.Split(new[] { '\t' }, StringSplitOptions.RemoveEmptyEntries);
                if (splitted.Length < 3)
                {
                    continue;
                }
                CurrencyData info = new CurrencyData();
                info.Name = splitted[0];
                info.Code = splitted[1];
                int divisibility;
                if (!int.TryParse(splitted[2], out divisibility))
                {
                    continue;
                }
                info.Divisibility = divisibility;
                if (!dico.ContainsKey(info.Code))
                {
                    dico.Add(info.Code, info);
                }
                if (splitted.Length >= 4)
                {
                    info.Symbol = splitted[3];
                }
            }

            foreach (var network in new BTCPayNetworkProvider(NetworkType.Mainnet).GetAll())
            {
                if (!dico.TryAdd(network.CryptoCode, new CurrencyData()
                {
                    Code = network.CryptoCode,
                    Divisibility = network.Divisibility,
                    Name = network.CryptoCode,
                    Crypto = true
                }))
                {
                    dico[network.CryptoCode].Crypto = true;
                }
            }

            dico.TryAdd("SATS", new CurrencyData()
            {
                Code         = "SATS",
                Crypto       = true,
                Divisibility = 0,
                Name         = "Satoshis",
                Symbol       = "Sats",
            });

            return(dico.Values.ToArray());
        }