handle resp better for payment

This commit is contained in:
Kukks
2024-06-24 16:17:57 +02:00
parent 0360c374e4
commit 2272a063c1
2 changed files with 20 additions and 7 deletions

View File

@@ -11,7 +11,7 @@
<PropertyGroup>
<Product>Nostr</Product>
<Description>NIP5 addresses, Zap support, Nostr Wallet Connect Lightning support</Description>
<Version>1.1.10</Version>
<Version>1.1.11</Version>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>
<!-- Plugin development properties -->

View File

@@ -11,6 +11,7 @@ using NBitcoin;
using NBitcoin.Secp256k1;
using NNostr.Client;
using NNostr.Client.Protocols;
using SHA256 = System.Security.Cryptography.SHA256;
namespace BTCPayServer.Plugins.NIP05;
@@ -122,10 +123,10 @@ public class NostrWalletConnectLightningClient : ILightningClient
private LightningPayment? ToLightningPayment(NIP47.Nip47Transaction tx)
{
if (tx.Type != "outgoing")
{
return null;
}
// if (tx.Type != "outgoing")
// {
// return null;
// }
var isPaid = tx.SettledAt.HasValue || !string.IsNullOrEmpty(tx.Preimage);
var invoice = BOLT11PaymentRequest.Parse(tx.Invoice, _network);
@@ -415,7 +416,19 @@ public class NostrWalletConnectLightningClient : ILightningClient
? Convert.ToDecimal(payParams.Amount.MilliSatoshi)
: null,
}, cancellation);
var lp = ToLightningPayment(response);
var payHash = response.PaymentHash??
payParams?.PaymentHash?.ToString()??
(response.Preimage is not null?
ConvertHelper.ToHexString(SHA256.HashData(Convert.FromHexString(response.Preimage))):
BOLT11PaymentRequest.Parse(bolt11, _network).PaymentHash.ToString());
var tx = await client.SendNIP47Request<NIP47.Nip47Transaction>(_connectParams.pubkey, _connectParams.secret,
new NIP47 .LookupInvoiceRequest()
{
PaymentHash = payHash
}, cancellation);
var lp = ToLightningPayment(tx)!;
return new PayResponse(lp.Status == LightningPaymentStatus.Complete ? PayResult.Ok : PayResult.Error,
new PayDetails()
{