Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
gruve-p committed Apr 22, 2024
2 parents 5418b4b + c8f0039 commit 761c6e7
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 39 deletions.
1 change: 0 additions & 1 deletion BTCPayServer.Data/Data/AddressInvoiceData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ public class AddressInvoiceData
public string Address { get; set; }
public InvoiceData InvoiceData { get; set; }
public string InvoiceDataId { get; set; }
public DateTimeOffset? CreatedTime { get; set; }


internal static void OnModelCreating(ModelBuilder builder)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using BTCPayServer.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace BTCPayServer.Migrations
{
[DbContext(typeof(ApplicationDbContext))]
[Migration("20240405052858_cleanup_address_invoices")]
public partial class cleanup_address_invoices : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
if (migrationBuilder.IsNpgsql())
{
migrationBuilder.Sql(@"
DELETE FROM ""AddressInvoices"" WHERE ""Address"" LIKE '%_LightningLike';
ALTER TABLE ""AddressInvoices"" DROP COLUMN IF EXISTS ""CreatedTime"";
VACUUM (FULL, ANALYZE) ""AddressInvoices"";", true);
}
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,6 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.Property<string>("Address")
.HasColumnType("text");

b.Property<DateTimeOffset?>("CreatedTime")
.HasColumnType("timestamp with time zone");

b.Property<string>("InvoiceDataId")
.HasColumnType("text");

Expand Down
1 change: 1 addition & 0 deletions BTCPayServer.Tests/AltcoinTests/AltcoinTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ public async Task CanHaveLTCOnlyStore()
{
invoice = user.BitPay.GetInvoice(invoice.Id);
Assert.Equal(firstPayment, invoice.CryptoInfo[0].Paid);
Assert.Equal("paidPartial", invoice.ExceptionStatus?.ToString());
});

Assert.Single(invoice.CryptoInfo); // Only BTC should be presented
Expand Down
18 changes: 8 additions & 10 deletions BTCPayServer.Tests/UnitTest1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1982,29 +1982,27 @@ public async Task EnsureWebhooksTrigger()
.PaymentLink, tester.ExplorerNode.Network);
var halfPaymentTx = await tester.ExplorerNode.SendToAddressAsync(invoicePaymentRequest.Address, Money.Coins(invoicePaymentRequest.Amount.ToDecimal(MoneyUnit.BTC)/2m));

invoicePaymentRequest = new BitcoinUrlBuilder((await client.GetInvoicePaymentMethods(user.StoreId, invoice.Id)).Single(model =>
PaymentMethodId.Parse(model.PaymentMethodId) ==
PaymentTypes.CHAIN.GetPaymentMethodId("BTC"))
.PaymentLink, tester.ExplorerNode.Network);
var remainingPaymentTx = await tester.ExplorerNode.SendToAddressAsync(invoicePaymentRequest.Address, Money.Coins(invoicePaymentRequest.Amount.ToDecimal(MoneyUnit.BTC)));

