Fix a bunch of minor bugs (#4983)

This commit is contained in:
Nicolas Dorier 2023-05-19 08:41:21 +09:00 committed by GitHub
parent acf003b1b4
commit 3d57b944ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 12 additions and 23 deletions

View File

@ -133,7 +133,7 @@ namespace BTCPayServer.Controllers.Greenfield
"A valid node info was not provided to open a channel with"); "A valid node info was not provided to open a channel with");
} }
if (request.ChannelAmount == null) if (request?.ChannelAmount is null)
{ {
ModelState.AddModelError(nameof(request.ChannelAmount), "ChannelAmount is missing"); ModelState.AddModelError(nameof(request.ChannelAmount), "ChannelAmount is missing");
} }
@ -142,7 +142,7 @@ namespace BTCPayServer.Controllers.Greenfield
ModelState.AddModelError(nameof(request.ChannelAmount), "ChannelAmount must be more than 0"); ModelState.AddModelError(nameof(request.ChannelAmount), "ChannelAmount must be more than 0");
} }
if (request.FeeRate == null) if (request?.FeeRate is null)
{ {
ModelState.AddModelError(nameof(request.FeeRate), "FeeRate is missing"); ModelState.AddModelError(nameof(request.FeeRate), "FeeRate is missing");
} }

View File

@ -352,7 +352,7 @@ namespace BTCPayServer.Controllers.Greenfield
[Authorize(Policy = Policies.CanCreateNonApprovedPullPayments, AuthenticationSchemes = AuthenticationSchemes.Greenfield)] [Authorize(Policy = Policies.CanCreateNonApprovedPullPayments, AuthenticationSchemes = AuthenticationSchemes.Greenfield)]
public async Task<IActionResult> CreatePayoutThroughStore(string storeId, CreatePayoutThroughStoreRequest request) public async Task<IActionResult> CreatePayoutThroughStore(string storeId, CreatePayoutThroughStoreRequest request)
{ {
if (request.Approved is true) if (request?.Approved is true)
{ {
if (!(await _authorizationService.AuthorizeAsync(User, null, if (!(await _authorizationService.AuthorizeAsync(User, null,
new PolicyRequirement(Policies.CanCreatePullPayments))).Succeeded) new PolicyRequirement(Policies.CanCreatePullPayments))).Succeeded)

View File

@ -164,7 +164,6 @@ namespace BTCPayServer.Controllers.Greenfield
{ {
var blob = model.GetStoreBlob(); var blob = model.GetStoreBlob();
model.StoreName = restModel.Name; model.StoreName = restModel.Name;
model.StoreName = restModel.Name;
model.StoreWebsite = restModel.Website; model.StoreWebsite = restModel.Website;
model.SpeedPolicy = restModel.SpeedPolicy; model.SpeedPolicy = restModel.SpeedPolicy;
model.SetDefaultPaymentId(defaultPaymentMethod); model.SetDefaultPaymentId(defaultPaymentMethod);
@ -240,7 +239,7 @@ namespace BTCPayServer.Controllers.Greenfield
ModelState.AddModelError(nameof(request.DisplayExpirationTimer), "DisplayExpirationTimer can only be between 1 and 34560 mins"); ModelState.AddModelError(nameof(request.DisplayExpirationTimer), "DisplayExpirationTimer can only be between 1 and 34560 mins");
if (request.MonitoringExpiration < TimeSpan.FromMinutes(10) && request.MonitoringExpiration > TimeSpan.FromMinutes(60 * 24 * 24)) if (request.MonitoringExpiration < TimeSpan.FromMinutes(10) && request.MonitoringExpiration > TimeSpan.FromMinutes(60 * 24 * 24))
ModelState.AddModelError(nameof(request.MonitoringExpiration), "MonitoringExpiration can only be between 10 and 34560 mins"); ModelState.AddModelError(nameof(request.MonitoringExpiration), "MonitoringExpiration can only be between 10 and 34560 mins");
if (request.PaymentTolerance < 0 && request.PaymentTolerance > 100) if (request.PaymentTolerance < 0 || request.PaymentTolerance > 100)
ModelState.AddModelError(nameof(request.PaymentTolerance), "PaymentTolerance can only be between 0 and 100 percent"); ModelState.AddModelError(nameof(request.PaymentTolerance), "PaymentTolerance can only be between 0 and 100 percent");
if (request.PaymentMethodCriteria?.Any() is true) if (request.PaymentMethodCriteria?.Any() is true)

View File

@ -361,11 +361,6 @@ namespace BTCPayServer
public ConcurrentDictionary<string, LightningAddressItem> Items { get; } = new(); public ConcurrentDictionary<string, LightningAddressItem> Items { get; } = new();
public ConcurrentDictionary<string, string[]> StoreToItemMap { get; } = new(); public ConcurrentDictionary<string, string[]> StoreToItemMap { get; } = new();
public override string ToString()
{
return null;
}
} }
[HttpGet("~/.well-known/lnurlp/{username}")] [HttpGet("~/.well-known/lnurlp/{username}")]

View File

@ -889,8 +889,11 @@ namespace BTCPayServer.Controllers
var userId = GetUserId(); var userId = GetUserId();
if (userId == null) if (userId == null)
return Challenge(AuthenticationSchemes.Cookie); return Challenge(AuthenticationSchemes.Cookie);
storeId = model.StoreId; var store = model.StoreId switch
var store = CurrentStore ?? await _Repo.FindStore(storeId, userId); {
null => CurrentStore,
string id => await _Repo.FindStore(storeId, userId)
};
if (store == null) if (store == null)
return Challenge(AuthenticationSchemes.Cookie); return Challenge(AuthenticationSchemes.Cookie);
var tokenRequest = new TokenRequest() var tokenRequest = new TokenRequest()
@ -908,7 +911,7 @@ namespace BTCPayServer.Controllers
Id = tokenRequest.PairingCode, Id = tokenRequest.PairingCode,
Label = model.Label, Label = model.Label,
}); });
await _TokenRepository.PairWithStoreAsync(tokenRequest.PairingCode, storeId); await _TokenRepository.PairWithStoreAsync(tokenRequest.PairingCode, store.Id);
pairingCode = tokenRequest.PairingCode; pairingCode = tokenRequest.PairingCode;
} }
else else

