Exemple #1
0
        public void InitBitcoin()
        {
            var nbxplorerNetwork = NBXplorerNetworkProvider.GetFromCryptoCode("BTC");
            var coinaverage      = new CoinAverageRateProvider("BTC");
            var bitpay           = new BitpayRateProvider(new Bitpay(new Key(), new Uri("https://bitpay.com/")));
            var btcRate          = new FallbackRateProvider(new IRateProvider[] { coinaverage, bitpay });

            Add(new BTCPayNetwork()
            {
                CryptoCode          = nbxplorerNetwork.CryptoCode,
                BlockExplorerLink   = NBXplorerNetworkProvider.ChainType == ChainType.Main? "https://www.smartbit.com.au/tx/{0}" : "https://testnet.smartbit.com.au/tx/{0}",
                NBitcoinNetwork     = nbxplorerNetwork.NBitcoinNetwork,
                NBXplorerNetwork    = nbxplorerNetwork,
                UriScheme           = "bitcoin",
                DefaultRateProvider = btcRate,
                CryptoImagePath     = "imlegacy/bitcoin-symbol.svg",
                DefaultSettings     = BTCPayDefaultSettings.GetDefaultSettings(NBXplorerNetworkProvider.ChainType)
            });
        }
 public IRateProvider ApplyRateRules(BTCPayNetwork network, IRateProvider rateProvider)
 {
     if (!PreferredExchange.IsCoinAverage())
     {
         // If the original rateProvider is a cache, use the same inner provider as fallback, and same memory cache to wrap it all
         if (rateProvider is CachedRateProvider cachedRateProvider)
         {
             rateProvider = new FallbackRateProvider(new IRateProvider[] {
                 new CoinAverageRateProvider(network.CryptoCode)
                 {
                     Exchange = PreferredExchange
                 },
                 cachedRateProvider.Inner
             });
             rateProvider = new CachedRateProvider(network.CryptoCode, rateProvider, cachedRateProvider.MemoryCache)
             {
                 AdditionalScope = PreferredExchange
             };
         }
         else
         {
             rateProvider = new FallbackRateProvider(new IRateProvider[] {
                 new CoinAverageRateProvider(network.CryptoCode)
                 {
                     Exchange = PreferredExchange
                 },
                 rateProvider
             });
         }
     }
     if (RateRules == null || RateRules.Count == 0)
     {
         return(rateProvider);
     }
     return(new TweakRateProvider(network, rateProvider, RateRules.ToList()));
 }
        public BTCPayNetworkProvider(Network network)
        {
            var coinaverage = new CoinAverageRateProvider("BTC");
            var bitpay      = new BitpayRateProvider(new Bitpay(new Key(), new Uri("https://bitpay.com/")));
            var btcRate     = new FallbackRateProvider(new IRateProvider[] { coinaverage, bitpay });

            var ltcRate = new CoinAverageRateProvider("LTC");

            if (network == Network.Main)
            {
                Add(new BTCPayNetwork()
                {
                    CryptoCode          = "BTC",
                    BlockExplorerLink   = "https://www.smartbit.com.au/tx/{0}",
                    NBitcoinNetwork     = Network.Main,
                    UriScheme           = "bitcoin",
                    DefaultRateProvider = btcRate,
                    CryptoImagePath     = "imlegacy/bitcoin-symbol.svg"
                });
                Add(new BTCPayNetwork()
                {
                    CryptoCode          = "LTC",
                    BlockExplorerLink   = "https://live.blockcypher.com/ltc/tx/{0}/",
                    NBitcoinNetwork     = NBXplorer.Altcoins.Litecoin.Networks.Mainnet,
                    UriScheme           = "litecoin",
                    DefaultRateProvider = ltcRate,
                    CryptoImagePath     = "imlegacy/litecoin-symbol.svg"
                });
            }

            if (network == Network.TestNet)
            {
                Add(new BTCPayNetwork()
                {
                    CryptoCode          = "BTC",
                    BlockExplorerLink   = "https://testnet.smartbit.com.au/tx/{0}",
                    NBitcoinNetwork     = Network.TestNet,
                    UriScheme           = "bitcoin",
                    DefaultRateProvider = btcRate,
                    CryptoImagePath     = "imlegacy/bitcoin-symbol.svg"
                });
                Add(new BTCPayNetwork()
                {
                    CryptoCode          = "LTC",
                    BlockExplorerLink   = "http://explorer.litecointools.com/tx/{0}",
                    NBitcoinNetwork     = NBXplorer.Altcoins.Litecoin.Networks.Testnet,
                    UriScheme           = "litecoin",
                    DefaultRateProvider = ltcRate,
                    CryptoImagePath     = "imlegacy/litecoin-symbol.svg"
                });
            }

            if (network == Network.RegTest)
            {
                Add(new BTCPayNetwork()
                {
                    CryptoCode          = "BTC",
                    BlockExplorerLink   = "https://testnet.smartbit.com.au/tx/{0}",
                    NBitcoinNetwork     = Network.RegTest,
                    UriScheme           = "bitcoin",
                    DefaultRateProvider = btcRate,
                    CryptoImagePath     = "imlegacy/bitcoin-symbol.svg"
                });
                Add(new BTCPayNetwork()
                {
                    CryptoCode          = "LTC",
                    BlockExplorerLink   = "http://explorer.litecointools.com/tx/{0}",
                    NBitcoinNetwork     = NBXplorer.Altcoins.Litecoin.Networks.Regtest,
                    UriScheme           = "litecoin",
                    DefaultRateProvider = ltcRate,
                    CryptoImagePath     = "imlegacy/litecoin-symbol.svg"
                });
            }
        }