2020-06-29 04:44:35 +02:00
|
|
|
using System;
|
2017-12-21 07:52:04 +01:00
|
|
|
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;
|
2021-07-30 11:47:02 +02:00
|
|
|
using BTCPayServer.Common;
|
2017-12-21 07:52:04 +01:00
|
|
|
using NBitcoin;
|
2018-01-12 03:54:57 +01:00
|
|
|
using NBXplorer;
|
2019-12-24 08:20:44 +01:00
|
|
|
using NBXplorer.Models;
|
2017-12-21 07:52:04 +01:00
|
|
|
|
|
|
|
namespace BTCPayServer
|
|
|
|
{
|
2019-05-09 12:05:08 +02:00
|
|
|
public enum DerivationType
|
|
|
|
{
|
|
|
|
Legacy,
|
|
|
|
SegwitP2SH,
|
|
|
|
Segwit
|
|
|
|
}
|
2018-01-11 14:52:28 +01:00
|
|
|
public class BTCPayDefaultSettings
|
|
|
|
{
|
|
|
|
static BTCPayDefaultSettings()
|
|
|
|
{
|
2021-01-27 06:39:38 +01:00
|
|
|
_Settings = new Dictionary<ChainName, BTCPayDefaultSettings>();
|
|
|
|
}
|
|
|
|
|
|
|
|
static readonly Dictionary<ChainName, BTCPayDefaultSettings> _Settings;
|
|
|
|
|
|
|
|
public static BTCPayDefaultSettings GetDefaultSettings(ChainName chainType)
|
|
|
|
{
|
|
|
|
if (_Settings.TryGetValue(chainType, out var v))
|
|
|
|
return v;
|
|
|
|
lock (_Settings)
|
2018-01-11 14:52:28 +01:00
|
|
|
{
|
2021-01-27 06:39:38 +01:00
|
|
|
if (_Settings.TryGetValue(chainType, out v))
|
|
|
|
return v;
|
2018-01-11 14:52:28 +01:00
|
|
|
var settings = new BTCPayDefaultSettings();
|
|
|
|
_Settings.Add(chainType, settings);
|
2018-04-19 09:54:25 +02:00
|
|
|
settings.DefaultDataDirectory = StandardConfiguration.DefaultDataDirectory.GetDirectory("BTCPayServer", NBXplorerDefaultSettings.GetFolderName(chainType));
|
2020-10-21 14:02:20 +02:00
|
|
|
settings.DefaultPluginDirectory =
|
2020-11-05 10:21:09 +01:00
|
|
|
StandardConfiguration.DefaultDataDirectory.GetDirectory("BTCPayServer", "Plugins");
|
2018-01-11 14:52:28 +01:00
|
|
|
settings.DefaultConfigurationFile = Path.Combine(settings.DefaultDataDirectory, "settings.config");
|
2021-01-27 06:39:38 +01:00
|
|
|
settings.DefaultPort = (chainType == ChainName.Mainnet ? 23000 :
|
|
|
|
chainType == ChainName.Regtest ? 23002
|
|
|
|
: 23001);
|
2018-01-11 14:52:28 +01:00
|
|
|
}
|
|
|
|
return _Settings[chainType];
|
|
|
|
}
|
|
|
|
|
|
|
|
public string DefaultDataDirectory { get; set; }
|
2020-10-21 14:02:20 +02:00
|
|
|
public string DefaultPluginDirectory { get; set; }
|
2018-01-11 14:52:28 +01:00
|
|
|
public string DefaultConfigurationFile { get; set; }
|
|
|
|
public int DefaultPort { get; set; }
|
|
|
|
}
|
2019-05-29 11:43:50 +02:00
|
|
|
|
2020-06-28 10:55:27 +02:00
|
|
|
public class BTCPayNetwork : BTCPayNetworkBase
|
2017-12-21 07:52:04 +01:00
|
|
|
{
|
2020-06-28 10:55:27 +02:00
|
|
|
public Network NBitcoinNetwork { get { return NBXplorerNetwork?.NBitcoinNetwork; } }
|
2018-01-12 03:54:57 +01:00
|
|
|
public NBXplorer.NBXplorerNetwork NBXplorerNetwork { get; set; }
|
2021-04-01 08:56:22 +02:00
|
|
|
public bool SupportRBF { get; set; }
|
2019-05-29 11:43:50 +02:00
|
|
|
public string LightningImagePath { get; set; }
|
2018-01-11 14:52:28 +01:00
|
|
|
public BTCPayDefaultSettings DefaultSettings { get; set; }
|
2021-01-07 14:49:53 +01:00
|
|
|
public KeyPath CoinType { get; set; }
|
2020-06-28 10:55:27 +02:00
|
|
|
|
2019-05-09 12:05:08 +02:00
|
|
|
public Dictionary<uint, DerivationType> ElectrumMapping = new Dictionary<uint, DerivationType>();
|
2019-05-29 11:43:50 +02:00
|
|
|
|
2019-12-24 08:20:44 +01:00
|
|
|
public virtual bool WalletSupported { get; set; } = true;
|
2020-06-28 10:55:27 +02:00
|
|
|
public virtual bool ReadonlyWallet { get; set; } = false;
|
2021-03-09 04:45:56 +01:00
|
|
|
public virtual bool VaultSupported { get; set; } = false;
|
2021-04-01 08:56:22 +02:00
|
|
|
public int MaxTrackedConfirmation { get; set; } = 6;
|
2020-03-29 17:28:22 +02:00
|
|
|
public bool SupportPayJoin { get; set; } = false;
|
2020-04-27 11:15:38 +02:00
|
|
|
public bool SupportLightning { get; set; } = true;
|
2020-03-29 17:28:22 +02:00
|
|
|
|
2019-05-29 11:43:50 +02:00
|
|
|
public override T ToObject<T>(string json)
|
|
|
|
{
|
|
|
|
return NBXplorerNetwork.Serializer.ToObject<T>(json);
|
|
|
|
}
|
|
|
|
|
|
|
|
public override string ToString<T>(T obj)
|
|
|
|
{
|
|
|
|
return NBXplorerNetwork.Serializer.ToString(obj);
|
|
|
|
}
|
2019-12-24 08:20:44 +01:00
|
|
|
public virtual IEnumerable<(MatchedOutput matchedOutput, OutPoint outPoint)> GetValidOutputs(NewTransactionEvent evtOutputs)
|
|
|
|
{
|
|
|
|
return evtOutputs.Outputs.Select(output =>
|
|
|
|
{
|
|
|
|
var outpoint = new OutPoint(evtOutputs.TransactionData.TransactionHash, output.Index);
|
|
|
|
return (output, outpoint);
|
|
|
|
});
|
|
|
|
}
|
2020-01-16 07:01:01 +01:00
|
|
|
|
2021-07-30 11:47:02 +02:00
|
|
|
public virtual PaymentUrlBuilder GenerateBIP21(string cryptoInfoAddress, Money cryptoInfoDue)
|
2020-01-16 07:01:01 +01:00
|
|
|
{
|
2021-10-23 07:47:15 +02:00
|
|
|
var builder = new PaymentUrlBuilder(this.NBitcoinNetwork.UriScheme);
|
2021-07-30 11:47:02 +02:00
|
|
|
builder.Host = cryptoInfoAddress;
|
|
|
|
if (cryptoInfoDue != null && cryptoInfoDue != Money.Zero)
|
|
|
|
{
|
|
|
|
builder.QueryParams.Add("amount", cryptoInfoDue.ToString(false, true));
|
|
|
|
}
|
|
|
|
return builder;
|
2020-01-16 07:01:01 +01:00
|
|
|
}
|
2020-05-03 18:04:34 +02:00
|
|
|
|
2021-03-11 13:34:52 +01:00
|
|
|
public virtual List<TransactionInformation> FilterValidTransactions(List<TransactionInformation> transactionInformationSet)
|
2020-05-03 18:04:34 +02:00
|
|
|
{
|
2021-03-11 13:34:52 +01:00
|
|
|
return transactionInformationSet;
|
2020-05-03 18:04:34 +02:00
|
|
|
}
|
2019-05-29 11:43:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public abstract class BTCPayNetworkBase
|
|
|
|
{
|
2020-10-21 09:53:05 +02:00
|
|
|
private string _blockExplorerLink;
|
2020-01-26 11:45:52 +01:00
|
|
|
public bool ShowSyncSummary { get; set; } = true;
|
2021-01-07 14:49:53 +01:00
|
|
|
public string CryptoCode { get; set; }
|
2020-10-21 09:53:05 +02:00
|
|
|
|
|
|
|
public string BlockExplorerLink
|
|
|
|
{
|
|
|
|
get => _blockExplorerLink;
|
|
|
|
set
|
|
|
|
{
|
|
|
|
if (string.IsNullOrEmpty(BlockExplorerLinkDefault))
|
|
|
|
{
|
|
|
|
BlockExplorerLinkDefault = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
_blockExplorerLink = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-01 08:56:22 +02:00
|
|
|
public string BlockExplorerLinkDefault { get; set; }
|
2019-05-29 11:43:50 +02:00
|
|
|
public string DisplayName { get; set; }
|
2020-01-21 14:28:13 +01:00
|
|
|
public int Divisibility { get; set; } = 8;
|
2019-05-29 11:43:50 +02:00
|
|
|
public bool IsBTC
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return CryptoCode == "BTC";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public string CryptoImagePath { get; set; }
|
2021-01-07 14:49:53 +01:00
|
|
|
public string[] DefaultRateRules { get; set; } = Array.Empty<string>();
|
2019-05-29 11:43:50 +02:00
|
|
|
public override string ToString()
|
|
|
|
{
|
|
|
|
return CryptoCode;
|
|
|
|
}
|
|
|
|
|
|
|
|
public virtual T ToObject<T>(string json)
|
|
|
|
{
|
2019-11-17 05:04:42 +01:00
|
|
|
return NBitcoin.JsonConverters.Serializer.ToObject<T>(json, null);
|
2019-05-29 11:43:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public virtual string ToString<T>(T obj)
|
|
|
|
{
|
2019-09-30 10:32:43 +02:00
|
|
|
return NBitcoin.JsonConverters.Serializer.ToString(obj, null);
|
2018-04-12 04:48:33 +02:00
|
|
|
}
|
2017-12-21 07:52:04 +01:00
|
|
|
}
|
|
|
|
}
|