Support onchain for prism

This commit is contained in:
Kukks
2023-10-31 14:35:47 +01:00
parent 64dc8501ae
commit 49cbc37e49
11 changed files with 382 additions and 105 deletions

View File

@@ -0,0 +1,49 @@
using System;
using System.Threading.Tasks;
using BTCPayServer.Abstractions.Contracts;
using BTCPayServer.Data.Payouts.LightningLike;
using BTCPayServer.HostedServices;
namespace BTCPayServer.Plugins.Prism;
public class LNURLPrismClaimCreate : IPluginHookFilter
{
private readonly BTCPayNetworkProvider _networkProvider;
public string Hook => "prism-claim-create";
public LNURLPrismClaimCreate(BTCPayNetworkProvider networkProvider)
{
_networkProvider = networkProvider;
}
public async Task<object> Execute(object args)
{
var network = _networkProvider.GetNetwork<BTCPayNetwork>("BTC");
if (args is not ClaimRequest claimRequest || network is null)
{
return args;
}
if (claimRequest.Destination?.ToString() is not { } potentialLnurl) return args;
try
{
LNURL.LNURL.ExtractUriFromInternetIdentifier(potentialLnurl);
claimRequest.Destination = new LNURLPayClaimDestinaton(potentialLnurl);
return claimRequest;
}
catch (Exception e)
{
try
{
LNURL.LNURL.Parse(potentialLnurl, out _);
claimRequest.Destination = new LNURLPayClaimDestinaton(potentialLnurl);
return claimRequest;
}
catch (Exception)
{
}
}
return args;
}
}