await user.AssertHasWebhookEvent(WebhookEventType.InvoiceCreated, (WebhookInvoiceEvent x)=> Assert.Equal(invoice.Id, x.InvoiceId));
await user.AssertHasWebhookEvent(WebhookEventType.InvoiceProcessing, (WebhookInvoiceEvent x)=> Assert.Equal(invoice.Id, x.InvoiceId));
await user.AssertHasWebhookEvent(WebhookEventType.InvoiceReceivedPayment,
(WebhookInvoiceReceivedPaymentEvent x) =>
{
Assert.Equal(invoice.Id, x.InvoiceId);
Assert.Contains(halfPaymentTx.ToString(), x.Payment.Id);
});
await user.AssertHasWebhookEvent(WebhookEventType.InvoiceReceivedPayment,
invoicePaymentRequest = new BitcoinUrlBuilder((await client.GetInvoicePaymentMethods(user.StoreId, invoice.Id)).Single(model =>
PaymentMethodId.Parse(model.PaymentMethodId) ==
PaymentTypes.CHAIN.GetPaymentMethodId("BTC"))
.PaymentLink, tester.ExplorerNode.Network);
var remainingPaymentTx = await tester.ExplorerNode.SendToAddressAsync(invoicePaymentRequest.Address, Money.Coins(invoicePaymentRequest.Amount.ToDecimal(MoneyUnit.BTC)));
await user.AssertHasWebhookEvent(WebhookEventType.InvoiceReceivedPayment,
(WebhookInvoiceReceivedPaymentEvent x) =>
{
Assert.Equal(invoice.Id, x.InvoiceId);
Assert.Contains(remainingPaymentTx.ToString(), x.Payment.Id);
});

await user.AssertHasWebhookEvent(WebhookEventType.InvoiceProcessing, (WebhookInvoiceEvent x) => Assert.Equal(invoice.Id, x.InvoiceId));
await tester.ExplorerNode.GenerateAsync(1);

await user.AssertHasWebhookEvent(WebhookEventType.InvoicePaymentSettled,
(WebhookInvoiceReceivedPaymentEvent x) =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
using BTCPayServer.Client.Models;
using BTCPayServer.Data;
using BTCPayServer.HostedServices;
using BTCPayServer.Logging;
using BTCPayServer.NTag424;
using BTCPayServer.Payments;
using BTCPayServer.Security;
Expand All @@ -29,7 +28,6 @@
using NBitcoin.DataEncoders;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Org.BouncyCastle.Bcpg.OpenPgp;
using MarkPayoutRequest = BTCPayServer.HostedServices.MarkPayoutRequest;

namespace BTCPayServer.Controllers.Greenfield
Expand All @@ -49,7 +47,6 @@ public class GreenfieldPullPaymentController : ControllerBase
private readonly IAuthorizationService _authorizationService;
private readonly SettingsRepository _settingsRepository;
private readonly BTCPayServerEnvironment _env;
private readonly Logs _logs;

public GreenfieldPullPaymentController(PullPaymentHostedService pullPaymentService,
LinkGenerator linkGenerator,
Expand All @@ -60,7 +57,7 @@ public GreenfieldPullPaymentController(PullPaymentHostedService pullPaymentServi
BTCPayNetworkProvider btcPayNetworkProvider,
IAuthorizationService authorizationService,
SettingsRepository settingsRepository,
BTCPayServerEnvironment env, Logs logs)
BTCPayServerEnvironment env)
{
_pullPaymentService = pullPaymentService;
_linkGenerator = linkGenerator;
Expand All @@ -72,7 +69,6 @@ public GreenfieldPullPaymentController(PullPaymentHostedService pullPaymentServi
_authorizationService = authorizationService;
_settingsRepository = settingsRepository;
_env = env;
_logs = logs;
}

[HttpGet("~/api/v1/stores/{storeId}/pull-payments")]
Expand Down Expand Up @@ -212,8 +208,6 @@ public async Task<IActionResult> RegisterBoltcard(string pullPaymentId, Register
{
if (pullPaymentId is null)
return PullPaymentNotFound();
this._logs.PayServer.LogInformation($"RegisterBoltcard: onExisting queryParam: {onExisting}");
this._logs.PayServer.LogInformation($"{JsonConvert.SerializeObject(request)}");
var pp = await _pullPaymentService.GetPullPayment(pullPaymentId, false);
if (pp is null)
return PullPaymentNotFound();
Expand Down Expand Up @@ -259,13 +253,7 @@ public async Task<IActionResult> RegisterBoltcard(string pullPaymentId, Register
_ => request.OnExisting
};

this._logs.PayServer.LogInformation($"After");
this._logs.PayServer.LogInformation($"{JsonConvert.SerializeObject(request)}");

var version = await _dbContextFactory.LinkBoltcardToPullPayment(pullPaymentId, issuerKey, request.UID, request.OnExisting);
this._logs.PayServer.LogInformation($"Version: " + version);
this._logs.PayServer.LogInformation($"ID: " + Encoders.Hex.EncodeData(issuerKey.GetId(request.UID)));

var keys = issuerKey.CreatePullPaymentCardKey(request.UID, version, pullPaymentId).DeriveBoltcardKeys(issuerKey);

var boltcardUrl = Url.Action(nameof(UIBoltcardController.GetWithdrawRequest), "UIBoltcard");
Expand All @@ -282,9 +270,6 @@ public async Task<IActionResult> RegisterBoltcard(string pullPaymentId, Register
K3 = Encoders.Hex.EncodeData(keys.K3.ToBytes()).ToUpperInvariant(),
K4 = Encoders.Hex.EncodeData(keys.K4.ToBytes()).ToUpperInvariant(),
};
this._logs.PayServer.LogInformation($"Response");
this._logs.PayServer.LogInformation($"{JsonConvert.SerializeObject(resp)}");

return Ok(resp);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public async Task<IActionResult> UpdateStorePaymentMethod(
if (request?.Enabled is { } enabled)
{
var storeBlob = Store.GetStoreBlob();
storeBlob.SetExcluded(paymentMethodId, enabled);
storeBlob.SetExcluded(paymentMethodId, !enabled);
Store.SetStoreBlob(storeBlob);
}
await _storeRepository.UpdateStore(Store);
Expand Down
2 changes: 0 additions & 2 deletions BTCPayServer/Services/Invoices/InvoiceRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,6 @@ public async Task CreateInvoiceAsync(InvoiceCreationContext creationContext)
await context.AddressInvoices.AddAsync(new AddressInvoiceData()
{
InvoiceDataId = invoice.Id,
CreatedTime = DateTimeOffset.UtcNow,
Address = trackedDestination
});
}
Expand Down Expand Up @@ -363,7 +362,6 @@ public async Task NewPaymentPrompt(string invoiceId, PaymentMethodContext paymen
await context.AddressInvoices.AddAsync(new AddressInvoiceData()
{
InvoiceDataId = invoiceId,
CreatedTime = DateTimeOffset.UtcNow,
Address = tracked
});
}
Expand Down
3 changes: 2 additions & 1 deletion BTCPayServer/wwwroot/swagger/v1/swagger.template.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@
},
"PaymentMethodId": {
"type": "string",
"description": "Payment method IDs are a combination of crypto code and payment type. Available payment method IDs for Bitcoin are: \n- `\"BTC-OnChain\"` (with the equivalent of `\"BTC\"`) \n-`\"BTC-LightningLike\"`: Any supported LN-based payment method (Lightning or LNURL) \n- `\"BTC-LightningNetwork\"`: Lightning \n- `\"BTC-LNURLPAY\"`: LNURL \n \nNote: Separator can be either `-` or `_`."
"description": "Payment method IDs are a combination of crypto code and payment type. Available payment method IDs for Bitcoin are: \n- `\"BTC-CHAIN\"`: Onchain \n-`\"BTC-LN\"`: Lightning \n- `\"BTC-LNURL\"`: LNURL",
"example": "BTC-CHAIN"
}
},
"securitySchemes": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,11 +345,6 @@
}
}
},
"PaymentMethodId": {
"type": "string",
"description": "The payment method id (`BTC-CHAIN`, `BTC-LN`, `BTC-LNURL`)",
"example": "BTC-CHAIN"
},
"GenericPaymentMethodData": {
"type": "object",
"additionalProperties": false,
Expand Down

0 comments on commit 761c6e7

Please sign in to comment.