View File

@ -261,7 +261,6 @@ namespace BTCPayServer.HostedServices
{ {
if (e.Name == InvoiceEvent.Expired || if (e.Name == InvoiceEvent.Expired ||
e.Name == InvoiceEvent.PaidInFull || e.Name == InvoiceEvent.PaidInFull ||
e.Name == InvoiceEvent.FailedToConfirm ||
e.Name == InvoiceEvent.MarkedInvalid || e.Name == InvoiceEvent.MarkedInvalid ||
e.Name == InvoiceEvent.MarkedCompleted || e.Name == InvoiceEvent.MarkedCompleted ||
e.Name == InvoiceEvent.FailedToConfirm || e.Name == InvoiceEvent.FailedToConfirm ||

View File

@ -380,7 +380,8 @@ namespace BTCPayServer.HostedServices
if ((onChainPaymentData.ConfirmationCount < network.MaxTrackedConfirmation && payment.Accounted) if ((onChainPaymentData.ConfirmationCount < network.MaxTrackedConfirmation && payment.Accounted)
&& (onChainPaymentData.Legacy || invoice.MonitoringExpiration < DateTimeOffset.UtcNow)) && (onChainPaymentData.Legacy || invoice.MonitoringExpiration < DateTimeOffset.UtcNow))
{ {
var transactionResult = await _explorerClientProvider.GetExplorerClient(payment.GetCryptoCode())?.GetTransactionAsync(onChainPaymentData.Outpoint.Hash); var client = _explorerClientProvider.GetExplorerClient(payment.GetCryptoCode());
var transactionResult = client is null ? null : await client.GetTransactionAsync(onChainPaymentData.Outpoint.Hash);
var confirmationCount = transactionResult?.Confirmations ?? 0; var confirmationCount = transactionResult?.Confirmations ?? 0;
onChainPaymentData.ConfirmationCount = confirmationCount; onChainPaymentData.ConfirmationCount = confirmationCount;
payment.SetCryptoPaymentData(onChainPaymentData); payment.SetCryptoPaymentData(onChainPaymentData);

View File

@ -60,9 +60,6 @@ namespace BTCPayServer.Hosting
{ {
httpContext.Response.SetHeader("Access-Control-Allow-Origin", "*"); httpContext.Response.SetHeader("Access-Control-Allow-Origin", "*");
httpContext.SetBitpayAuth(bitpayAuth); httpContext.SetBitpayAuth(bitpayAuth);
}
if (isBitpayAPI)
{
await _Next(httpContext); await _Next(httpContext);
return; return;
} }

View File

@ -430,11 +430,6 @@ namespace BTCPayServer.Services.Invoices
{ {
using var context = _applicationDbContextFactory.CreateContext(); using var context = _applicationDbContextFactory.CreateContext();
var items = context.Invoices.Where(a => invoiceIds.Contains(a.Id)); var items = context.Invoices.Where(a => invoiceIds.Contains(a.Id));
if (items == null)
{
return;
}
foreach (InvoiceData invoice in items) foreach (InvoiceData invoice in items)
{ {
invoice.Archived = archive; invoice.Archived = archive;