Merge remote-tracking branch 'btcpayserver/master' into feature/crowdfund

This commit is contained in:
Kukks
2019-01-07 10:58:52 +01:00
13 changed files with 47 additions and 28 deletions

View File

@@ -122,7 +122,7 @@ namespace BTCPayServer.Tests
ServerUri = new Uri("http://" + HostName + ":" + Port + "/"); ServerUri = new Uri("http://" + HostName + ":" + Port + "/");
Environment.SetEnvironmentVariable("ASPNETCORE_ENVIRONMENT", "Development"); Environment.SetEnvironmentVariable("ASPNETCORE_ENVIRONMENT", "Development");
var conf = new DefaultConfiguration() { Logger = Logs.LogProvider.CreateLogger("Console") }.CreateConfiguration(new[] { "--datadir", _Directory, "--conf", confPath }); var conf = new DefaultConfiguration() { Logger = Logs.LogProvider.CreateLogger("Console") }.CreateConfiguration(new[] { "--datadir", _Directory, "--conf", confPath, "--disable-registration", "false" });
_Host = new WebHostBuilder() _Host = new WebHostBuilder()
.UseConfiguration(conf) .UseConfiguration(conf)
.ConfigureServices(s => .ConfigureServices(s =>

View File

@@ -101,7 +101,7 @@ namespace BTCPayServer.Tests
Rate = 10513.44m, Rate = 10513.44m,
}.SetPaymentMethodDetails(new BTCPayServer.Payments.Bitcoin.BitcoinLikeOnChainPaymentMethod() }.SetPaymentMethodDetails(new BTCPayServer.Payments.Bitcoin.BitcoinLikeOnChainPaymentMethod()
{ {
NetworkFee = Money.Coins(0.00000100m), NextNetworkFee = Money.Coins(0.00000100m),
DepositAddress = dummy DepositAddress = dummy
})); }));
paymentMethods.Add(new PaymentMethod() paymentMethods.Add(new PaymentMethod()
@@ -110,7 +110,7 @@ namespace BTCPayServer.Tests
Rate = 216.79m Rate = 216.79m
}.SetPaymentMethodDetails(new BTCPayServer.Payments.Bitcoin.BitcoinLikeOnChainPaymentMethod() }.SetPaymentMethodDetails(new BTCPayServer.Payments.Bitcoin.BitcoinLikeOnChainPaymentMethod()
{ {
NetworkFee = Money.Coins(0.00010000m), NextNetworkFee = Money.Coins(0.00010000m),
DepositAddress = dummy DepositAddress = dummy
})); }));
invoiceEntity.SetPaymentMethods(paymentMethods); invoiceEntity.SetPaymentMethods(paymentMethods);
@@ -150,7 +150,7 @@ namespace BTCPayServer.Tests
var entity = new InvoiceEntity(); var entity = new InvoiceEntity();
#pragma warning disable CS0618 #pragma warning disable CS0618
entity.Payments = new System.Collections.Generic.List<PaymentEntity>(); entity.Payments = new System.Collections.Generic.List<PaymentEntity>();
entity.SetPaymentMethod(new PaymentMethod() { CryptoCode = "BTC", Rate = 5000, NetworkFee = Money.Coins(0.1m) }); entity.SetPaymentMethod(new PaymentMethod() { CryptoCode = "BTC", Rate = 5000, NextNetworkFee = Money.Coins(0.1m) });
entity.ProductInformation = new ProductInformation() { Price = 5000 }; entity.ProductInformation = new ProductInformation() { Price = 5000 };
var paymentMethod = entity.GetPaymentMethods(null).TryGet("BTC", PaymentTypes.BTCLike); var paymentMethod = entity.GetPaymentMethods(null).TryGet("BTC", PaymentTypes.BTCLike);
@@ -190,13 +190,13 @@ namespace BTCPayServer.Tests
{ {
CryptoCode = "BTC", CryptoCode = "BTC",
Rate = 1000, Rate = 1000,
NetworkFee = Money.Coins(0.1m) NextNetworkFee = Money.Coins(0.1m)
}); });
paymentMethods.Add(new PaymentMethod() paymentMethods.Add(new PaymentMethod()
{ {
CryptoCode = "LTC", CryptoCode = "LTC",
Rate = 500, Rate = 500,
NetworkFee = Money.Coins(0.01m) NextNetworkFee = Money.Coins(0.01m)
}); });
entity.SetPaymentMethods(paymentMethods); entity.SetPaymentMethods(paymentMethods);
entity.Payments = new List<PaymentEntity>(); entity.Payments = new List<PaymentEntity>();
@@ -275,7 +275,7 @@ namespace BTCPayServer.Tests
var entity = new InvoiceEntity(); var entity = new InvoiceEntity();
#pragma warning disable CS0618 #pragma warning disable CS0618
entity.Payments = new List<PaymentEntity>(); entity.Payments = new List<PaymentEntity>();
entity.SetPaymentMethod(new PaymentMethod() { CryptoCode = "BTC", Rate = 5000, NetworkFee = Money.Coins(0.1m) }); entity.SetPaymentMethod(new PaymentMethod() { CryptoCode = "BTC", Rate = 5000, NextNetworkFee = Money.Coins(0.1m) });
entity.ProductInformation = new ProductInformation() { Price = 5000 }; entity.ProductInformation = new ProductInformation() { Price = 5000 };
entity.PaymentTolerance = 0; entity.PaymentTolerance = 0;

