mirror of
https://github.com/aljazceru/BTCPayServerPlugins.git
synced 2025-12-17 07:34:24 +01:00
fix
This commit is contained in:
@@ -9,7 +9,7 @@
|
|||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Product>Blink</Product>
|
<Product>Blink</Product>
|
||||||
<Description>Blink Lightning support</Description>
|
<Description>Blink Lightning support</Description>
|
||||||
<Version>1.0.3</Version>
|
<Version>1.0.4</Version>
|
||||||
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
|
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
|
||||||
<RootNamespace>BTCPayServer.Plugins.Blink</RootNamespace>
|
<RootNamespace>BTCPayServer.Plugins.Blink</RootNamespace>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#nullable enable
|
#nullable enable
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
@@ -9,10 +10,13 @@ using BTCPayServer.HostedServices;
|
|||||||
using BTCPayServer.Lightning;
|
using BTCPayServer.Lightning;
|
||||||
using GraphQL;
|
using GraphQL;
|
||||||
using GraphQL.Client.Http;
|
using GraphQL.Client.Http;
|
||||||
|
using GraphQL.Client.Http.Websocket;
|
||||||
using GraphQL.Client.Serializer.Newtonsoft;
|
using GraphQL.Client.Serializer.Newtonsoft;
|
||||||
using Microsoft.AspNetCore.OutputCaching;
|
using Microsoft.AspNetCore.OutputCaching;
|
||||||
using NBitcoin;
|
using NBitcoin;
|
||||||
|
using Newtonsoft.Json;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
|
using Newtonsoft.Json.Serialization;
|
||||||
using Network = NBitcoin.Network;
|
using Network = NBitcoin.Network;
|
||||||
|
|
||||||
namespace BTCPayServer.Plugins.Blink;
|
namespace BTCPayServer.Plugins.Blink;
|
||||||
@@ -28,17 +32,32 @@ public class BlinkLightningClient : ILightningClient
|
|||||||
private readonly Network _network;
|
private readonly Network _network;
|
||||||
private readonly GraphQLHttpClient _client;
|
private readonly GraphQLHttpClient _client;
|
||||||
|
|
||||||
|
public class BlinkConnectionInit
|
||||||
|
{
|
||||||
|
[JsonProperty("X-API-KEY")] public string ApiKey { get; set; }
|
||||||
|
}
|
||||||
public BlinkLightningClient(string apiKey, Uri apiEndpoint, string walletId, Network network, HttpClient httpClient)
|
public BlinkLightningClient(string apiKey, Uri apiEndpoint, string walletId, Network network, HttpClient httpClient)
|
||||||
{
|
{
|
||||||
_apiKey = apiKey;
|
_apiKey = apiKey;
|
||||||
_apiEndpoint = apiEndpoint;
|
_apiEndpoint = apiEndpoint;
|
||||||
WalletId = walletId;
|
WalletId = walletId;
|
||||||
_network = network;
|
_network = network;
|
||||||
_client = new GraphQLHttpClient(new GraphQLHttpClientOptions() {EndPoint = _apiEndpoint, WebSocketEndPoint = new Uri( "wss://" + _apiEndpoint.Host.Replace("api.", "ws.") + _apiEndpoint.PathAndQuery), ConfigureWebsocketOptions =
|
_client = new GraphQLHttpClient(new GraphQLHttpClientOptions() {EndPoint = _apiEndpoint,
|
||||||
options =>
|
WebSocketEndPoint =
|
||||||
|
new Uri("wss://" + _apiEndpoint.Host.Replace("api.", "ws.") + _apiEndpoint.PathAndQuery),
|
||||||
|
WebSocketProtocol = WebSocketProtocols.GRAPHQL_TRANSPORT_WS,
|
||||||
|
ConfigureWebSocketConnectionInitPayload = options => new BlinkConnectionInit() {ApiKey = apiKey},
|
||||||
|
ConfigureWebsocketOptions =
|
||||||
|
_ => { }
|
||||||
|
}, new NewtonsoftJsonSerializer(settings =>
|
||||||
|
{
|
||||||
|
if (settings.ContractResolver is CamelCasePropertyNamesContractResolver
|
||||||
|
camelCasePropertyNamesContractResolver)
|
||||||
{
|
{
|
||||||
options.SetRequestHeader("X-API-KEY", apiKey);
|
camelCasePropertyNamesContractResolver.NamingStrategy.OverrideSpecifiedNames = false;
|
||||||
}}, new NewtonsoftJsonSerializer(), httpClient);
|
camelCasePropertyNamesContractResolver.NamingStrategy.ProcessDictionaryKeys = false;
|
||||||
|
}
|
||||||
|
}), httpClient);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -384,7 +403,7 @@ expiresIn = (int)createInvoiceRequest.Expiry.TotalMinutes
|
|||||||
{
|
{
|
||||||
|
|
||||||
_lightningClient = lightningClient;
|
_lightningClient = lightningClient;
|
||||||
var stream = httpClient.CreateSubscriptionStream<dynamic>(new GraphQLRequest()
|
var stream = httpClient.CreateSubscriptionStream<JObject>(new GraphQLRequest()
|
||||||
{
|
{
|
||||||
Query = @"subscription myUpdates {
|
Query = @"subscription myUpdates {
|
||||||
myUpdates {
|
myUpdates {
|
||||||
@@ -409,14 +428,16 @@ expiresIn = (int)createInvoiceRequest.Expiry.TotalMinutes
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var x = stream;
|
if(response.Data is null)
|
||||||
var y = _lightningClient;
|
|
||||||
if (response.Data.myUpdates.update.transaction.direction != "RECEIVE")
|
|
||||||
return;
|
return;
|
||||||
if ((await _lightningClient.GetInvoice(response.Data.myUpdates.update.transaction.initiationVia
|
if (response.Data.SelectToken("myUpdates.update.transaction.direction")?.Value<string>() != "RECEIVE")
|
||||||
.paymentHash.ToString())) is LightningInvoice inv)
|
return;
|
||||||
|
var invoiceId = response.Data
|
||||||
|
.SelectToken("myUpdates.update.transaction.initiationVia.paymentHash")?.Value<string>();
|
||||||
|
if (invoiceId is null)
|
||||||
|
return;
|
||||||
|
if (await _lightningClient.GetInvoice(invoiceId) is LightningInvoice inv)
|
||||||
{
|
{
|
||||||
|
|
||||||
_invoices.Writer.TryWrite(inv);
|
_invoices.Writer.TryWrite(inv);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user