mirror of
https://github.com/aljazceru/BTCPayServerPlugins.git
synced 2025-12-17 15:44:26 +01:00
prism: support onchain source & fix catach all with bolt 11 payments
This commit is contained in:
@@ -11,7 +11,7 @@
|
|||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Product>LN Prism</Product>
|
<Product>LN Prism</Product>
|
||||||
<Description>Automated value splits for lightning.</Description>
|
<Description>Automated value splits for lightning.</Description>
|
||||||
<Version>1.1.8</Version>
|
<Version>1.1.9</Version>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<!-- Plugin development properties -->
|
<!-- Plugin development properties -->
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
|
|||||||
@@ -25,7 +25,7 @@
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
||||||
<button type="button" class="btn btn-sm btn-link" @onclick="StartUpdate(dest,balance)">Update</button>
|
<button type="button" class="btn btn-sm btn-link" @onclick="() => StartUpdate(dest,balance)">Update</button>
|
||||||
}
|
}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|||||||
@@ -0,0 +1,54 @@
|
|||||||
|
@* @using NBitcoin *@
|
||||||
|
@* @if (Destinations.Any()) *@
|
||||||
|
@* { *@
|
||||||
|
@* <div class="form-group"> *@
|
||||||
|
@* <select class="form-select" @bind="SelectedDestinationId"> *@
|
||||||
|
@* *@
|
||||||
|
@* <option value="null">Select destination to configure</option> *@
|
||||||
|
@* @foreach (var destination in Destinations) *@
|
||||||
|
@* { *@
|
||||||
|
@* <option value="@destination.Key">@destination.Key</option> *@
|
||||||
|
@* } *@
|
||||||
|
@* </select> *@
|
||||||
|
@* </div> *@
|
||||||
|
@* *@
|
||||||
|
@* @if (SelectedDestinationId is not null && SelectedDestinationId != "null") *@
|
||||||
|
@* { *@
|
||||||
|
@* <PrismDestinationEditor ValidateId="ValidateId" Id="@SelectedDestinationId" IdChanged="OnIdRenamed" ValidateDestination="s => ValidateDestination(s, false)" @bind-Settings="SelectedDestination"></PrismDestinationEditor> *@
|
||||||
|
@* } *@
|
||||||
|
@* } *@
|
||||||
|
@* *@
|
||||||
|
@* @code { *@
|
||||||
|
@* *@
|
||||||
|
@* [Parameter] *@
|
||||||
|
@* public Dictionary<string, PrismDestination> Destinations { get; set; } *@
|
||||||
|
@* *@
|
||||||
|
@* *@
|
||||||
|
@* public string? SelectedDestinationId { get; set; } *@
|
||||||
|
@* *@
|
||||||
|
@* public PrismDestination? SelectedDestination *@
|
||||||
|
@* { *@
|
||||||
|
@* get *@
|
||||||
|
@* { *@
|
||||||
|
@* if (SelectedDestinationId is null or "null") *@
|
||||||
|
@* return null; *@
|
||||||
|
@* Destinations.TryGetValue(SelectedDestinationId, out var res); *@
|
||||||
|
@* return res; *@
|
||||||
|
@* } *@
|
||||||
|
@* set *@
|
||||||
|
@* { *@
|
||||||
|
@* if (SelectedDestinationId is null) *@
|
||||||
|
@* return; *@
|
||||||
|
@* if (value is null) *@
|
||||||
|
@* { *@
|
||||||
|
@* Destinations.Remove(SelectedDestinationId); *@
|
||||||
|
@* SelectedDestinationId = null; *@
|
||||||
|
@* } *@
|
||||||
|
@* else *@
|
||||||
|
@* { *@
|
||||||
|
@* Destinations.AddOrReplace(SelectedDestinationId, value); *@
|
||||||
|
@* } *@
|
||||||
|
@* } *@
|
||||||
|
@* } *@
|
||||||
|
@* *@
|
||||||
|
@* } *@
|
||||||
@@ -304,7 +304,7 @@ namespace BTCPayServer.Plugins.Prism
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (evt is InvoiceEvent invoiceEvent &&
|
if (evt is InvoiceEvent invoiceEvent &&
|
||||||
new[] {InvoiceEventCode.Completed, InvoiceEventCode.MarkedCompleted}.Contains(
|
new[] {InvoiceEventCode.Confirmed, InvoiceEventCode.MarkedCompleted}.Contains(
|
||||||
invoiceEvent.EventCode))
|
invoiceEvent.EventCode))
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -313,13 +313,13 @@ namespace BTCPayServer.Plugins.Prism
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
var onChainCatchAllIdentifier = "*"+ PaymentTypes.BTCLike.ToStringNormalized();
|
||||||
var catchAllPrism = prismSettings.Splits.FirstOrDefault(split => split.Source == "*");
|
var catchAllPrism = prismSettings.Splits.FirstOrDefault(split => split.Source == "*" || split.Source ==onChainCatchAllIdentifier);
|
||||||
Split prism = null;
|
Split prism = null;
|
||||||
LightningAddressData address = null;
|
LightningAddressData address = null;
|
||||||
var pm = invoiceEvent.Invoice.GetPaymentMethod(new PaymentMethodId("BTC", LNURLPayPaymentType.Instance));
|
|
||||||
var pmdRaw = pm?.GetPaymentMethodDetails();
|
var pm = invoiceEvent.Invoice.GetPaymentMethod(new PaymentMethodId("BTC", LNURLPayPaymentType.Instance));
|
||||||
var pmd = pmdRaw as LNURLPayPaymentMethodDetails;
|
var pmd = pm?.GetPaymentMethodDetails() as LNURLPayPaymentMethodDetails;
|
||||||
if (string.IsNullOrEmpty(pmd?.ConsumedLightningAddress) && catchAllPrism is null)
|
if (string.IsNullOrEmpty(pmd?.ConsumedLightningAddress) && catchAllPrism is null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
@@ -333,15 +333,18 @@ namespace BTCPayServer.Plugins.Prism
|
|||||||
|
|
||||||
prism = prismSettings.Splits.FirstOrDefault(s => s.Source.Equals(address.Username, StringComparison.InvariantCultureIgnoreCase));
|
prism = prismSettings.Splits.FirstOrDefault(s => s.Source.Equals(address.Username, StringComparison.InvariantCultureIgnoreCase));
|
||||||
}
|
}
|
||||||
|
else if (catchAllPrism?.Source == onChainCatchAllIdentifier)
|
||||||
|
{
|
||||||
|
pm = invoiceEvent.Invoice.GetPaymentMethod(new PaymentMethodId("BTC", PaymentTypes.BTCLike));
|
||||||
|
prism = catchAllPrism;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//do not run prism on payments not LN based.
|
if (pmd is null)
|
||||||
if (invoiceEvent.Invoice.GetPayments("BTC", true).All(entity =>
|
{
|
||||||
{
|
pm = invoiceEvent.Invoice.GetPaymentMethod(new PaymentMethodId("BTC", PaymentTypes.LightningLike));
|
||||||
var pmi = entity.GetPaymentMethodId();
|
}
|
||||||
return pmi.CryptoCode == "BTC" && (pmi.PaymentType == LightningPaymentType.Instance || pmi.PaymentType == LNURLPayPaymentType.Instance);
|
prism = catchAllPrism;
|
||||||
}))
|
|
||||||
prism = catchAllPrism;
|
|
||||||
}
|
}
|
||||||
var splits = prism?.Destinations;
|
var splits = prism?.Destinations;
|
||||||
if (splits?.Any() is not true)
|
if (splits?.Any() is not true)
|
||||||
@@ -351,6 +354,10 @@ namespace BTCPayServer.Plugins.Prism
|
|||||||
|
|
||||||
|
|
||||||
var msats = LightMoney.FromUnit(pm.Calculate().CryptoPaid, LightMoneyUnit.BTC).ToUnit(LightMoneyUnit.MilliSatoshi);
|
var msats = LightMoney.FromUnit(pm.Calculate().CryptoPaid, LightMoneyUnit.BTC).ToUnit(LightMoneyUnit.MilliSatoshi);
|
||||||
|
if(msats <= 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
//compute the sats for each destination based on splits percentage
|
//compute the sats for each destination based on splits percentage
|
||||||
var msatsPerDestination =
|
var msatsPerDestination =
|
||||||
splits.ToDictionary(s => s.Destination, s => (long) (msats * (s.Percentage / 100)));
|
splits.ToDictionary(s => s.Destination, s => (long) (msats * (s.Percentage / 100)));
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ public class PrismClaimCreate : IPluginHookFilter
|
|||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
if (BOLT11PaymentRequest.TryParse(shift.depositAddress, out var bolt11, network.NBitcoinNetwork))
|
if (BOLT11PaymentRequest.TryParse(shift.depositAddress, out var bolt11, network.NBitcoinNetwork))
|
||||||
{
|
{
|
||||||
claimRequest.Destination = new BoltInvoiceClaimDestination(shift.depositAddress, bolt11);
|
claimRequest.Destination = new BoltInvoiceClaimDestination(shift.depositAddress, bolt11);
|
||||||
claimRequest.Metadata = JObject.FromObject(new
|
claimRequest.Metadata = JObject.FromObject(new
|
||||||
|
|||||||
Reference in New Issue
Block a user