View File

@@ -61,6 +61,12 @@ namespace BTCPayServer.Configuration
set; set;
} = new List<NBXplorerConnectionSetting>(); } = new List<NBXplorerConnectionSetting>();
public bool DisableRegistration
{
get;
private set;
}
public static string GetDebugLog(IConfiguration configuration) public static string GetDebugLog(IConfiguration configuration)
{ {
return configuration.GetValue<string>("debuglog", null); return configuration.GetValue<string>("debuglog", null);
@@ -237,6 +243,8 @@ namespace BTCPayServer.Configuration
Logs.Configuration.LogInformation("LogFile: " + LogFile); Logs.Configuration.LogInformation("LogFile: " + LogFile);
Logs.Configuration.LogInformation("Log Level: " + GetDebugLogLevel(conf)); Logs.Configuration.LogInformation("Log Level: " + GetDebugLogLevel(conf));
} }
DisableRegistration = conf.GetOrDefault<bool>("disable-registration", true);
} }
private SSHSettings ParseSSHConfiguration(IConfiguration conf) private SSHSettings ParseSSHConfiguration(IConfiguration conf)

View File

@@ -43,6 +43,7 @@ namespace BTCPayServer.Configuration
app.Option("--sshtrustedfingerprints", "SSH Host public key fingerprint or sha256 (default: empty, it will allow untrusted connections)", CommandOptionType.SingleValue); app.Option("--sshtrustedfingerprints", "SSH Host public key fingerprint or sha256 (default: empty, it will allow untrusted connections)", CommandOptionType.SingleValue);
app.Option("--debuglog", "A rolling log file for debug messages.", CommandOptionType.SingleValue); app.Option("--debuglog", "A rolling log file for debug messages.", CommandOptionType.SingleValue);
app.Option("--debugloglevel", "The severity you log (default:information)", CommandOptionType.SingleValue); app.Option("--debugloglevel", "The severity you log (default:information)", CommandOptionType.SingleValue);
app.Option("--disable-registration", "Disables new user registrations (default:true)", CommandOptionType.SingleValue);
foreach (var network in provider.GetAll()) foreach (var network in provider.GetAll())
{ {
var crypto = network.CryptoCode.ToLowerInvariant(); var crypto = network.CryptoCode.ToLowerInvariant();

View File

@@ -32,6 +32,7 @@ namespace BTCPayServer.Controllers
StoreRepository storeRepository; StoreRepository storeRepository;
RoleManager<IdentityRole> _RoleManager; RoleManager<IdentityRole> _RoleManager;
SettingsRepository _SettingsRepository; SettingsRepository _SettingsRepository;
Configuration.BTCPayServerOptions _Options;
ILogger _logger; ILogger _logger;
public AccountController( public AccountController(
@@ -40,7 +41,8 @@ namespace BTCPayServer.Controllers
StoreRepository storeRepository, StoreRepository storeRepository,
SignInManager<ApplicationUser> signInManager, SignInManager<ApplicationUser> signInManager,
IEmailSender emailSender, IEmailSender emailSender,
SettingsRepository settingsRepository) SettingsRepository settingsRepository,
Configuration.BTCPayServerOptions options)
{ {
this.storeRepository = storeRepository; this.storeRepository = storeRepository;
_userManager = userManager; _userManager = userManager;
@@ -48,6 +50,7 @@ namespace BTCPayServer.Controllers
_emailSender = emailSender; _emailSender = emailSender;
_RoleManager = roleManager; _RoleManager = roleManager;
_SettingsRepository = settingsRepository; _SettingsRepository = settingsRepository;
_Options = options;
_logger = Logs.PayServer; _logger = Logs.PayServer;
} }
@@ -271,6 +274,13 @@ namespace BTCPayServer.Controllers
{ {
await _RoleManager.CreateAsync(new IdentityRole(Roles.ServerAdmin)); await _RoleManager.CreateAsync(new IdentityRole(Roles.ServerAdmin));
await _userManager.AddToRoleAsync(user, Roles.ServerAdmin); await _userManager.AddToRoleAsync(user, Roles.ServerAdmin);
if(_Options.DisableRegistration)
{
// Once the admin user has been created lock subsequent user registrations (needs to be disabled for unit tests that require multiple users).
policies.LockSubscription = true;
await _SettingsRepository.UpdateSetting(policies);
}
} }
var code = await _userManager.GenerateEmailConfirmationTokenAsync(user); var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

View File

@@ -304,7 +304,7 @@ namespace BTCPayServer.Controllers
#pragma warning disable CS0618 // Type or member is obsolete #pragma warning disable CS0618 // Type or member is obsolete
Status = invoice.StatusString, Status = invoice.StatusString,
#pragma warning restore CS0618 // Type or member is obsolete #pragma warning restore CS0618 // Type or member is obsolete
NetworkFee = paymentMethodDetails.GetNetworkFee(), NetworkFee = paymentMethodDetails.GetNextNetworkFee(),
IsMultiCurrency = invoice.GetPayments().Select(p => p.GetPaymentMethodId()).Concat(new[] { paymentMethod.GetId() }).Distinct().Count() > 1, IsMultiCurrency = invoice.GetPayments().Select(p => p.GetPaymentMethodId()).Concat(new[] { paymentMethod.GetId() }).Distinct().Count() > 1,
ChangellyEnabled = changelly != null, ChangellyEnabled = changelly != null,
ChangellyMerchantId = changelly?.ChangellyMerchantId, ChangellyMerchantId = changelly?.ChangellyMerchantId,

View File

@@ -240,7 +240,7 @@ namespace BTCPayServer.Controllers
#pragma warning disable CS0618 #pragma warning disable CS0618
if (paymentMethod.GetId().IsBTCOnChain) if (paymentMethod.GetId().IsBTCOnChain)
{ {
entity.TxFee = paymentMethod.NetworkFee; entity.TxFee = paymentMethod.NextNetworkFee;
entity.Rate = paymentMethod.Rate; entity.Rate = paymentMethod.Rate;
entity.DepositAddress = paymentMethod.DepositAddress; entity.DepositAddress = paymentMethod.DepositAddress;
} }

View File

@@ -20,9 +20,9 @@ namespace BTCPayServer.Payments.Bitcoin
return DepositAddress; return DepositAddress;
} }
public decimal GetNetworkFee() public decimal GetNextNetworkFee()
{ {
return NetworkFee.ToDecimal(MoneyUnit.BTC); return NextNetworkFee.ToDecimal(MoneyUnit.BTC);
} }
public void SetPaymentDestination(string newPaymentDestination) public void SetPaymentDestination(string newPaymentDestination)
{ {
@@ -34,7 +34,7 @@ namespace BTCPayServer.Payments.Bitcoin
[JsonIgnore] [JsonIgnore]
public FeeRate FeeRate { get; set; } public FeeRate FeeRate { get; set; }
[JsonIgnore] [JsonIgnore]
public Money NetworkFee { get; set; } public Money NextNetworkFee { get; set; }
[JsonIgnore] [JsonIgnore]
public String DepositAddress { get; set; } public String DepositAddress { get; set; }
public BitcoinAddress GetDepositAddress(Network network) public BitcoinAddress GetDepositAddress(Network network)

View File

@@ -53,11 +53,11 @@ namespace BTCPayServer.Payments.Bitcoin
switch (onchainMethod.NetworkFeeMode) switch (onchainMethod.NetworkFeeMode)
{ {
case NetworkFeeMode.Always: case NetworkFeeMode.Always:
onchainMethod.NetworkFee = onchainMethod.FeeRate.GetFee(100); // assume price for 100 bytes onchainMethod.NextNetworkFee = onchainMethod.FeeRate.GetFee(100); // assume price for 100 bytes
break; break;
case NetworkFeeMode.Never: case NetworkFeeMode.Never:
case NetworkFeeMode.MultiplePaymentsOnly: case NetworkFeeMode.MultiplePaymentsOnly:
onchainMethod.NetworkFee = Money.Zero; onchainMethod.NextNetworkFee = Money.Zero;
break; break;
} }
onchainMethod.DepositAddress = (await prepare.ReserveAddress).ToString(); onchainMethod.DepositAddress = (await prepare.ReserveAddress).ToString();

View File

@@ -18,10 +18,10 @@ namespace BTCPayServer.Payments
string GetPaymentDestination(); string GetPaymentDestination();
PaymentTypes GetPaymentType(); PaymentTypes GetPaymentType();
/// <summary> /// <summary>
/// Returns what a merchant would need to pay to cashout this payment /// Returns fee that the merchant charge to the customer for the next payment
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
decimal GetNetworkFee(); decimal GetNextNetworkFee();
/// <summary> /// <summary>
/// Change the payment destination (internal plumbing) /// Change the payment destination (internal plumbing)
/// </summary> /// </summary>

View File

@@ -22,7 +22,7 @@ namespace BTCPayServer.Payments.Lightning
return PaymentTypes.LightningLike; return PaymentTypes.LightningLike;
} }
public decimal GetNetworkFee() public decimal GetNextNetworkFee()
{ {
return 0.0m; return 0.0m;
} }

