2017-12-21 07:52:04 +01:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2018-01-11 14:52:28 +01:00
|
|
|
|
using System.IO;
|
2017-12-21 07:52:04 +01:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
2018-01-08 18:57:06 +01:00
|
|
|
|
using BTCPayServer.Services.Rates;
|
|
|
|
|
using Microsoft.Extensions.Caching.Memory;
|
2017-12-21 07:52:04 +01:00
|
|
|
|
using NBitcoin;
|
2018-01-08 18:57:06 +01:00
|
|
|
|
using NBitpayClient;
|
2018-01-12 03:54:57 +01:00
|
|
|
|
using NBXplorer;
|
2017-12-21 07:52:04 +01:00
|
|
|
|
|
|
|
|
|
namespace BTCPayServer
|
|
|
|
|
{
|
2018-01-12 03:54:57 +01:00
|
|
|
|
public partial class BTCPayNetworkProvider
|
2017-12-21 07:52:04 +01:00
|
|
|
|
{
|
|
|
|
|
Dictionary<string, BTCPayNetwork> _Networks = new Dictionary<string, BTCPayNetwork>();
|
2018-01-08 18:57:06 +01:00
|
|
|
|
|
2017-12-21 07:52:04 +01:00
|
|
|
|
|
2018-01-12 03:54:57 +01:00
|
|
|
|
private readonly NBXplorerNetworkProvider _NBXplorerNetworkProvider;
|
|
|
|
|
public NBXplorerNetworkProvider NBXplorerNetworkProvider
|
|
|
|
|
{
|
|
|
|
|
get
|
2017-12-21 07:52:04 +01:00
|
|
|
|
{
|
2018-01-12 03:54:57 +01:00
|
|
|
|
return _NBXplorerNetworkProvider;
|
2017-12-21 07:52:04 +01:00
|
|
|
|
}
|
2018-01-12 03:54:57 +01:00
|
|
|
|
}
|
2018-01-11 14:52:28 +01:00
|
|
|
|
|
2018-02-25 16:48:12 +01:00
|
|
|
|
BTCPayNetworkProvider(BTCPayNetworkProvider filtered, string[] cryptoCodes)
|
|
|
|
|
{
|
2018-04-19 09:54:25 +02:00
|
|
|
|
NetworkType = filtered.NetworkType;
|
|
|
|
|
_NBXplorerNetworkProvider = new NBXplorerNetworkProvider(filtered.NetworkType);
|
2018-02-25 16:48:12 +01:00
|
|
|
|
_Networks = new Dictionary<string, BTCPayNetwork>();
|
|
|
|
|
cryptoCodes = cryptoCodes.Select(c => c.ToUpperInvariant()).ToArray();
|
|
|
|
|
foreach (var network in filtered._Networks)
|
|
|
|
|
{
|
|
|
|
|
if(cryptoCodes.Contains(network.Key))
|
|
|
|
|
{
|
|
|
|
|
_Networks.Add(network.Key, network.Value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-19 09:54:25 +02:00
|
|
|
|
public NetworkType NetworkType { get; private set; }
|
|
|
|
|
public BTCPayNetworkProvider(NetworkType networkType)
|
2018-01-12 03:54:57 +01:00
|
|
|
|
{
|
2018-04-19 09:54:25 +02:00
|
|
|
|
_NBXplorerNetworkProvider = new NBXplorerNetworkProvider(networkType);
|
|
|
|
|
NetworkType = networkType;
|
2018-01-12 03:54:57 +01:00
|
|
|
|
InitBitcoin();
|
|
|
|
|
InitLitecoin();
|
2018-04-10 12:07:57 +02:00
|
|
|
|
InitDogecoin();
|
2018-05-05 20:56:44 +02:00
|
|
|
|
InitBitcoinGold();
|
2018-05-11 07:24:29 +02:00
|
|
|
|
InitMonacoin();
|
2018-04-17 18:13:50 +02:00
|
|
|
|
InitPolis();
|
2018-06-03 14:30:43 +02:00
|
|
|
|
InitFeathercoin();
|
2018-06-23 17:45:57 +02:00
|
|
|
|
InitGroestlcoin();
|
2018-06-09 17:25:45 +02:00
|
|
|
|
InitUfo();
|
2017-12-21 07:52:04 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-02-25 16:48:12 +01:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Keep only the specified crypto
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="cryptoCodes">Crypto to support</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public BTCPayNetworkProvider Filter(string[] cryptoCodes)
|
|
|
|
|
{
|
|
|
|
|
return new BTCPayNetworkProvider(this, cryptoCodes);
|
|
|
|
|
}
|
|
|
|
|
|
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)
|
|
|
|
|
{
|
2018-02-25 16:48:12 +01:00
|
|
|
|
_Networks.Add(network.CryptoCode.ToUpperInvariant(), network);
|
2017-12-21 07:52:04 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-01-07 18:36:41 +01:00
|
|
|
|
public IEnumerable<BTCPayNetwork> GetAll()
|
|
|
|
|
{
|
|
|
|
|
return _Networks.Values.ToArray();
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-25 16:48:12 +01:00
|
|
|
|
public bool Support(string cryptoCode)
|
|
|
|
|
{
|
|
|
|
|
return _Networks.ContainsKey(cryptoCode.ToUpperInvariant());
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-21 07:52:04 +01:00
|
|
|
|
public BTCPayNetwork GetNetwork(string cryptoCode)
|
|
|
|
|
{
|
2018-05-04 08:35:39 +02:00
|
|
|
|
if(!_Networks.TryGetValue(cryptoCode.ToUpperInvariant(), out BTCPayNetwork network))
|
|
|
|
|
{
|
|
|
|
|
if (cryptoCode == "XBT")
|
|
|
|
|
return GetNetwork("BTC");
|
|
|
|
|
}
|
2017-12-21 07:52:04 +01:00
|
|
|
|
return network;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|