2020-06-28 21:44:35 -05:00
|
|
|
using System;
|
2020-06-24 10:34:09 +09:00
|
|
|
using System.ComponentModel.DataAnnotations;
|
2021-10-21 17:43:02 +02:00
|
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
2021-04-13 10:36:49 +02:00
|
|
|
using BTCPayServer.Client.Models;
|
2020-06-24 10:34:09 +09:00
|
|
|
using Microsoft.EntityFrameworkCore;
|
2024-03-14 19:13:26 +09:00
|
|
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
2020-06-24 10:34:09 +09:00
|
|
|
using NBitcoin;
|
|
|
|
|
|
|
|
namespace BTCPayServer.Data
|
|
|
|
{
|
2024-06-28 20:07:53 +09:00
|
|
|
public partial class PayoutData
|
2020-06-24 10:34:09 +09:00
|
|
|
{
|
|
|
|
[Key]
|
|
|
|
[MaxLength(30)]
|
|
|
|
public string Id { get; set; }
|
|
|
|
public DateTimeOffset Date { get; set; }
|
|
|
|
public string PullPaymentDataId { get; set; }
|
2022-04-24 05:19:34 +02:00
|
|
|
public string StoreDataId { get; set; }
|
2024-08-28 18:52:08 +09:00
|
|
|
/// <summary>
|
|
|
|
/// The currency of the payout (eg. BTC)
|
|
|
|
/// </summary>
|
2024-06-28 20:07:53 +09:00
|
|
|
public string Currency { get; set; }
|
2024-08-28 18:52:08 +09:00
|
|
|
/// <summary>
|
|
|
|
/// The amount of the payout in Currency.
|
|
|
|
/// The Amount only get set when the payout is actually approved.
|
|
|
|
/// </summary>
|
|
|
|
public decimal? Amount { get; set; }
|
|
|
|
/// <summary>
|
|
|
|
/// The original currency of the payout (eg. USD)
|
|
|
|
/// </summary>
|
|
|
|
public string OriginalCurrency { get; set; }
|
|
|
|
/// <summary>
|
|
|
|
/// The amount of the payout in OriginalCurrency
|
|
|
|
/// </summary>
|
|
|
|
public decimal OriginalAmount { get; set; }
|
2020-06-24 10:34:09 +09:00
|
|
|
public PullPaymentData PullPaymentData { get; set; }
|
|
|
|
[MaxLength(20)]
|
|
|
|
public PayoutState State { get; set; }
|
|
|
|
[MaxLength(20)]
|
|
|
|
[Required]
|
2024-06-28 20:07:53 +09:00
|
|
|
public string PayoutMethodId { get; set; }
|
2024-03-14 19:13:26 +09:00
|
|
|
public string Blob { get; set; }
|
|
|
|
public string Proof { get; set; }
|
2021-10-23 22:10:54 +09:00
|
|
|
#nullable enable
|
2024-09-06 10:34:10 +09:00
|
|
|
/// <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; }
|
2021-10-23 22:10:54 +09:00
|
|
|
#nullable restore
|
2022-04-24 05:19:34 +02:00
|
|
|
public StoreData StoreData { get; set; }
|
2020-12-28 14:57:21 -06:00
|
|
|
|
2024-03-14 19:13:26 +09:00
|
|
|
internal static void OnModelCreating(ModelBuilder builder, DatabaseFacade databaseFacade)
|
2020-06-24 10:34:09 +09:00
|
|
|
{
|
|
|
|
builder.Entity<PayoutData>()
|
|
|
|
.HasOne(o => o.PullPaymentData)
|
|
|
|
.WithMany(o => o.Payouts).OnDelete(DeleteBehavior.Cascade);
|
2022-04-24 05:19:34 +02:00
|
|
|
builder.Entity<PayoutData>()
|
|
|
|
.HasOne(o => o.StoreData)
|
|
|
|
.WithMany(o => o.Payouts).OnDelete(DeleteBehavior.Cascade);
|
2020-06-24 10:34:09 +09:00
|
|
|
builder.Entity<PayoutData>()
|
|
|
|
.Property(o => o.State)
|
|
|
|
.HasConversion<string>();
|
|
|
|
builder.Entity<PayoutData>()
|
|
|
|
.HasIndex(o => o.State);
|
2021-10-21 17:43:02 +02:00
|
|
|
builder.Entity<PayoutData>()
|
2024-09-06 10:34:10 +09:00
|
|
|
.HasIndex(x => new { DestinationId = x.DedupId, x.State });
|
2024-03-14 19:13:26 +09:00
|
|
|
|
2024-04-15 19:08:25 +09:00
|
|
|
builder.Entity<PayoutData>()
|
|
|
|
.Property(o => o.Blob)
|
2024-10-20 00:08:28 +09:00
|
|
|
.HasColumnType("jsonb");
|
2024-04-15 19:08:25 +09:00
|
|
|
builder.Entity<PayoutData>()
|
|
|
|
.Property(o => o.Proof)
|
|
|
|
.HasColumnType("JSONB");
|
2020-06-24 10:34:09 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|