View File

@@ -730,7 +730,7 @@ namespace BTCPayServer.Services.Invoices
{ {
FeeRate = FeeRate, FeeRate = FeeRate,
DepositAddress = string.IsNullOrEmpty(DepositAddress) ? null : DepositAddress, DepositAddress = string.IsNullOrEmpty(DepositAddress) ? null : DepositAddress,
NetworkFee = NetworkFee NextNetworkFee = NextNetworkFee
}; };
} }
else else
@@ -738,7 +738,7 @@ namespace BTCPayServer.Services.Invoices
var details = PaymentMethodExtensions.DeserializePaymentMethodDetails(GetId(), PaymentMethodDetails); var details = PaymentMethodExtensions.DeserializePaymentMethodDetails(GetId(), PaymentMethodDetails);
if (details is Payments.Bitcoin.BitcoinLikeOnChainPaymentMethod btcLike) if (details is Payments.Bitcoin.BitcoinLikeOnChainPaymentMethod btcLike)
{ {
btcLike.NetworkFee = NetworkFee; btcLike.NextNetworkFee = NextNetworkFee;
btcLike.DepositAddress = string.IsNullOrEmpty(DepositAddress) ? null : DepositAddress; btcLike.DepositAddress = string.IsNullOrEmpty(DepositAddress) ? null : DepositAddress;
btcLike.FeeRate = FeeRate; btcLike.FeeRate = FeeRate;
} }
@@ -760,7 +760,7 @@ namespace BTCPayServer.Services.Invoices
if (paymentMethod is Payments.Bitcoin.BitcoinLikeOnChainPaymentMethod bitcoinPaymentMethod) if (paymentMethod is Payments.Bitcoin.BitcoinLikeOnChainPaymentMethod bitcoinPaymentMethod)
{ {
NetworkFee = bitcoinPaymentMethod.NetworkFee; NextNetworkFee = bitcoinPaymentMethod.NextNetworkFee;
FeeRate = bitcoinPaymentMethod.FeeRate; FeeRate = bitcoinPaymentMethod.FeeRate;
DepositAddress = bitcoinPaymentMethod.DepositAddress; DepositAddress = bitcoinPaymentMethod.DepositAddress;
} }
@@ -775,8 +775,8 @@ namespace BTCPayServer.Services.Invoices
[Obsolete("Use ((BitcoinLikeOnChainPaymentMethod)GetPaymentMethod()).FeeRate")] [Obsolete("Use ((BitcoinLikeOnChainPaymentMethod)GetPaymentMethod()).FeeRate")]
public FeeRate FeeRate { get; set; } public FeeRate FeeRate { get; set; }
[JsonProperty(PropertyName = "txFee")] [JsonProperty(PropertyName = "txFee")]
[Obsolete("Use ((BitcoinLikeOnChainPaymentMethod)GetPaymentMethod()).TxFee")] [Obsolete("Use ((BitcoinLikeOnChainPaymentMethod)GetPaymentMethod()).NextNetworkFee")]
public Money NetworkFee { get; set; } public Money NextNetworkFee { get; set; }
[JsonProperty(PropertyName = "depositAddress")] [JsonProperty(PropertyName = "depositAddress")]
[Obsolete("Use ((BitcoinLikeOnChainPaymentMethod)GetPaymentMethod()).DepositAddress")] [Obsolete("Use ((BitcoinLikeOnChainPaymentMethod)GetPaymentMethod()).DepositAddress")]
public string DepositAddress { get; set; } public string DepositAddress { get; set; }
@@ -841,7 +841,7 @@ namespace BTCPayServer.Services.Invoices
var method = GetPaymentMethodDetails(); var method = GetPaymentMethodDetails();
if (method == null) if (method == null)
return 0.0m; return 0.0m;
return method.GetNetworkFee(); return method.GetNextNetworkFee();
} }
} }

