-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
295 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.Extensions.Hosting; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace BTCPayServer.Plugins.Strike.Persistence; | ||
|
||
internal class StrikeDbContextMigrator : IHostedService | ||
{ | ||
private readonly StrikeDbContextFactory _dbContextFactory; | ||
private readonly ILogger<StrikeDbContextMigrator> _logger; | ||
|
||
public StrikeDbContextMigrator(StrikeDbContextFactory dbContextFactory, ILogger<StrikeDbContextMigrator> logger) | ||
{ | ||
_dbContextFactory = dbContextFactory; | ||
_logger = logger; | ||
} | ||
|
||
public async Task StartAsync(CancellationToken cancellationToken) | ||
{ | ||
try | ||
{ | ||
_logger.LogDebug("Migrating Strike database"); | ||
await using var ctx = _dbContextFactory.CreateContext(); | ||
await using var dbContext = _dbContextFactory.CreateContext(); | ||
await ctx.Database.MigrateAsync(cancellationToken); | ||
} | ||
catch (Exception e) | ||
{ | ||
_logger.LogError(e, "Error while migrating Strike database: {error}", e.Message); | ||
} | ||
} | ||
|
||
public Task StopAsync(CancellationToken cancellationToken) | ||
{ | ||
return Task.CompletedTask; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
using System.Linq; | ||
using BTCPayServer.Abstractions.Constants; | ||
using BTCPayServer.Client; | ||
using BTCPayServer.Data; | ||
using BTCPayServer.Payments; | ||
using BTCPayServer.Payments.Lightning; | ||
using BTCPayServer.Services.Stores; | ||
using BTCPayServer.Services.Wallets; | ||
using Microsoft.AspNetCore.Authorization; | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace BTCPayServer.Plugins.Strike; | ||
|
||
[Authorize(AuthenticationSchemes = AuthenticationSchemes.Cookie)] | ||
[Route("plugins/{storeId}/strike")] | ||
public class StrikeController : Controller | ||
{ | ||
private readonly BTCPayNetworkProvider _btcPayNetworkProvider; | ||
private readonly BTCPayWalletProvider _btcWalletProvider; | ||
private readonly StoreRepository _storeRepository; | ||
|
||
public StrikeController(BTCPayNetworkProvider btcPayNetworkProvider, | ||
BTCPayWalletProvider btcWalletProvider, StoreRepository storeRepository) | ||
{ | ||
_btcPayNetworkProvider = btcPayNetworkProvider; | ||
_btcWalletProvider = btcWalletProvider; | ||
_storeRepository = storeRepository; | ||
} | ||
|
||
|
||
[HttpGet("")] | ||
public IActionResult Index(string storeId) | ||
{ | ||
return RedirectToAction(nameof(Dashboard), new {storeId}); | ||
} | ||
|
||
[HttpGet("dashboard")] | ||
[Authorize(Policy = Policies.CanViewStoreSettings, AuthenticationSchemes = AuthenticationSchemes.Cookie)] | ||
public IActionResult Dashboard(string storeId) | ||
{ | ||
return View((object)storeId); | ||
} | ||
|
||
[Authorize(Policy = Policies.CanModifyStoreSettings, AuthenticationSchemes = AuthenticationSchemes.Cookie)] | ||
[HttpGet("configure")] | ||
public IActionResult Configure(string storeId) | ||
{ | ||
return View(); | ||
} | ||
|
||
[HttpPost("configure")] | ||
[Authorize(Policy = Policies.CanModifyStoreSettings, AuthenticationSchemes = AuthenticationSchemes.Cookie)] | ||
public IActionResult Configure(string storeId, string command, string settings) | ||
{ | ||
var store = HttpContext.GetStoreData(); | ||
var existing = store.GetSupportedPaymentMethods(_btcPayNetworkProvider).OfType<LightningSupportedPaymentMethod>() | ||
.FirstOrDefault(method => | ||
method.PaymentId.PaymentType == LightningPaymentType.Instance && | ||
method.PaymentId.CryptoCode == "BTC"); | ||
|
||
// if (command == "clear") | ||
// { | ||
// await _breezService.Set(storeId, null); | ||
// TempData[WellKnownTempData.SuccessMessage] = "Settings cleared successfully"; | ||
// var client = _breezService.GetClient(storeId); | ||
// var isStoreSetToThisMicro = existing?.GetExternalLightningUrl() == client?.ToString(); | ||
// if (client is not null && isStoreSetToThisMicro) | ||
// { | ||
// store.SetSupportedPaymentMethod(existing.PaymentId, null); | ||
// await _storeRepository.UpdateStore(store); | ||
// } | ||
// return RedirectToAction(nameof(Configure), new {storeId}); | ||
// } | ||
// | ||
// if (command == "save") | ||
// { | ||
// | ||
// try | ||
// { | ||
// if (string.IsNullOrEmpty(settings.Mnemonic)) | ||
// { | ||
// ModelState.AddModelError(nameof(settings.Mnemonic), "Mnemonic is required"); | ||
// return View(settings); | ||
// } | ||
// else | ||
// { | ||
// try | ||
// { | ||
// new Mnemonic(settings.Mnemonic); | ||
// } | ||
// catch (Exception e) | ||
// { | ||
// ModelState.AddModelError(nameof(settings.Mnemonic), "Invalid mnemonic"); | ||
// return View(settings); | ||
// } | ||
// } | ||
// | ||
// if (settings.GreenlightCredentials is not null) | ||
// { | ||
// await using var stream = settings.GreenlightCredentials .OpenReadStream(); | ||
// using var archive = new ZipArchive(stream); | ||
// var deviceClientArchiveEntry = archive.GetEntry("client.crt"); | ||
// var deviceKeyArchiveEntry = archive.GetEntry("client-key.pem"); | ||
// if(deviceClientArchiveEntry is null || deviceKeyArchiveEntry is null) | ||
// { | ||
// ModelState.AddModelError(nameof(settings.GreenlightCredentials), "Invalid zip file (does not have client.crt or client-key.pem)"); | ||
// return View(settings); | ||
// } | ||
// else | ||
// { | ||
// var deviceClient = await ReadAsByteArrayAsync(deviceClientArchiveEntry.Open()); | ||
// var deviceKey = await ReadAsByteArrayAsync(deviceKeyArchiveEntry.Open()); | ||
// var dir = _breezService.GetWorkDir(storeId); | ||
// Directory.CreateDirectory(dir); | ||
// await System.IO.File.WriteAllBytesAsync(Path.Combine(dir, "client.crt"), deviceClient); | ||
// await System.IO.File.WriteAllBytesAsync(Path.Combine(dir, "client-key.pem"), deviceKey); | ||
// | ||
// await _breezService.Set(storeId, settings); | ||
// } | ||
// | ||
// } | ||
// else | ||
// { | ||
// | ||
// await _breezService.Set(storeId, settings); | ||
// } | ||
// } | ||
// catch (Exception e) | ||
// { | ||
// TempData[WellKnownTempData.ErrorMessage] = $"Couldnt use provided settings: {e.Message}"; | ||
// return View(settings); | ||
// } | ||
// | ||
// if(existing is null) | ||
// { | ||
// existing = new LightningSupportedPaymentMethod() | ||
// { | ||
// CryptoCode = "BTC" | ||
// }; | ||
// var client = _breezService.GetClient(storeId); | ||
// existing.SetLightningUrl(client); | ||
// store.SetSupportedPaymentMethod(existing); | ||
// var lnurl = new LNURLPaySupportedPaymentMethod() | ||
// { | ||
// CryptoCode = "BTC", | ||
// }; | ||
// store.SetSupportedPaymentMethod(lnurl); | ||
// await _storeRepository.UpdateStore(store); | ||
// } | ||
// | ||
// TempData[WellKnownTempData.SuccessMessage] = "Settings saved successfully"; | ||
// return RedirectToAction(nameof(Info), new {storeId}); | ||
// } | ||
//return NotFound(); | ||
|
||
return RedirectToAction(nameof(Configure), new {storeId}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
@using BTCPayServer.Abstractions.Contracts | ||
@using BTCPayServer.Client | ||
@using Microsoft.AspNetCore.Mvc.TagHelpers | ||
@inject IScopeProvider ScopeProvider | ||
@{ | ||
var storeId = ScopeProvider.GetCurrentStoreId(); | ||
} | ||
@if (!string.IsNullOrEmpty(storeId)) | ||
{ | ||
<li class="nav-item"> | ||
<a permission="@Policies.CanViewStoreSettings" asp-controller="Strike" asp-action="Index" asp-route-storeId="@storeId" class="nav-link @ViewData.IsActivePage("Strike")" id="Nav-Strike"> | ||
<svg style="width: 20px; margin-left: 1px; margin-right: 7px;" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" data-theme="dark" focusable="false"> | ||
<path fill-rule="evenodd" clip-rule="evenodd" d="M3.31317 8.49362C2.82011 8.30435 2.57384 7.75121 2.76311 7.25815C2.95238 6.76509 3.50552 6.51881 3.99858 6.70808L7.55779 8.07434C7.56174 8.07591 7.5657 8.07746 7.56967 8.07899L9.35521 8.76439C9.84827 8.95366 10.4014 8.70738 10.5907 8.21432C10.7799 7.72126 10.5337 7.16812 10.0406 6.97885L10.0404 6.97877C10.0405 6.97874 10.0405 6.9787 10.0406 6.97866L8.25506 6.29326C7.762 6.104 7.51572 5.55086 7.70499 5.0578C7.89426 4.56473 8.4474 4.31846 8.94046 4.50773L14.1921 6.52363C14.2046 6.52845 14.217 6.53352 14.2293 6.53881C14.2519 6.54711 14.2745 6.55559 14.2971 6.56425C16.7624 7.5106 17.9938 10.2763 17.0474 12.7416C16.1011 15.2069 13.3354 16.4383 10.8701 15.4919C10.8226 15.4737 10.7756 15.4548 10.729 15.4353C10.7065 15.4285 10.684 15.4208 10.6616 15.4122L5.51344 13.436C5.02038 13.2467 4.77411 12.6936 4.96338 12.2005C5.15265 11.7075 5.70579 11.4612 6.19885 11.6504L7.98415 12.3358C7.98411 12.3356 7.98407 12.3355 7.98403 12.3354L7.9844 12.3355C8.47746 12.5248 9.0306 12.2785 9.21987 11.7854C9.40914 11.2924 9.16287 10.7392 8.66981 10.55L7.86633 10.2416C7.86634 10.2415 7.86634 10.2415 7.86635 10.2414L3.31317 8.49362Z" fill="currentColor"></path> | ||
</svg> | ||
<span>Strike</span> | ||
</a> | ||
</li> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
@using BTCPayServer | ||
@{ | ||
ViewData.SetActivePage("Strike", "Configure", "Configure"); | ||
var storeId = Context.GetCurrentStoreId(); | ||
} | ||
<form method="post" asp-action="Configure" asp-controller="Strike" asp-route-storeId="@storeId" enctype="multipart/form-data"> | ||
<div class="row mb-4"> | ||
<div class="col-12"> | ||
<div class="d-flex align-items-center justify-content-between mb-3"> | ||
<h3 class="mb-0"> | ||
<span>@ViewData["Title"]</span> | ||
</h3> | ||
<div class="d-flex gap-3 mt-3 mt-sm-0"> | ||
<button name="command" type="submit" value="save" class="btn btn-primary">Save</button> | ||
@* @if (active) *@ | ||
@* { *@ | ||
@* <button name="command" type="submit" value="clear" class="btn btn-danger">Clear</button> *@ | ||
@* } *@ | ||
</div> | ||
</div> | ||
|
||
</div> | ||
</div> | ||
</form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
@using BTCPayServer.Models.StoreViewModels | ||
@using BTCPayServer.Security | ||
@model object | ||
@{ | ||
var storeId = Model switch | ||
{ | ||
string s => s, | ||
StoreDashboardViewModel dashboardModel => dashboardModel.StoreId, | ||
_ => Context.GetImplicitStoreId() | ||
}; | ||
ViewData.SetActivePage("Strike", "Strike Dashboard", "Dashboard"); | ||
} | ||
|
||
<h3>Dashboard</h3> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
@{ | ||
Layout = "../Shared/_NavLayout.cshtml"; | ||
ViewData["NavPartialName"] = "_Nav"; | ||
} | ||
<style> | ||
#mainContent > section { | ||
padding: 3rem !important; | ||
} | ||
</style> | ||
|
||
@RenderBody() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
@using BTCPayServer.Client | ||
@using BTCPayServer.Models.StoreViewModels | ||
@using BTCPayServer.Security | ||
@using Microsoft.AspNetCore.Mvc.TagHelpers | ||
|
||
@{ | ||
var storeId = Model switch | ||
{ | ||
string s => s, | ||
StoreDashboardViewModel dashboardModel => dashboardModel.StoreId, | ||
_ => Context.GetImplicitStoreId() | ||
}; | ||
} | ||
|
||
<div class="sticky-header-setup"></div> | ||
<div class="sticky-header mb-xl"> | ||
<h2 class="mt-1 mb-2 mb-lg-4">Strike</h2> | ||
<nav id="SectionNav"> | ||
<div class="nav"> | ||
<a permission="@Policies.CanViewStoreSettings" asp-action="Dashboard" asp-route-storeId="@storeId" class="nav-link @ViewData.IsActivePage("Strike", null, "Dashboard")">Dashboard</a> | ||
<a permission="@Policies.CanModifyStoreSettings" asp-action="Configure" asp-route-storeId="@storeId" class="nav-link @ViewData.IsActivePage("Strike", null, "Configure")">Configuration</a> | ||
</div> | ||
</nav> | ||
</div> |
Submodule btcpayserver
updated
836 files