diff --git a/Plugins/BTCPayServer.Plugins.SideShift/PrismClaimCreate.cs b/Plugins/BTCPayServer.Plugins.SideShift/PrismClaimCreate.cs new file mode 100644 index 0000000..ab2ac1a --- /dev/null +++ b/Plugins/BTCPayServer.Plugins.SideShift/PrismClaimCreate.cs @@ -0,0 +1,84 @@ +using System; +using System.Net.Http; +using System.Threading.Tasks; +using BTCPayServer.Abstractions.Contracts; +using BTCPayServer.Data.Payouts.LightningLike; +using BTCPayServer.HostedServices; +using BTCPayServer.Lightning; +using Newtonsoft.Json.Linq; + +namespace BTCPayServer.Plugins.SideShift; + +public class PrismClaimCreate : IPluginHookFilter +{ + private readonly IHttpClientFactory _httpClientFactory; + private readonly BTCPayNetworkProvider _networkProvider; + public string Hook => "prism-claim-create"; + + public PrismClaimCreate(IHttpClientFactory httpClientFactory, BTCPayNetworkProvider networkProvider) + { + _httpClientFactory = httpClientFactory; + _networkProvider = networkProvider; + } + public async Task Execute(object args) + { + var network = _networkProvider.GetNetwork("BTC"); + if (args is not ClaimRequest claimRequest || network is null) + { + return Task.FromResult(args); + } + + if (claimRequest.Destination?.ToString() is not { } args1 || !args1.StartsWith("sideshift:")) return args; + var request = JObject.Parse(args1.Substring("sideshift:".Length)).ToObject(); + if (!request.Valid()) + { + return null; + } + var client = _httpClientFactory.CreateClient("sideshift"); + + + var shiftResponse = await client.PostAsJsonAsync("https://sideshift.ai/api/v2/shifts/variable", new + { + settleAddress = request.ShiftDestination, + affiliateId = "qg0OrfHJV", + settleMemo = request.ShiftMemo, + depositCoin = "BTC", + depositNetwork = "lightning", + settleCoin = request.ShiftCoin, + settleNetwork = request.ShiftNetwork, + } + ); + if (!shiftResponse.IsSuccessStatusCode) + { + return null; + } + var shift = await shiftResponse.Content.ReadAsAsync(); + try + { + LNURL.LNURL.Parse(shift.depositAddress, out _); + claimRequest.Destination = new LNURLPayClaimDestinaton(shift.depositAddress); + claimRequest.Metadata = JObject.FromObject(new + { + Source = $"Prism->Sideshift", + SourceLink = $"https://sideshift.ai/orders/{shift.id}?openSupport=true", + }); + return claimRequest; + } + catch (Exception e) + { + if (BOLT11PaymentRequest.TryParse(shift.depositAddress, out var bolt11, network.NBitcoinNetwork)) + { + claimRequest.Destination = new BoltInvoiceClaimDestination(shift.depositAddress, bolt11); + claimRequest.Metadata = JObject.FromObject(new + { + Source = $"Prism->Sideshift", + SourceLink = $"https://sideshift.ai/orders/{shift.id}?openSupport=true", + }); + return claimRequest; + } + } + + return null; + + } +} \ No newline at end of file diff --git a/Plugins/BTCPayServer.Plugins.SideShift/PrismDestinationValidate.cs b/Plugins/BTCPayServer.Plugins.SideShift/PrismDestinationValidate.cs new file mode 100644 index 0000000..4bf158f --- /dev/null +++ b/Plugins/BTCPayServer.Plugins.SideShift/PrismDestinationValidate.cs @@ -0,0 +1,17 @@ +using System.Threading.Tasks; +using BTCPayServer.Abstractions.Contracts; +using Newtonsoft.Json.Linq; + +namespace BTCPayServer.Plugins.SideShift; + +public class PrismDestinationValidate : IPluginHookFilter +{ + public string Hook => "prism-destination-validate"; + public async Task Execute(object args) + { + if (args is not string args1 || !args1.StartsWith("sideshift:")) return args; + var json = JObject.Parse(args1.Substring("sideshift:".Length)).ToObject(); + return json.Valid(); + } + +} \ No newline at end of file diff --git a/Plugins/BTCPayServer.Plugins.SideShift/PrismEditFiltercs.cs b/Plugins/BTCPayServer.Plugins.SideShift/PrismEditFiltercs.cs new file mode 100644 index 0000000..c730736 --- /dev/null +++ b/Plugins/BTCPayServer.Plugins.SideShift/PrismEditFiltercs.cs @@ -0,0 +1,15 @@ +using System.Threading.Tasks; +using BTCPayServer.Abstractions.Contracts; + +namespace BTCPayServer.Plugins.SideShift; + +public class PrismEditFilter : IPluginHookFilter +{ + public string Hook => "prism-edit-buttons"; + + public Task Execute(object args) + { + return Task.FromResult(( args??"") + ""); + + } +} \ No newline at end of file diff --git a/Plugins/BTCPayServer.Plugins.SideShift/PrismSideshiftDestination.cs b/Plugins/BTCPayServer.Plugins.SideShift/PrismSideshiftDestination.cs new file mode 100644 index 0000000..a4eb247 --- /dev/null +++ b/Plugins/BTCPayServer.Plugins.SideShift/PrismSideshiftDestination.cs @@ -0,0 +1,15 @@ +namespace BTCPayServer.Plugins.SideShift; + +public class PrismSideshiftDestination +{ + public string ShiftCoin { get; set; } + public string ShiftNetwork { get; set; } + public string ShiftDestination { get; set; } + public string ShiftMemo { get; set; } + + public bool Valid() + { + return !string.IsNullOrEmpty(ShiftCoin) && !string.IsNullOrEmpty(ShiftNetwork) && + !string.IsNullOrEmpty(ShiftDestination); + } +} \ No newline at end of file diff --git a/Plugins/BTCPayServer.Plugins.SideShift/SideShiftAvailableCoin.cs b/Plugins/BTCPayServer.Plugins.SideShift/SideShiftAvailableCoin.cs new file mode 100644 index 0000000..0f2ecfa --- /dev/null +++ b/Plugins/BTCPayServer.Plugins.SideShift/SideShiftAvailableCoin.cs @@ -0,0 +1,14 @@ +using Newtonsoft.Json.Linq; + +namespace BTCPayServer.Plugins.SideShift; + +public class SideShiftAvailableCoin +{ + public string coin { get; set; } + public string[] networks { get; set; } + public string name { get; set; } + public bool hasMemo { get; set; } + public JToken fixedOnly { get; set; } + public JToken variableOnly { get; set; } + public JToken settleOffline { get; set; } +} \ No newline at end of file diff --git a/Plugins/BTCPayServer.Plugins.SideShift/SideShiftController.cs b/Plugins/BTCPayServer.Plugins.SideShift/SideShiftController.cs index 61048b0..9a0e7eb 100644 --- a/Plugins/BTCPayServer.Plugins.SideShift/SideShiftController.cs +++ b/Plugins/BTCPayServer.Plugins.SideShift/SideShiftController.cs @@ -201,7 +201,7 @@ namespace BTCPayServer.Plugins.SideShift if (claim.Result == ClaimRequest.ClaimResult.Ok) { await using var ctx = _dbContextFactory.CreateContext(); - ppBlob.Description += $"The payout of {claim.PayoutData.Destination} will be forwarded to SideShift.ai for further conversion. Please go to the order page for support."; + ppBlob.Description += $"
The payout of {claim.PayoutData.Destination} will be forwarded to SideShift.ai for further conversion. Please go to the order page for support."; pp.SetBlob(ppBlob); ctx.Attach(pp).State = EntityState.Modified; await ctx.SaveChangesAsync(); diff --git a/Plugins/BTCPayServer.Plugins.SideShift/SideShiftPlugin.cs b/Plugins/BTCPayServer.Plugins.SideShift/SideShiftPlugin.cs index 14bc3ed..94d68da 100644 --- a/Plugins/BTCPayServer.Plugins.SideShift/SideShiftPlugin.cs +++ b/Plugins/BTCPayServer.Plugins.SideShift/SideShiftPlugin.cs @@ -1,14 +1,7 @@ -using System; -using System.Net.Http; -using System.Threading.Tasks; using BTCPayServer.Abstractions.Contracts; using BTCPayServer.Abstractions.Models; using BTCPayServer.Abstractions.Services; -using BTCPayServer.Data; -using BTCPayServer.Data.Payouts.LightningLike; -using BTCPayServer.Lightning; using Microsoft.Extensions.DependencyInjection; -using Newtonsoft.Json.Linq; namespace BTCPayServer.Plugins.SideShift { @@ -47,107 +40,9 @@ namespace BTCPayServer.Plugins.SideShift applicationBuilder.AddSingleton(new UIExtension("SideShift/PrismEnhance", "prism-edit")); applicationBuilder.AddSingleton(); - applicationBuilder.AddSingleton(); + applicationBuilder.AddSingleton(); + applicationBuilder.AddSingleton(); base.Execute(applicationBuilder); } } - - - public class PrismSideshiftDestination - { - public string ShiftCoin { get; set; } - public string ShiftNetwork { get; set; } - public string ShiftDestination { get; set; } - public string ShiftMemo { get; set; } - - public bool Valid() - { - return !string.IsNullOrEmpty(ShiftCoin) && !string.IsNullOrEmpty(ShiftNetwork) && - !string.IsNullOrEmpty(ShiftDestination); - } - } - - public class PrismDestinationValidate : IPluginHookFilter - { - public string Hook => "prism-destination-validate"; - public async Task Execute(object args) - { - if (args is not string args1 || !args1.StartsWith("sideshift:")) return args; - var json = JObject.Parse(args1.Substring("sideshift:".Length)).ToObject(); - return json.Valid(); - } - - } - - public class PrismClaimDestination : IPluginHookFilter - { - private readonly IHttpClientFactory _httpClientFactory; - private readonly BTCPayNetworkProvider _networkProvider; - public string Hook => "prism-claim-destination"; - - public PrismClaimDestination(IHttpClientFactory httpClientFactory, BTCPayNetworkProvider networkProvider) - { - _httpClientFactory = httpClientFactory; - _networkProvider = networkProvider; - } - public async Task Execute(object args) - { - var network = _networkProvider.GetNetwork("BTC"); - if (args is not string s || network is null) - { - return Task.FromResult(args); - } - if (args is not string args1 || !args1.StartsWith("sideshift:")) return args; - var request = JObject.Parse(args1.Substring("sideshift:".Length)).ToObject(); - if (!request.Valid()) - { - return null; - } - var client = _httpClientFactory.CreateClient("sideshift"); - - - var shiftResponse = await client.PostAsJsonAsync("https://sideshift.ai/api/v2/shifts/variable", new - { - settleAddress = request.ShiftDestination, - affiliateId = "qg0OrfHJV", - settleMemo = request.ShiftMemo, - depositCoin = "BTC", - depositNetwork = "lightning", - settleCoin = request.ShiftCoin, - settleNetwork = request.ShiftNetwork, - } - ); - if (!shiftResponse.IsSuccessStatusCode) - { - return null; - } - var shift = await shiftResponse.Content.ReadAsAsync(); - try - { - LNURL.LNURL.Parse(shift.depositAddress, out var lnurl); - return new LNURLPayClaimDestinaton(shift.depositAddress); - } - catch (Exception e) - { - if (BOLT11PaymentRequest.TryParse(shift.depositAddress, out var bolt11, network.NBitcoinNetwork)) - { - return new BoltInvoiceClaimDestination(shift.depositAddress, bolt11); - } - } - - return null; - - } - } - - public class SideShiftAvailableCoin - { - public string coin { get; set; } - public string[] networks { get; set; } - public string name { get; set; } - public bool hasMemo { get; set; } - public JToken fixedOnly { get; set; } - public JToken variableOnly { get; set; } - public JToken settleOffline { get; set; } - } } \ No newline at end of file diff --git a/Plugins/BTCPayServer.Plugins.SideShift/Views/Shared/SideShift/PrismEnhance.cshtml b/Plugins/BTCPayServer.Plugins.SideShift/Views/Shared/SideShift/PrismEnhance.cshtml index e25f4f4..a246d77 100644 --- a/Plugins/BTCPayServer.Plugins.SideShift/Views/Shared/SideShift/PrismEnhance.cshtml +++ b/Plugins/BTCPayServer.Plugins.SideShift/Views/Shared/SideShift/PrismEnhance.cshtml @@ -11,7 +11,6 @@ return; } } -