View File

@@ -393,7 +393,7 @@ retry:
paymentMethods = entity.GetPaymentMethods(null); paymentMethods = entity.GetPaymentMethods(null);
var paymentMethodDetails = paymentMethods.TryGet(paymentEntity.GetPaymentMethodId())?.GetPaymentMethodDetails(); var paymentMethodDetails = paymentMethods.TryGet(paymentEntity.GetPaymentMethodId())?.GetPaymentMethodDetails();
if (paymentMethodDetails != null) // == null should never happen, but we never know. if (paymentMethodDetails != null) // == null should never happen, but we never know.
paymentEntity.NetworkFee = paymentMethodDetails.GetNetworkFee(); paymentEntity.NetworkFee = paymentMethodDetails.GetNextNetworkFee();
} }
return paymentEntity; return paymentEntity;
@@ -582,15 +582,15 @@ retry:
#pragma warning restore CS0618 #pragma warning restore CS0618
ReceivedTime = date.UtcDateTime, ReceivedTime = date.UtcDateTime,
Accounted = accounted, Accounted = accounted,
NetworkFee = paymentMethodDetails.GetNetworkFee() NetworkFee = paymentMethodDetails.GetNextNetworkFee()
}; };
entity.SetCryptoPaymentData(paymentData); entity.SetCryptoPaymentData(paymentData);
if (paymentMethodDetails is Payments.Bitcoin.BitcoinLikeOnChainPaymentMethod bitcoinPaymentMethod && if (paymentMethodDetails is Payments.Bitcoin.BitcoinLikeOnChainPaymentMethod bitcoinPaymentMethod &&
bitcoinPaymentMethod.NetworkFeeMode == NetworkFeeMode.MultiplePaymentsOnly && bitcoinPaymentMethod.NetworkFeeMode == NetworkFeeMode.MultiplePaymentsOnly &&
bitcoinPaymentMethod.NetworkFee == Money.Zero) bitcoinPaymentMethod.NextNetworkFee == Money.Zero)
{ {
bitcoinPaymentMethod.NetworkFee = bitcoinPaymentMethod.FeeRate.GetFee(100); // assume price for 100 bytes bitcoinPaymentMethod.NextNetworkFee = bitcoinPaymentMethod.FeeRate.GetFee(100); // assume price for 100 bytes
paymentMethod.SetPaymentMethodDetails(bitcoinPaymentMethod); paymentMethod.SetPaymentMethodDetails(bitcoinPaymentMethod);
invoiceEntity.SetPaymentMethod(paymentMethod); invoiceEntity.SetPaymentMethod(paymentMethod);
invoice.Blob = ToBytes(invoiceEntity, network.NBitcoinNetwork); invoice.Blob = ToBytes(invoiceEntity, network.NBitcoinNetwork);