mirror of
https://github.com/aljazceru/BTCPayServerPlugins.git
synced 2025-12-17 15:44:26 +01:00
Fix: Nostr Lighthning Client was always failing
This commit is contained in:
@@ -169,11 +169,21 @@ public class NostrWalletConnectLightningClient : ILightningClient
|
||||
var (nostrClient, usage) = await _nostrClientPool.GetClientAndConnect(_connectParams.relays, cts.Token);
|
||||
using (usage)
|
||||
{
|
||||
var tx = await nostrClient.SendNIP47Request<NIP47.Nip47Transaction>(_connectParams.pubkey, _connectParams.secret,
|
||||
NIP47.Nip47Transaction tx;
|
||||
try
|
||||
{
|
||||
tx = await nostrClient.SendNIP47Request<NIP47.Nip47Transaction>(_connectParams.pubkey, _connectParams.secret,
|
||||
new NIP47.LookupInvoiceRequest()
|
||||
{
|
||||
PaymentHash = paymentHash
|
||||
}, cts.Token);
|
||||
}
|
||||
// The standard says it returns NOT_FOUND error, but
|
||||
// Alby returns INTERNAL error... Probably safer to catch all
|
||||
catch (Exception)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return ToLightningPayment(tx)!;
|
||||
}
|
||||
}
|
||||
@@ -405,19 +415,16 @@ public class NostrWalletConnectLightningClient : ILightningClient
|
||||
public async Task<PayResponse> Pay(string bolt11, PayInvoiceParams payParams,
|
||||
CancellationToken cancellation = new())
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
var cts = CancellationTokenSource.CreateLinkedTokenSource(cancellation);
|
||||
cts.CancelAfter(TimeSpan.FromSeconds(10));
|
||||
var (client, usage) = await _nostrClientPool.GetClientAndConnect(_connectParams.relays, cts.Token);
|
||||
|
||||
using (usage)
|
||||
{
|
||||
var response = await client.SendNIP47Request<NIP47.PayInvoiceResponse>(_connectParams.pubkey,
|
||||
_connectParams.secret,
|
||||
bolt11 is null
|
||||
? new NIP47.PayKeysendRequest()
|
||||
NIP47.INIP47Request request;
|
||||
if (bolt11 is null)
|
||||
{
|
||||
request = new NIP47.PayKeysendRequest()
|
||||
{
|
||||
Amount = Convert.ToDecimal(payParams.Amount.MilliSatoshi),
|
||||
Pubkey = payParams.Destination.ToHex(),
|
||||
@@ -426,20 +433,25 @@ public class NostrWalletConnectLightningClient : ILightningClient
|
||||
Type = kv.Key.ToString(),
|
||||
Value = kv.Value
|
||||
}).ToArray()
|
||||
};
|
||||
|
||||
}
|
||||
: new NIP47.PayInvoiceRequest()
|
||||
else
|
||||
{
|
||||
request = new NIP47.PayInvoiceRequest()
|
||||
{
|
||||
Invoice = bolt11,
|
||||
Amount = payParams.Amount?.MilliSatoshi is not null
|
||||
? Convert.ToDecimal(payParams.Amount.MilliSatoshi)
|
||||
: null,
|
||||
}, cts.Token);
|
||||
};
|
||||
|
||||
var payHash = payParams?.PaymentHash?.ToString()??
|
||||
(response.Preimage is not null?
|
||||
ConvertHelper.ToHexString(SHA256.HashData(Convert.FromHexString(response.Preimage))):
|
||||
BOLT11PaymentRequest.Parse(bolt11, _network).PaymentHash.ToString());
|
||||
}
|
||||
var response = await client.SendNIP47Request<NIP47.PayInvoiceResponse>(_connectParams.pubkey, _connectParams.secret, request, cts.Token);
|
||||
var payHash = ConvertHelper.ToHexString(SHA256.HashData(Convert.FromHexString(response.Preimage)));
|
||||
|
||||
try
|
||||
{
|
||||
var tx = await client.SendNIP47Request<NIP47.Nip47Transaction>(_connectParams.pubkey, _connectParams.secret,
|
||||
new NIP47.LookupInvoiceRequest()
|
||||
{
|
||||
@@ -456,17 +468,20 @@ public class NostrWalletConnectLightningClient : ILightningClient
|
||||
FeeAmount = lp.Fee
|
||||
});
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return new PayResponse()
|
||||
return new PayResponse(PayResult.Ok, new PayDetails()
|
||||
{
|
||||
Result = PayResult.Error,
|
||||
ErrorDetail = e.Message
|
||||
};
|
||||
Status = LightningPaymentStatus.Complete,
|
||||
PaymentHash = new uint256(payHash),
|
||||
Preimage = new uint256(response.Preimage),
|
||||
})
|
||||
{ ErrorDetail = e.Message };
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public async Task<PayResponse> Pay(string bolt11, CancellationToken cancellation = new())
|
||||
{
|
||||
return await Pay(bolt11, new PayInvoiceParams(), cancellation);
|
||||
|
||||
Reference in New Issue
Block a user