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>
|
||||
<Product>LN Prism</Product>
|
||||
<Description>Automated value splits for lightning.</Description>
|
||||
<Version>1.1.8</Version>
|
||||
<Version>1.1.9</Version>
|
||||
</PropertyGroup>
|
||||
<!-- Plugin development properties -->
|
||||
<PropertyGroup>
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
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>
|
||||
</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 &&
|
||||
new[] {InvoiceEventCode.Completed, InvoiceEventCode.MarkedCompleted}.Contains(
|
||||
new[] {InvoiceEventCode.Confirmed, InvoiceEventCode.MarkedCompleted}.Contains(
|
||||
invoiceEvent.EventCode))
|
||||
{
|
||||
|
||||
@@ -313,13 +313,13 @@ namespace BTCPayServer.Plugins.Prism
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var catchAllPrism = prismSettings.Splits.FirstOrDefault(split => split.Source == "*");
|
||||
var onChainCatchAllIdentifier = "*"+ PaymentTypes.BTCLike.ToStringNormalized();
|
||||
var catchAllPrism = prismSettings.Splits.FirstOrDefault(split => split.Source == "*" || split.Source ==onChainCatchAllIdentifier);
|
||||
Split prism = null;
|
||||
LightningAddressData address = null;
|
||||
|
||||
var pm = invoiceEvent.Invoice.GetPaymentMethod(new PaymentMethodId("BTC", LNURLPayPaymentType.Instance));
|
||||
var pmdRaw = pm?.GetPaymentMethodDetails();
|
||||
var pmd = pmdRaw as LNURLPayPaymentMethodDetails;
|
||||
var pmd = pm?.GetPaymentMethodDetails() as LNURLPayPaymentMethodDetails;
|
||||
if (string.IsNullOrEmpty(pmd?.ConsumedLightningAddress) && catchAllPrism is null)
|
||||
{
|
||||
return;
|
||||
@@ -333,14 +333,17 @@ namespace BTCPayServer.Plugins.Prism
|
||||
|
||||
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
|
||||
{
|
||||
//do not run prism on payments not LN based.
|
||||
if (invoiceEvent.Invoice.GetPayments("BTC", true).All(entity =>
|
||||
if (pmd is null)
|
||||
{
|
||||
var pmi = entity.GetPaymentMethodId();
|
||||
return pmi.CryptoCode == "BTC" && (pmi.PaymentType == LightningPaymentType.Instance || pmi.PaymentType == LNURLPayPaymentType.Instance);
|
||||
}))
|
||||
pm = invoiceEvent.Invoice.GetPaymentMethod(new PaymentMethodId("BTC", PaymentTypes.LightningLike));
|
||||
}
|
||||
prism = catchAllPrism;
|
||||
}
|
||||
var splits = prism?.Destinations;
|
||||
@@ -351,6 +354,10 @@ namespace BTCPayServer.Plugins.Prism
|
||||
|
||||
|
||||
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
|
||||
var msatsPerDestination =
|
||||
splits.ToDictionary(s => s.Destination, s => (long) (msats * (s.Percentage / 100)));
|
||||
|
||||
Reference in New Issue
Block a user