-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
224 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
using BTCPayApp.Core.JsonConverters; | ||
using BTCPayServer.Lightning; | ||
using NBitcoin; | ||
|
||
namespace BTCPayApp.Core.Data; | ||
|
||
public class AppLightningPayment : VersionedData | ||
{ | ||
[JsonConverter(typeof(UInt256JsonConverter))] | ||
public uint256 PaymentHash { get; set; } | ||
|
||
public string PaymentId { get; set; } | ||
public string? Preimage { get; set; } | ||
|
||
[JsonConverter(typeof(UInt256JsonConverter))] | ||
public uint256 Secret { get; set; } | ||
|
||
public bool Inbound { get; set; } | ||
|
||
[JsonConverter(typeof(DateTimeToUnixTimeConverter))] | ||
public DateTimeOffset Timestamp { get; set; } | ||
|
||
[JsonConverter(typeof(LightMoneyJsonConverter))] | ||
public LightMoney Value { get; set; } | ||
|
||
[JsonConverter(typeof(JsonStringEnumConverter))] | ||
public LightningPaymentStatus Status { get; set; } | ||
|
||
[JsonConverter(typeof(BOLT11PaymentRequestJsonConverter))] | ||
public BOLT11PaymentRequest PaymentRequest { get; set; } | ||
|
||
[JsonExtensionData] public Dictionary<string, JsonElement> AdditionalData { get; set; } = new(); | ||
|
||
public override string Entity => "LightningPayment"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
namespace BTCPayApp.Core.Data; | ||
|
||
public class Channel | ||
public class Channel:VersionedData | ||
{ | ||
public string Id { get; set; } | ||
public List<string> Aliases { get; set; } | ||
public byte[] Data { get; set; } | ||
|
||
|
||
|
||
|
||
public override string Entity => "Channel"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace BTCPayApp.Core.Data; | ||
|
||
public record PeerInfo | ||
{ | ||
public string Endpoint { get; set; } | ||
public bool Persistent { get; set; } | ||
public bool Trusted { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System.Text.Json; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.ChangeTracking; | ||
using Microsoft.EntityFrameworkCore.Metadata.Builders; | ||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion; | ||
|
||
namespace BTCPayApp.Core.Data; | ||
|
||
public static class ValueConversionExtensions | ||
{ | ||
public static PropertyBuilder<T> HasJsonConversion<T>(this PropertyBuilder<T> propertyBuilder) | ||
where T : class, new() | ||
{ | ||
var converter = new ValueConverter<T, string> | ||
( | ||
v => JsonSerializer.Serialize(v, JsonSerializerOptions.Default), | ||
v => JsonSerializer.Deserialize<T>(v, JsonSerializerOptions.Default) ?? new T() | ||
); | ||
|
||
var comparer = new ValueComparer<T> | ||
( | ||
(l, r) => JsonSerializer.Serialize(l, JsonSerializerOptions.Default) == | ||
JsonSerializer.Serialize(r, JsonSerializerOptions.Default), | ||
v => v == null ? 0 : JsonSerializer.Serialize(v, JsonSerializerOptions.Default).GetHashCode(), | ||
v => JsonSerializer.Deserialize<T>(JsonSerializer.Serialize(v, JsonSerializerOptions.Default), | ||
JsonSerializerOptions.Default)! | ||
); | ||
|
||
propertyBuilder.HasConversion(converter); | ||
propertyBuilder.Metadata.SetValueConverter(converter); | ||
propertyBuilder.Metadata.SetValueComparer(comparer); | ||
propertyBuilder.HasColumnType("jsonb"); | ||
|
||
return propertyBuilder; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using System.ComponentModel.DataAnnotations.Schema; | ||
|
||
namespace BTCPayApp.Core.Data; | ||
|
||
public abstract class VersionedData | ||
{ | ||
public ulong Version { get; set; } = 0; | ||
[NotMapped] | ||
public abstract string Entity { get; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.