Rename PayoutData.Destination (#6197)

This commit is contained in:
Nicolas Dorier 2024-09-06 10:34:10 +09:00 committed by GitHub
parent 4ce68f817d
commit 99dda66bbc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 50 additions and 13 deletions

View File

@ -44,7 +44,14 @@ namespace BTCPayServer.Data
public string Blob { get; set; }
public string Proof { get; set; }
#nullable enable
public string? Destination { get; set; }
/// <summary>
/// For example, BTC-CHAIN needs to ensure that only a single address is tied to an active payout.
/// If `PayoutBlob.Destination` is `bitcoin://1BvBMSeYstWetqTFn5Au4m4GFg7xJaNVN2?amount=0.1`
/// Then `DedupId` is `1BvBMSeYstWetqTFn5Au4m4GFg7xJaNVN2`
/// For Lightning, Destination could be the lightning address, BOLT11 or LNURL
/// But the `DedupId` would be the `PaymentHash`.
/// </summary>
public string? DedupId { get; set; }
#nullable restore
public StoreData StoreData { get; set; }
@ -62,7 +69,7 @@ namespace BTCPayServer.Data
builder.Entity<PayoutData>()
.HasIndex(o => o.State);
builder.Entity<PayoutData>()
.HasIndex(x => new { DestinationId = x.Destination, x.State });
.HasIndex(x => new { DestinationId = x.DedupId, x.State });
builder.Entity<PayoutData>()
.Property(o => o.Blob)

View File

@ -0,0 +1,32 @@
using BTCPayServer.Data;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace BTCPayServer.Migrations
{
[DbContext(typeof(ApplicationDbContext))]
[Migration("20240906010127_renamecol")]
public partial class renamecol : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.RenameColumn(
name: "Destination",
table: "Payouts",
newName: "DedupId");
migrationBuilder.RenameIndex(
name: "IX_Payouts_Destination_State",
table: "Payouts",
newName: "IX_Payouts_DedupId_State");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
}
}
}

View File

@ -565,7 +565,7 @@ namespace BTCPayServer.Migrations
b.Property<DateTimeOffset>("Date")
.HasColumnType("timestamp with time zone");
b.Property<string>("Destination")
b.Property<string>("DedupId")
.HasColumnType("text");
b.Property<decimal>("OriginalAmount")
@ -601,7 +601,7 @@ namespace BTCPayServer.Migrations
b.HasIndex("StoreDataId");
b.HasIndex("Destination", "State");
b.HasIndex("DedupId", "State");
b.ToTable("Payouts");
});

View File

@ -430,7 +430,7 @@ public class BitcoinLikePayoutHandler : IPayoutHandler, IHasNetwork
.Where(p => p.State == PayoutState.AwaitingPayment)
.Where(p => p.PayoutMethodId == paymentMethodId.ToString())
#pragma warning disable CA1307 // Specify StringComparison
.Where(p => destination.Equals(p.Destination))
.Where(p => destination.Equals(p.DedupId))
#pragma warning restore CA1307 // Specify StringComparison
.FirstOrDefaultAsync();

View File

@ -415,7 +415,6 @@ namespace BTCPayServer.HostedServices
Date = DateTimeOffset.UtcNow,
State = PayoutState.Completed,
PullPaymentDataId = pp.Id,
Destination = topUp.InvoiceEntity.Id,
StoreDataId = pp.StoreId
};
if (topUp.InvoiceEntity.Currency != pp.Currency ||
@ -649,7 +648,7 @@ namespace BTCPayServer.HostedServices
if (req.ClaimRequest.Destination.Id != null)
{
if (await ctx.Payouts.AnyAsync(data =>
data.Destination.Equals(req.ClaimRequest.Destination.Id) &&
data.DedupId.Equals(req.ClaimRequest.Destination.Id) &&
data.State != PayoutState.Completed && data.State != PayoutState.Cancelled
))
{
@ -693,7 +692,7 @@ namespace BTCPayServer.HostedServices
State = PayoutState.AwaitingApproval,
PullPaymentDataId = req.ClaimRequest.PullPaymentId,
PayoutMethodId = req.ClaimRequest.PayoutMethodId.ToString(),
Destination = req.ClaimRequest.Destination.Id,
DedupId = req.ClaimRequest.Destination.Id,
StoreDataId = req.ClaimRequest.StoreId ?? pp?.StoreId,
Currency = payoutHandler.Currency,
OriginalCurrency = pp?.Currency ?? payoutHandler.Currency

View File

@ -1,4 +1,4 @@
#nullable enable
#nullable enable
using System.Threading.Tasks;
using BTCPayServer.Client.Models;
using BTCPayServer.Controllers;
@ -23,13 +23,12 @@ public class PayoutWebhookDeliveryRequest(PayoutEvent evt, string? webhookId, We
private string Interpolate(string str)
{
var blob = evt.Payout.GetBlob(btcPayNetworkJsonSerializerSettings);
var res = str.Replace("{Payout.Id}", evt.Payout.Id)
.Replace("{Payout.PullPaymentId}", evt.Payout.PullPaymentDataId)
.Replace("{Payout.Destination}", evt.Payout.Destination)
.Replace("{Payout.Destination}", evt.Payout.DedupId ?? blob.Destination)
.Replace("{Payout.State}", evt.Payout.State.ToString());
var blob = evt.Payout.GetBlob(btcPayNetworkJsonSerializerSettings);
res = InterpolateJsonField(res, "Payout.Metadata", blob.Metadata);
return res;
}

View File

@ -636,7 +636,7 @@ WHERE cte.""Id""=p.""Id""
continue;
}
var claim = await handler?.ParseClaimDestination(payoutData.GetBlob(_btcPayNetworkJsonSerializerSettings).Destination, default);
payoutData.Destination = claim.destination?.Id;
payoutData.DedupId = claim.destination?.Id;
}
await ctx.SaveChangesAsync();
}