mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2024-11-20 10:40:29 +01:00
27 lines
995 B
C#
27 lines
995 B
C#
using System;
|
|
using System.Diagnostics.CodeAnalysis;
|
|
using BTCPayServer.Lightning;
|
|
using NBitcoin.JsonConverters;
|
|
using Newtonsoft.Json;
|
|
|
|
namespace BTCPayServer.Client.JsonConverters
|
|
{
|
|
public class NodeUriJsonConverter : JsonConverter<NodeInfo>
|
|
{
|
|
public override NodeInfo ReadJson(JsonReader reader, Type objectType, [AllowNull] NodeInfo existingValue, bool hasExistingValue, JsonSerializer serializer)
|
|
{
|
|
if (reader.TokenType != JsonToken.String)
|
|
throw new JsonObjectException(reader.Path, "Unexpected token type for NodeUri");
|
|
if (NodeInfo.TryParse((string)reader.Value, out var info))
|
|
return info;
|
|
throw new JsonObjectException(reader.Path, "Invalid NodeUri");
|
|
}
|
|
|
|
public override void WriteJson(JsonWriter writer, [AllowNull] NodeInfo value, JsonSerializer serializer)
|
|
{
|
|
if (value is NodeInfo)
|
|
writer.WriteValue(value.ToString());
|
|
}
|
|
}
|
|
}
|