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 Sep 8, 2024
2 parents 8a7db56 + 73dcde7 commit 734b912
Show file tree
Hide file tree
Showing 45 changed files with 344 additions and 194 deletions.
2 changes: 1 addition & 1 deletion BTCPayServer.Client/Models/CreatePayoutRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ public class CreatePayoutRequest
public string Destination { get; set; }
[JsonConverter(typeof(NumericStringJsonConverter))]
public decimal? Amount { get; set; }
public string PaymentMethod { get; set; }
public string PayoutMethodId { get; set; }
}
}
2 changes: 2 additions & 0 deletions BTCPayServer.Client/Models/GenerateOnChainWalletRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace BTCPayServer.Client
{
public class GenerateOnChainWalletRequest
{
public string Label { get; set; }
public int AccountNumber { get; set; } = 0;
[JsonConverter(typeof(MnemonicJsonConverter))]
public Mnemonic ExistingMnemonic { get; set; }
Expand All @@ -29,6 +30,7 @@ public class GenerateOnChainWalletResponse : GenericPaymentMethodData
{
public class ConfigData
{
public string Label { get; set; }
public string AccountDerivation { get; set; }
[JsonExtensionData]
IDictionary<string, JToken> AdditionalData { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace BTCPayServer.Client.Models;

public class LightningAutomatedPayoutSettings
{
public string PaymentMethod { get; set; }
public string PayoutMethodId { get; set; }

[JsonConverter(typeof(TimeSpanJsonConverter.Seconds))]
public TimeSpan IntervalSeconds { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace BTCPayServer.Client.Models;

public class OnChainAutomatedPayoutSettings
{
public string PaymentMethod { get; set; }
public string PayoutMethodId { get; set; }

[JsonConverter(typeof(TimeSpanJsonConverter.Seconds))]
public TimeSpan IntervalSeconds { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion BTCPayServer.Client/Models/PaymentMethodCriteriaData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace BTCPayServer.Client.Models;

public class PaymentMethodCriteriaData
{
public string PaymentMethod { get; set; }
public string PaymentMethodId { get; set; }
public string CurrencyCode { get; set; }
[JsonConverter(typeof(NumericStringJsonConverter))]
public decimal Amount { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion BTCPayServer.Client/Models/PayoutData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class PayoutData
public string Id { get; set; }
public string PullPaymentId { get; set; }
public string Destination { get; set; }
public string PaymentMethod { get; set; }
public string PayoutMethodId { get; set; }
public string CryptoCode { get; set; }
[JsonConverter(typeof(NumericStringJsonConverter))]
public decimal Amount { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion BTCPayServer.Client/Models/RefundInvoiceRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public enum RefundVariant
public class RefundInvoiceRequest
{
public string? Name { get; set; } = null;
public string? PaymentMethod { get; set; }
public string? PayoutMethodId { get; set; }
public string? Description { get; set; } = null;

[JsonConverter(typeof(StringEnumConverter))]
Expand Down
1 change: 1 addition & 0 deletions BTCPayServer.Data/DBScripts/002.RefactorPayouts.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ UPDATE "Payouts" SET
"Currency" = split_part("PayoutMethodId", '_', 1),
"PayoutMethodId"=
CASE
WHEN ("Blob"->>'Amount')::NUMERIC < 0 THEN 'TOPUP'
WHEN split_part("PayoutMethodId", '_', 2) = 'LightningLike' THEN split_part("PayoutMethodId", '_', 1) || '-LN'
ELSE split_part("PayoutMethodId", '_', 1) || '-CHAIN'
END;
Expand Down
11 changes: 9 additions & 2 deletions BTCPayServer.Data/Data/PayoutData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,14 @@ public partial class PayoutData
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; }

Expand All @@ -62,7 +69,7 @@ internal static void OnModelCreating(ModelBuilder builder, DatabaseFacade databa
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)
Expand Down
4 changes: 2 additions & 2 deletions BTCPayServer.Data/Data/PayoutProcessorData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class PayoutProcessorData : IHasBlobUntyped
public string Id { get; set; }
public string StoreId { get; set; }
public StoreData Store { get; set; }
public string PaymentMethod { get; set; }
public string PayoutMethodId { get; set; }
public string Processor { get; set; }

[Obsolete("Use Blob2 instead")]
Expand All @@ -36,6 +36,6 @@ internal static void OnModelCreating(ModelBuilder builder, DatabaseFacade databa

public override string ToString()
{
return $"{Processor} {PaymentMethod} {StoreId}";
return $"{Processor} {PayoutMethodId} {StoreId}";
}
}
36 changes: 36 additions & 0 deletions BTCPayServer.Data/Migrations/20240906010127_renamecol.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
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");
migrationBuilder.RenameColumn(
name: "PaymentMethod",
table: "PayoutProcessors",
newName: "PayoutMethodId");
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.Property<DateTimeOffset>("Date")
.HasColumnType("timestamp with time zone");

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

b.Property<decimal>("OriginalAmount")
Expand Down Expand Up @@ -601,7 +601,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)

b.HasIndex("StoreDataId");

b.HasIndex("Destination", "State");
b.HasIndex("DedupId", "State");

b.ToTable("Payouts");
});
Expand All @@ -618,7 +618,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.Property<string>("Blob2")
.HasColumnType("JSONB");

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

b.Property<string>("Processor")
Expand Down
11 changes: 11 additions & 0 deletions BTCPayServer.Tests/DatabaseTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ public async Task CanMigratePayoutsAndPullPayments()
PullPaymentDataId = null as string,
PaymentMethodId = "BTC_LightningLike",
Blob = "{\"Amount\": \"10.0\", \"Revision\": 0, \"Destination\": \"address\", \"CryptoAmount\": null, \"MinimumConfirmation\": 1}"
},
new
{
Id = "p4",
StoreId = "store1",
PullPaymentDataId = null as string,
PaymentMethodId = "BTC_LightningLike",
Blob = "{\"Amount\": \"-10.0\", \"Revision\": 0, \"Destination\": \"address\", \"CryptoAmount\": null, \"MinimumConfirmation\": 1}"
}
};
await conn.ExecuteAsync("INSERT INTO \"Payouts\"(\"Id\", \"StoreDataId\", \"PullPaymentDataId\", \"PaymentMethodId\", \"Blob\", \"State\", \"Date\") VALUES (@Id, @StoreId, @PullPaymentDataId, @PaymentMethodId, @Blob::JSONB, 'state', NOW())", parameters);
Expand All @@ -75,6 +83,9 @@ public async Task CanMigratePayoutsAndPullPayments()

migrated = await conn.ExecuteScalarAsync<bool>("SELECT 't'::BOOLEAN FROM \"Payouts\" WHERE \"Id\"='p3' AND \"Amount\" IS NULL AND \"OriginalAmount\"=10.0 AND \"OriginalCurrency\"='BTC'");
Assert.True(migrated);

migrated = await conn.ExecuteScalarAsync<bool>("SELECT 't'::BOOLEAN FROM \"Payouts\" WHERE \"Id\"='p4' AND \"Amount\" IS NULL AND \"OriginalAmount\"=-10.0 AND \"OriginalCurrency\"='BTC' AND \"PayoutMethodId\"='TOPUP'");
Assert.True(migrated);
}
}
}
Loading

0 comments on commit 734b912

Please sign in to comment.