2017-12-21 07:52:04 +01:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using NBitcoin;
|
|
|
|
|
|
|
|
|
|
namespace BTCPayServer
|
|
|
|
|
{
|
|
|
|
|
public class BTCPayNetworkProvider
|
|
|
|
|
{
|
2018-01-08 15:05:41 +01:00
|
|
|
|
static BTCPayNetworkProvider()
|
|
|
|
|
{
|
|
|
|
|
NBXplorer.Altcoins.Litecoin.Networks.EnsureRegistered();
|
|
|
|
|
}
|
2017-12-21 07:52:04 +01:00
|
|
|
|
Dictionary<string, BTCPayNetwork> _Networks = new Dictionary<string, BTCPayNetwork>();
|
|
|
|
|
public BTCPayNetworkProvider(Network network)
|
|
|
|
|
{
|
2018-01-06 10:57:56 +01:00
|
|
|
|
if (network == Network.Main)
|
2017-12-21 07:52:04 +01:00
|
|
|
|
{
|
|
|
|
|
Add(new BTCPayNetwork()
|
|
|
|
|
{
|
|
|
|
|
CryptoCode = "BTC",
|
|
|
|
|
BlockExplorerLink = "https://www.smartbit.com.au/tx/{0}",
|
|
|
|
|
NBitcoinNetwork = Network.Main,
|
2018-01-07 18:36:41 +01:00
|
|
|
|
UriScheme = "bitcoin",
|
2017-12-21 07:52:04 +01:00
|
|
|
|
});
|
2018-01-08 15:05:41 +01:00
|
|
|
|
Add(new BTCPayNetwork()
|
|
|
|
|
{
|
|
|
|
|
CryptoCode = "LTC",
|
|
|
|
|
BlockExplorerLink = "https://live.blockcypher.com/ltc/tx/{0}/",
|
|
|
|
|
NBitcoinNetwork = NBXplorer.Altcoins.Litecoin.Networks.Mainnet,
|
|
|
|
|
UriScheme = "litecoin",
|
|
|
|
|
});
|
2017-12-21 07:52:04 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (network == Network.TestNet)
|
|
|
|
|
{
|
|
|
|
|
Add(new BTCPayNetwork()
|
|
|
|
|
{
|
|
|
|
|
CryptoCode = "BTC",
|
|
|
|
|
BlockExplorerLink = "https://testnet.smartbit.com.au/tx/{0}",
|
|
|
|
|
NBitcoinNetwork = Network.TestNet,
|
2018-01-07 18:36:41 +01:00
|
|
|
|
UriScheme = "bitcoin",
|
2017-12-21 07:52:04 +01:00
|
|
|
|
});
|
2018-01-08 15:05:41 +01:00
|
|
|
|
Add(new BTCPayNetwork()
|
|
|
|
|
{
|
|
|
|
|
CryptoCode = "LTC",
|
|
|
|
|
BlockExplorerLink = "http://explorer.litecointools.com/tx/{0}",
|
|
|
|
|
NBitcoinNetwork = NBXplorer.Altcoins.Litecoin.Networks.Testnet,
|
|
|
|
|
UriScheme = "litecoin",
|
|
|
|
|
});
|
2017-12-21 07:52:04 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (network == Network.RegTest)
|
|
|
|
|
{
|
|
|
|
|
Add(new BTCPayNetwork()
|
|
|
|
|
{
|
|
|
|
|
CryptoCode = "BTC",
|
|
|
|
|
BlockExplorerLink = "https://testnet.smartbit.com.au/tx/{0}",
|
|
|
|
|
NBitcoinNetwork = Network.RegTest,
|
|
|
|
|
UriScheme = "bitcoin"
|
|
|
|
|
});
|
2018-01-08 15:05:41 +01:00
|
|
|
|
Add(new BTCPayNetwork()
|
|
|
|
|
{
|
|
|
|
|
CryptoCode = "LTC",
|
|
|
|
|
BlockExplorerLink = "http://explorer.litecointools.com/tx/{0}",
|
|
|
|
|
NBitcoinNetwork = NBXplorer.Altcoins.Litecoin.Networks.Regtest,
|
|
|
|
|
UriScheme = "litecoin",
|
|
|
|
|
});
|
2017-12-21 07:52:04 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-08 15:05:41 +01:00
|
|
|
|
[Obsolete("To use only for legacy stuff")]
|
2018-01-06 10:57:56 +01:00
|
|
|
|
public BTCPayNetwork BTC
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return GetNetwork("BTC");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-21 07:52:04 +01:00
|
|
|
|
public void Add(BTCPayNetwork network)
|
|
|
|
|
{
|
|
|
|
|
_Networks.Add(network.CryptoCode, network);
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-07 18:36:41 +01:00
|
|
|
|
public IEnumerable<BTCPayNetwork> GetAll()
|
|
|
|
|
{
|
|
|
|
|
return _Networks.Values.ToArray();
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-21 07:52:04 +01:00
|
|
|
|
public BTCPayNetwork GetNetwork(string cryptoCode)
|
|
|
|
|
{
|
|
|
|
|
_Networks.TryGetValue(cryptoCode.ToUpperInvariant(), out BTCPayNetwork network);
|
|
|
|
|
return network;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|