Update services client
This commit is contained in:
@ -6,7 +6,7 @@
|
|||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||||
<RepositoryUrl>https://git.v0l.io/Kieran/NostrServices</RepositoryUrl>
|
<RepositoryUrl>https://git.v0l.io/Kieran/NostrServices</RepositoryUrl>
|
||||||
<Version>1.0.1</Version>
|
<Version>1.0.2</Version>
|
||||||
<Authors>Kieran</Authors>
|
<Authors>Kieran</Authors>
|
||||||
<Description>Client wrapper for https://nostr.api.v0l.io</Description>
|
<Description>Client wrapper for https://nostr.api.v0l.io</Description>
|
||||||
<PackageProjectUrl>https://git.v0l.io/Kieran/NostrServices</PackageProjectUrl>
|
<PackageProjectUrl>https://git.v0l.io/Kieran/NostrServices</PackageProjectUrl>
|
||||||
@ -19,4 +19,8 @@
|
|||||||
<PackageReference Include="Nostr.Client" Version="2.0.0" />
|
<PackageReference Include="Nostr.Client" Version="2.0.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\NostrServices.Model\NostrServices.Model.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
|
using System.Net.Http.Headers;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Nostr.Client.Json;
|
using Nostr.Client.Json;
|
||||||
using Nostr.Client.Messages;
|
using Nostr.Client.Messages;
|
||||||
|
using NostrServices.Model;
|
||||||
|
|
||||||
namespace NostrServices.Client;
|
namespace NostrServices.Client;
|
||||||
|
|
||||||
@ -15,54 +17,47 @@ public class NostrServicesClient
|
|||||||
_client.Timeout = TimeSpan.FromSeconds(60);
|
_client.Timeout = TimeSpan.FromSeconds(60);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<NostrProfile?> Profile(string id)
|
public async Task<CompactProfile?> Profile(string id)
|
||||||
{
|
{
|
||||||
var rsp = await _client.GetAsync($"/api/v1/export/profile/{id}");
|
return await Get<CompactProfile>(HttpMethod.Get, $"/api/v1/export/profile/{id}");
|
||||||
if (rsp.IsSuccessStatusCode)
|
|
||||||
{
|
|
||||||
var json = await rsp.Content.ReadAsStringAsync();
|
|
||||||
return JsonConvert.DeserializeObject<NostrProfile>(json);
|
|
||||||
}
|
|
||||||
|
|
||||||
return default;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<NostrEvent?> Event(string id)
|
public async Task<NostrEvent?> Event(string id)
|
||||||
{
|
{
|
||||||
var rsp = await _client.GetAsync($"/api/v1/export/{id}");
|
return await Get<NostrEvent>(HttpMethod.Get, $"/api/v1/export/{id}");
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<LinkPreviewData?> LinkPreview(string url)
|
||||||
|
{
|
||||||
|
return await Get<LinkPreviewData>(HttpMethod.Get, $"/api/v1/preview?url={Uri.EscapeDataString(url)}");
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<List<RelayDistance>?> CloseRelays(double lat, double lon, int count = 5)
|
||||||
|
{
|
||||||
|
return await Get<List<RelayDistance>>(HttpMethod.Post, $"/api/v1/relays?count={count}", new {lat, lon});
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<List<RelayDistance>?> TopRelays(int count = 5)
|
||||||
|
{
|
||||||
|
return await Get<List<RelayDistance>>(HttpMethod.Get, $"/api/v1/relays/top?count={count}");
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task<T?> Get<T>(HttpMethod method, string path, object? body = null)
|
||||||
|
{
|
||||||
|
var req = new HttpRequestMessage(method, path);
|
||||||
|
if (body != null)
|
||||||
|
{
|
||||||
|
req.Content = new StringContent(JsonConvert.SerializeObject(body, NostrSerializer.Settings),
|
||||||
|
new MediaTypeHeaderValue("application/json"));
|
||||||
|
}
|
||||||
|
|
||||||
|
var rsp = await _client.SendAsync(req);
|
||||||
if (rsp.IsSuccessStatusCode)
|
if (rsp.IsSuccessStatusCode)
|
||||||
{
|
{
|
||||||
var json = await rsp.Content.ReadAsStringAsync();
|
var json = await rsp.Content.ReadAsStringAsync();
|
||||||
return NostrJson.Deserialize<NostrEvent>(json);
|
return JsonConvert.DeserializeObject<T>(json, NostrSerializer.Settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
return default;
|
return default;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class NostrProfile
|
|
||||||
{
|
|
||||||
[JsonProperty("pubkey")]
|
|
||||||
public byte[] PubKey { get; init; } = null!;
|
|
||||||
|
|
||||||
[JsonProperty("name")]
|
|
||||||
public string? Name { get; init; }
|
|
||||||
|
|
||||||
[JsonProperty("about")]
|
|
||||||
public string? About { get; init; }
|
|
||||||
|
|
||||||
[JsonProperty("picture")]
|
|
||||||
public string? Picture { get; init; }
|
|
||||||
|
|
||||||
[JsonProperty("nip05")]
|
|
||||||
public string? Nip05 { get; init; }
|
|
||||||
|
|
||||||
[JsonProperty("lud16")]
|
|
||||||
public string? LightningAddress { get; init; }
|
|
||||||
|
|
||||||
[JsonProperty("banner")]
|
|
||||||
public string? Banner { get; init; }
|
|
||||||
|
|
||||||
[JsonProperty("created")]
|
|
||||||
public DateTime Created { get; init; }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
29
NostrServices.Model/LinkPreviewData.cs
Normal file
29
NostrServices.Model/LinkPreviewData.cs
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
using Newtonsoft.Json;
|
||||||
|
using ProtoBuf;
|
||||||
|
|
||||||
|
namespace NostrServices.Model;
|
||||||
|
|
||||||
|
[ProtoContract]
|
||||||
|
public class LinkPreviewData
|
||||||
|
{
|
||||||
|
[ProtoMember(1)]
|
||||||
|
[JsonIgnore]
|
||||||
|
[System.Text.Json.Serialization.JsonIgnore]
|
||||||
|
public List<KeyValuePair<string, string>> OgTags { get; init; } = new();
|
||||||
|
|
||||||
|
[ProtoIgnore]
|
||||||
|
[JsonProperty("og_tags")]
|
||||||
|
public List<string[]> OgTagsJson => OgTags.Select(a => new[] {a.Key, a.Value}).ToList();
|
||||||
|
|
||||||
|
[ProtoMember(2)]
|
||||||
|
[JsonProperty("title")]
|
||||||
|
public string? Title { get; init; }
|
||||||
|
|
||||||
|
[ProtoMember(3)]
|
||||||
|
[JsonProperty("description")]
|
||||||
|
public string? Description { get; init; }
|
||||||
|
|
||||||
|
[ProtoMember(4)]
|
||||||
|
[JsonProperty("image")]
|
||||||
|
public string? Image { get; init; }
|
||||||
|
}
|
15
NostrServices.Model/NostrServices.Model.csproj
Normal file
15
NostrServices.Model/NostrServices.Model.csproj
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||||
|
<PackageReference Include="Nostr.Client" Version="2.0.0" />
|
||||||
|
<PackageReference Include="protobuf-net.Core" Version="3.2.30" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
66
NostrServices.Model/Profile.cs
Normal file
66
NostrServices.Model/Profile.cs
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
using NBitcoin.JsonConverters;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Nostr.Client.Json;
|
||||||
|
using Nostr.Client.Messages;
|
||||||
|
using Nostr.Client.Messages.Metadata;
|
||||||
|
using ProtoBuf;
|
||||||
|
|
||||||
|
namespace NostrServices.Model;
|
||||||
|
|
||||||
|
[ProtoContract]
|
||||||
|
public class CompactProfile
|
||||||
|
{
|
||||||
|
[ProtoMember(1)]
|
||||||
|
[JsonProperty("pubkey")]
|
||||||
|
[JsonConverter(typeof(HexJsonConverter))]
|
||||||
|
public byte[] PubKey { get; init; } = null!;
|
||||||
|
|
||||||
|
[ProtoMember(2)]
|
||||||
|
[JsonProperty("name")]
|
||||||
|
public string? Name { get; init; }
|
||||||
|
|
||||||
|
[ProtoMember(3)]
|
||||||
|
[JsonProperty("about")]
|
||||||
|
public string? About { get; init; }
|
||||||
|
|
||||||
|
[ProtoMember(4)]
|
||||||
|
[JsonProperty("picture")]
|
||||||
|
public string? Picture { get; init; }
|
||||||
|
|
||||||
|
[ProtoMember(5)]
|
||||||
|
[JsonProperty("nip05")]
|
||||||
|
public string? Nip05 { get; init; }
|
||||||
|
|
||||||
|
[ProtoMember(6)]
|
||||||
|
[JsonProperty("lud16")]
|
||||||
|
public string? Lud16 { get; init; }
|
||||||
|
|
||||||
|
[ProtoMember(7)]
|
||||||
|
[JsonProperty("banner")]
|
||||||
|
public string? Banner { get; init; }
|
||||||
|
|
||||||
|
[ProtoMember(8)]
|
||||||
|
[JsonProperty("created")]
|
||||||
|
public DateTime Created { get; init; }
|
||||||
|
|
||||||
|
public static CompactProfile? FromNostrEvent(NostrEvent ev)
|
||||||
|
{
|
||||||
|
var meta = NostrJson.Deserialize<NostrMetadata>(ev.Content);
|
||||||
|
if (meta != default)
|
||||||
|
{
|
||||||
|
return new()
|
||||||
|
{
|
||||||
|
PubKey = Convert.FromHexString(ev.Pubkey!),
|
||||||
|
Name = meta.Name,
|
||||||
|
About = meta.About,
|
||||||
|
Picture = meta.Picture,
|
||||||
|
Nip05 = meta.Nip05,
|
||||||
|
Lud16 = meta.Lud16,
|
||||||
|
Banner = meta.Banner,
|
||||||
|
Created = ev.CreatedAt!.Value
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return default;
|
||||||
|
}
|
||||||
|
}
|
36
NostrServices.Model/RelayDistance.cs
Normal file
36
NostrServices.Model/RelayDistance.cs
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace NostrServices.Model;
|
||||||
|
|
||||||
|
public class RelayDistance
|
||||||
|
{
|
||||||
|
[JsonProperty("url")]
|
||||||
|
public Uri Url { get; init; } = null!;
|
||||||
|
|
||||||
|
[JsonProperty("distance")]
|
||||||
|
public double Distance { get; init; }
|
||||||
|
|
||||||
|
[JsonProperty("users")]
|
||||||
|
public long? Users { get; init; }
|
||||||
|
|
||||||
|
[JsonProperty("country")]
|
||||||
|
public string? Country { get; init; }
|
||||||
|
|
||||||
|
[JsonProperty("city")]
|
||||||
|
public string? City { get; init; }
|
||||||
|
|
||||||
|
[JsonProperty("description")]
|
||||||
|
public string? Description { get; init; }
|
||||||
|
|
||||||
|
[JsonProperty("is_paid")]
|
||||||
|
public bool? IsPaid { get; init; }
|
||||||
|
|
||||||
|
[JsonProperty("is_write_restricted")]
|
||||||
|
public bool? IsWriteRestricted { get; init; }
|
||||||
|
|
||||||
|
[JsonProperty("lat")]
|
||||||
|
public double? Latitude { get; init; }
|
||||||
|
|
||||||
|
[JsonProperty("lon")]
|
||||||
|
public double? Longitude { get; init; }
|
||||||
|
}
|
@ -19,6 +19,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PayForReactions", "PayForRe
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NostrServices.Client", "NostrServices.Client\NostrServices.Client.csproj", "{17CA7036-95BC-4851-BAB1-419996EA2761}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NostrServices.Client", "NostrServices.Client\NostrServices.Client.csproj", "{17CA7036-95BC-4851-BAB1-419996EA2761}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NostrServices.Model", "NostrServices.Model\NostrServices.Model.csproj", "{70E7A5B7-005F-4EEE-9C0D-7FFB1389ED2A}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
@ -49,5 +51,9 @@ Global
|
|||||||
{17CA7036-95BC-4851-BAB1-419996EA2761}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{17CA7036-95BC-4851-BAB1-419996EA2761}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{17CA7036-95BC-4851-BAB1-419996EA2761}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{17CA7036-95BC-4851-BAB1-419996EA2761}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{17CA7036-95BC-4851-BAB1-419996EA2761}.Release|Any CPU.Build.0 = Release|Any CPU
|
{17CA7036-95BC-4851-BAB1-419996EA2761}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{70E7A5B7-005F-4EEE-9C0D-7FFB1389ED2A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{70E7A5B7-005F-4EEE-9C0D-7FFB1389ED2A}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{70E7A5B7-005F-4EEE-9C0D-7FFB1389ED2A}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{70E7A5B7-005F-4EEE-9C0D-7FFB1389ED2A}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
EndGlobal
|
EndGlobal
|
||||||
|
@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Mvc;
|
|||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Nostr.Client.Json;
|
using Nostr.Client.Json;
|
||||||
using Nostr.Client.Messages;
|
using Nostr.Client.Messages;
|
||||||
|
using NostrServices.Model;
|
||||||
using NostrServices.Services;
|
using NostrServices.Services;
|
||||||
|
|
||||||
namespace NostrServices.Controllers;
|
namespace NostrServices.Controllers;
|
||||||
|
@ -3,8 +3,7 @@ using System.Text;
|
|||||||
using AngleSharp;
|
using AngleSharp;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.Extensions.Caching.Memory;
|
using Microsoft.Extensions.Caching.Memory;
|
||||||
using Newtonsoft.Json;
|
using NostrServices.Model;
|
||||||
using ProtoBuf;
|
|
||||||
using StackExchange.Redis;
|
using StackExchange.Redis;
|
||||||
|
|
||||||
namespace NostrServices.Controllers;
|
namespace NostrServices.Controllers;
|
||||||
@ -102,28 +101,3 @@ public class LinkPreviewController : Controller
|
|||||||
return default;
|
return default;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[ProtoContract]
|
|
||||||
public class LinkPreviewData
|
|
||||||
{
|
|
||||||
[ProtoMember(1)]
|
|
||||||
[JsonIgnore]
|
|
||||||
[System.Text.Json.Serialization.JsonIgnore]
|
|
||||||
public List<KeyValuePair<string, string>> OgTags { get; init; } = new();
|
|
||||||
|
|
||||||
[ProtoIgnore]
|
|
||||||
[JsonProperty("og_tags")]
|
|
||||||
public List<string[]> OgTagsJson => OgTags.Select(a => new[] {a.Key, a.Value}).ToList();
|
|
||||||
|
|
||||||
[ProtoMember(2)]
|
|
||||||
[JsonProperty("title")]
|
|
||||||
public string? Title { get; init; }
|
|
||||||
|
|
||||||
[ProtoMember(3)]
|
|
||||||
[JsonProperty("description")]
|
|
||||||
public string? Description { get; init; }
|
|
||||||
|
|
||||||
[ProtoMember(4)]
|
|
||||||
[JsonProperty("image")]
|
|
||||||
public string? Image { get; init; }
|
|
||||||
}
|
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
using AngleSharp;
|
using AngleSharp;
|
||||||
using AngleSharp.Dom;
|
using AngleSharp.Dom;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Newtonsoft.Json;
|
|
||||||
using Nostr.Client.Identifiers;
|
using Nostr.Client.Identifiers;
|
||||||
using Nostr.Client.Messages;
|
using Nostr.Client.Messages;
|
||||||
using Nostr.Client.Utils;
|
using Nostr.Client.Utils;
|
||||||
|
using NostrServices.Model;
|
||||||
using NostrServices.Services;
|
using NostrServices.Services;
|
||||||
using ProtoBuf;
|
using ProtoBuf;
|
||||||
|
|
||||||
@ -18,14 +18,11 @@ public class OpenGraphController : Controller
|
|||||||
{
|
{
|
||||||
private readonly ILogger<OpenGraphController> _logger;
|
private readonly ILogger<OpenGraphController> _logger;
|
||||||
private readonly RedisStore _redisStore;
|
private readonly RedisStore _redisStore;
|
||||||
private readonly HttpClient _httpClient;
|
|
||||||
|
|
||||||
public OpenGraphController(ILogger<OpenGraphController> logger, RedisStore redisStore, HttpClient httpClient)
|
public OpenGraphController(ILogger<OpenGraphController> logger, RedisStore redisStore)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_redisStore = redisStore;
|
_redisStore = redisStore;
|
||||||
_httpClient = httpClient;
|
|
||||||
_httpClient.Timeout = TimeSpan.FromSeconds(2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -118,7 +115,7 @@ public class OpenGraphController : Controller
|
|||||||
{
|
{
|
||||||
case (long)NostrKind.LiveEvent:
|
case (long)NostrKind.LiveEvent:
|
||||||
{
|
{
|
||||||
var host = ev.Tags.FirstOrDefault(a => a is {Key: "p", Values: [_, "host", ..]})?.Values[0] ?? ev.PubKey.ToHex();
|
var host = ev.Tags.FirstOrDefault(a => a.Key == "p" && a.Values[1] == "host")?.Values[0] ?? ev.PubKey.ToHex();
|
||||||
var hostProfile = await _redisStore.GetProfile(host);
|
var hostProfile = await _redisStore.GetProfile(host);
|
||||||
var hostName = hostProfile?.Name ?? profile?.Name ?? "Nostrich";
|
var hostName = hostProfile?.Name ?? profile?.Name ?? "Nostrich";
|
||||||
var stream = ev.GetFirstTagValue("streaming") ?? ev.GetFirstTagValue("recording") ?? "";
|
var stream = ev.GetFirstTagValue("streaming") ?? ev.GetFirstTagValue("recording") ?? "";
|
||||||
|
@ -20,7 +20,7 @@ public class RelaysController : Controller
|
|||||||
const int distance = 5000 * 1000; // 5,000km
|
const int distance = 5000 * 1000; // 5,000km
|
||||||
var relays = await _database.FindCloseRelays(pos.Lat, pos.Lon, distance, count);
|
var relays = await _database.FindCloseRelays(pos.Lat, pos.Lon, distance, count);
|
||||||
|
|
||||||
return Json(relays.Select(RelayDistance.FromDistance));
|
return Json(relays.Select(a => a.FromDistance()));
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("top")]
|
[HttpGet("top")]
|
||||||
@ -30,7 +30,7 @@ public class RelaysController : Controller
|
|||||||
var topSelected = top.OrderByDescending(a => a.Value).Take(count);
|
var topSelected = top.OrderByDescending(a => a.Value).Take(count);
|
||||||
|
|
||||||
var infos = await Task.WhenAll(topSelected.Select(a => _database.GetRelay(a.Key)));
|
var infos = await Task.WhenAll(topSelected.Select(a => _database.GetRelay(a.Key)));
|
||||||
return Json(infos.Where(a => a != default).Select(a => RelayDistance.FromInfo(a!)));
|
return Json(infos.Where(a => a != default).Select(a => a!.FromInfo()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,42 +43,12 @@ public class LatLonReq
|
|||||||
public double Lon { get; init; }
|
public double Lon { get; init; }
|
||||||
}
|
}
|
||||||
|
|
||||||
class RelayDistance
|
public static class RelayDistanceExtension
|
||||||
{
|
{
|
||||||
[JsonProperty("url")]
|
public static Model.RelayDistance FromDistance(this RelayDistance x)
|
||||||
public Uri Url { get; init; } = null!;
|
|
||||||
|
|
||||||
[JsonProperty("distance")]
|
|
||||||
public double Distance { get; init; }
|
|
||||||
|
|
||||||
[JsonProperty("users")]
|
|
||||||
public long? Users { get; init; }
|
|
||||||
|
|
||||||
[JsonProperty("country")]
|
|
||||||
public string? Country { get; init; }
|
|
||||||
|
|
||||||
[JsonProperty("city")]
|
|
||||||
public string? City { get; init; }
|
|
||||||
|
|
||||||
[JsonProperty("description")]
|
|
||||||
public string? Description { get; init; }
|
|
||||||
|
|
||||||
[JsonProperty("is_paid")]
|
|
||||||
public bool? IsPaid { get; init; }
|
|
||||||
|
|
||||||
[JsonProperty("is_write_restricted")]
|
|
||||||
public bool? IsWriteRestricted { get; init; }
|
|
||||||
|
|
||||||
[JsonProperty("lat")]
|
|
||||||
public double? Latitude { get; init; }
|
|
||||||
|
|
||||||
[JsonProperty("lon")]
|
|
||||||
public double? Longitude { get; init; }
|
|
||||||
|
|
||||||
public static RelayDistance FromDistance(Services.RelayDistance x)
|
|
||||||
{
|
{
|
||||||
var rp = x.Relay.Positions.FirstOrDefault(a => a.IpAddress == x.IpAddress) ?? x.Relay.Positions.First();
|
var rp = x.Relay.Positions.FirstOrDefault(a => a.IpAddress == x.IpAddress) ?? x.Relay.Positions.First();
|
||||||
return new RelayDistance()
|
return new Model.RelayDistance()
|
||||||
{
|
{
|
||||||
Url = x.Relay.Url,
|
Url = x.Relay.Url,
|
||||||
Distance = x.Distance,
|
Distance = x.Distance,
|
||||||
@ -93,10 +63,10 @@ class RelayDistance
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static RelayDistance FromInfo(RelayInfo x)
|
public static Model.RelayDistance FromInfo(this RelayInfo x)
|
||||||
{
|
{
|
||||||
var rp = x.Positions.First();
|
var rp = x.Positions.First();
|
||||||
return new RelayDistance()
|
return new Model.RelayDistance()
|
||||||
{
|
{
|
||||||
Url = x.Url,
|
Url = x.Url,
|
||||||
Distance = 0,
|
Distance = 0,
|
||||||
|
@ -5,6 +5,7 @@ using Nostr.Client.Json;
|
|||||||
using Nostr.Client.Messages;
|
using Nostr.Client.Messages;
|
||||||
using Nostr.Client.Utils;
|
using Nostr.Client.Utils;
|
||||||
using NostrRelay;
|
using NostrRelay;
|
||||||
|
using NostrServices.Model;
|
||||||
using NostrServices.Services;
|
using NostrServices.Services;
|
||||||
using ProtoBuf;
|
using ProtoBuf;
|
||||||
using StackExchange.Redis;
|
using StackExchange.Redis;
|
||||||
|
@ -31,6 +31,7 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\NostrRelay\NostrRelay.csproj" />
|
<ProjectReference Include="..\NostrRelay\NostrRelay.csproj" />
|
||||||
|
<ProjectReference Include="..\NostrServices.Model\NostrServices.Model.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
using NBitcoin;
|
using NBitcoin;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Nostr.Client.Messages;
|
using Nostr.Client.Messages;
|
||||||
|
using NostrServices.Model;
|
||||||
|
|
||||||
namespace NostrServices.Services.EventHandlers;
|
namespace NostrServices.Services.EventHandlers;
|
||||||
|
|
||||||
|
@ -1,11 +1,8 @@
|
|||||||
using NBitcoin;
|
using NBitcoin;
|
||||||
using NBitcoin.JsonConverters;
|
|
||||||
using Newtonsoft.Json;
|
|
||||||
using Nostr.Client.Identifiers;
|
using Nostr.Client.Identifiers;
|
||||||
using Nostr.Client.Json;
|
|
||||||
using Nostr.Client.Messages;
|
using Nostr.Client.Messages;
|
||||||
using Nostr.Client.Messages.Metadata;
|
|
||||||
using Nostr.Client.Utils;
|
using Nostr.Client.Utils;
|
||||||
|
using NostrServices.Model;
|
||||||
using ProtoBuf;
|
using ProtoBuf;
|
||||||
using StackExchange.Redis;
|
using StackExchange.Redis;
|
||||||
|
|
||||||
@ -231,64 +228,6 @@ public class CompactEvent
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[ProtoContract]
|
|
||||||
public class CompactProfile
|
|
||||||
{
|
|
||||||
[ProtoMember(1)]
|
|
||||||
[JsonProperty("pubkey")]
|
|
||||||
[JsonConverter(typeof(HexJsonConverter))]
|
|
||||||
public byte[] PubKey { get; init; } = null!;
|
|
||||||
|
|
||||||
[ProtoMember(2)]
|
|
||||||
[JsonProperty("name")]
|
|
||||||
public string? Name { get; init; }
|
|
||||||
|
|
||||||
[ProtoMember(3)]
|
|
||||||
[JsonProperty("about")]
|
|
||||||
public string? About { get; init; }
|
|
||||||
|
|
||||||
[ProtoMember(4)]
|
|
||||||
[JsonProperty("picture")]
|
|
||||||
public string? Picture { get; init; }
|
|
||||||
|
|
||||||
[ProtoMember(5)]
|
|
||||||
[JsonProperty("nip05")]
|
|
||||||
public string? Nip05 { get; init; }
|
|
||||||
|
|
||||||
[ProtoMember(6)]
|
|
||||||
[JsonProperty("lud16")]
|
|
||||||
public string? Lud16 { get; init; }
|
|
||||||
|
|
||||||
[ProtoMember(7)]
|
|
||||||
[JsonProperty("banner")]
|
|
||||||
public string? Banner { get; init; }
|
|
||||||
|
|
||||||
[ProtoMember(8)]
|
|
||||||
[JsonProperty("created")]
|
|
||||||
public DateTime Created { get; init; }
|
|
||||||
|
|
||||||
public static CompactProfile? FromNostrEvent(NostrEvent ev)
|
|
||||||
{
|
|
||||||
var meta = NostrJson.Deserialize<NostrMetadata>(ev.Content);
|
|
||||||
if (meta != default)
|
|
||||||
{
|
|
||||||
return new()
|
|
||||||
{
|
|
||||||
PubKey = Convert.FromHexString(ev.Pubkey!),
|
|
||||||
Name = meta.Name,
|
|
||||||
About = meta.About,
|
|
||||||
Picture = meta.Picture,
|
|
||||||
Nip05 = meta.Nip05,
|
|
||||||
Lud16 = meta.Lud16,
|
|
||||||
Banner = meta.Banner,
|
|
||||||
Created = ev.CreatedAt!.Value
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return default;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[ProtoContract]
|
[ProtoContract]
|
||||||
public class RelayDistance
|
public class RelayDistance
|
||||||
{
|
{
|
||||||
|
@ -105,7 +105,7 @@ public class ReactionQueueWorker : BackgroundService
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
var parsedTarget = Lnurl.ParseLnUrl(senderProfile.LightningAddress ?? "");
|
var parsedTarget = Lnurl.ParseLnUrl(senderProfile.Lud16 ?? "");
|
||||||
if (parsedTarget == default)
|
if (parsedTarget == default)
|
||||||
{
|
{
|
||||||
_logger.LogInformation(
|
_logger.LogInformation(
|
||||||
@ -115,7 +115,7 @@ public class ReactionQueueWorker : BackgroundService
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
_logger.LogInformation("Starting payment for {name} - {addr}", senderProfile.Name, senderProfile.LightningAddress);
|
_logger.LogInformation("Starting payment for {name} - {addr}", senderProfile.Name, senderProfile.Lud16);
|
||||||
var svc = await _lnurl.LoadAsync(parsedTarget.ToString());
|
var svc = await _lnurl.LoadAsync(parsedTarget.ToString());
|
||||||
if (svc == default)
|
if (svc == default)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user