Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
gruve-p committed Oct 30, 2024
2 parents f22e373 + 5ad0b12 commit 46aebf1
Show file tree
Hide file tree
Showing 18 changed files with 182 additions and 89 deletions.
12 changes: 1 addition & 11 deletions BTCPayServer.Tests/AltcoinTests/ElementsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,23 +63,17 @@ public async Task ElementsAssetsAreHandledCorrectly()
//no tether on our regtest, lets create it and set it
var tether = tester.NetworkProvider.GetNetwork<ElementsBTCPayNetwork>("USDT");
var lbtc = tester.NetworkProvider.GetNetwork<ElementsBTCPayNetwork>("LBTC");
var etb = tester.NetworkProvider.GetNetwork<ElementsBTCPayNetwork>("ETB");
var issueAssetResult = await tester.LBTCExplorerNode.SendCommandAsync("issueasset", 100000, 0);
tether.AssetId = uint256.Parse(issueAssetResult.Result["asset"].ToString());
((ElementsBTCPayNetwork)tester.PayTester.GetService<BTCPayWalletProvider>().GetWallet("USDT").Network)
.AssetId = tether.AssetId;
Assert.Equal(tether.AssetId, tester.NetworkProvider.GetNetwork<ElementsBTCPayNetwork>("USDT").AssetId);
Assert.Equal(tether.AssetId, ((ElementsBTCPayNetwork)tester.PayTester.GetService<BTCPayWalletProvider>().GetWallet("USDT").Network).AssetId);

var issueAssetResult2 = await tester.LBTCExplorerNode.SendCommandAsync("issueasset", 100000, 0);
etb.AssetId = uint256.Parse(issueAssetResult2.Result["asset"].ToString());
((ElementsBTCPayNetwork)tester.PayTester.GetService<BTCPayWalletProvider>().GetWallet("ETB").Network)
.AssetId = etb.AssetId;


user.RegisterDerivationScheme("LBTC");
user.RegisterDerivationScheme("USDT");
user.RegisterDerivationScheme("ETB");

//test: register 2 assets on the same elements network and make sure paying an invoice on one does not affect the other in any way
var invoice = await user.BitPay.CreateInvoiceAsync(new Invoice(0.1m, "BTC"));
Expand Down Expand Up @@ -109,11 +103,7 @@ public async Task ElementsAssetsAreHandledCorrectly()
Assert.Equal("paid", localInvoice.Status);
Assert.Single(localInvoice.CryptoInfo.Single(info => info.CryptoCode.Equals("USDT", StringComparison.InvariantCultureIgnoreCase)).Payments);
});

//test precision based on https://github.com/ElementsProject/elements/issues/805#issuecomment-601277606
var etbBip21 = new BitcoinUrlBuilder(invoice.CryptoInfo.Single(info => info.CryptoCode == "ETB").PaymentUrls.BIP21, etb.NBitcoinNetwork);
//precision = 2, 1ETB = 0.00000100
Assert.Equal(100, etbBip21.Amount.Satoshi);


var lbtcBip21 = new BitcoinUrlBuilder(invoice.CryptoInfo.Single(info => info.CryptoCode == "LBTC").PaymentUrls.BIP21, lbtc.NBitcoinNetwork);
//precision = 8, 0.1 = 0.1
Expand Down
11 changes: 8 additions & 3 deletions BTCPayServer/Components/MainNav/Default.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,14 @@
</li>
@if (ViewData.IsCategoryActive(typeof(WalletsNavPages), scheme.WalletId.ToString()) || ViewData.IsPageActive([WalletsNavPages.Settings], scheme.WalletId.ToString()) || ViewData.IsPageActive([StoreNavPages.OnchainSettings], categoryId))
{
<li class="nav-item nav-item-sub">
<a id="WalletNav-Send" class="nav-link @ViewData.ActivePageClass([WalletsNavPages.Send, WalletsNavPages.PSBT], scheme.WalletId.ToString())" asp-area="" asp-controller="UIWallets" asp-action="WalletSend" asp-route-walletId="@scheme.WalletId" text-translate="true">Send</a>
</li>
@if (!scheme.ReadonlyWallet)
{
<li class="nav-item nav-item-sub">
<a id="WalletNav-Send" class="nav-link @ViewData.ActivePageClass([WalletsNavPages.Send, WalletsNavPages.PSBT], scheme.WalletId.ToString())" asp-area="" asp-controller="UIWallets" asp-action="WalletSend" asp-route-walletId="@scheme.WalletId" text-translate="true">Send</a>
</li>
}


<li class="nav-item nav-item-sub">
<a id="WalletNav-Receive" class="nav-link @ViewData.ActivePageClass(WalletsNavPages.Receive, scheme.WalletId.ToString())" asp-area="" asp-controller="UIWallets" asp-action="WalletReceive" asp-route-walletId="@scheme.WalletId" text-translate="true">Receive</a>
</li>
Expand Down
18 changes: 14 additions & 4 deletions BTCPayServer/Controllers/UIServerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1275,7 +1275,7 @@ public async Task<IActionResult> Emails(ServerEmailsViewModel model, string comm
}

[Route("server/logs/{file?}")]
public async Task<IActionResult> LogsView(string? file = null, int offset = 0)
public async Task<IActionResult> LogsView(string? file = null, int offset = 0, bool download = false)
{
if (offset < 0)
{
Expand Down Expand Up @@ -1317,13 +1317,23 @@ public async Task<IActionResult> LogsView(string? file = null, int offset = 0)
return NotFound();
try
{
using var fileStream = new FileStream(
var fileStream = new FileStream(
fi.FullName,
FileMode.Open,
FileAccess.Read,
FileShare.ReadWrite);
using var reader = new StreamReader(fileStream);
vm.Log = await reader.ReadToEndAsync();
if (download)
{
return new FileStreamResult(fileStream, "text/plain")
{
FileDownloadName = file
};
}
await using (fileStream)
{
using var reader = new StreamReader(fileStream);
vm.Log = await reader.ReadToEndAsync();
}
}
catch
{
Expand Down
1 change: 1 addition & 0 deletions BTCPayServer/Controllers/UIStoresController.Dashboard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ internal void AddPaymentMethods(StoreData store, StoreBlob storeBlob,
Crypto = network.CryptoCode,
PaymentMethodId = handler.PaymentMethodId,
WalletSupported = network.WalletSupported,
ReadonlyWallet = network.ReadonlyWallet,
Value = value,
WalletId = new WalletId(store.Id, network.CryptoCode),
Enabled = !excludeFilters.Match(handler.PaymentMethodId) && strategy != null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class StoreDerivationScheme
public string Value { get; set; }
public WalletId WalletId { get; set; }
public bool WalletSupported { get; set; }
public bool ReadonlyWallet { get; set; }
public bool Enabled { get; set; }
public bool Collapsed { get; set; }
}
Expand Down
29 changes: 20 additions & 9 deletions BTCPayServer/Payments/Lightning/LightningPendingPayoutListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using BTCPayServer.Services.Stores;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Newtonsoft.Json.Linq;
using PayoutData = BTCPayServer.Data.PayoutData;
using StoreData = BTCPayServer.Data.StoreData;

Expand All @@ -21,7 +22,6 @@ namespace BTCPayServer.Payments.Lightning;
public class LightningPendingPayoutListener : BaseAsyncService
{
private readonly LightningClientFactoryService _lightningClientFactoryService;
private readonly ApplicationDbContextFactory _applicationDbContextFactory;
private readonly PullPaymentHostedService _pullPaymentHostedService;
private readonly StoreRepository _storeRepository;
private readonly IOptions<LightningNetworkOptions> _options;
Expand All @@ -32,7 +32,6 @@ public class LightningPendingPayoutListener : BaseAsyncService

public LightningPendingPayoutListener(
LightningClientFactoryService lightningClientFactoryService,
ApplicationDbContextFactory applicationDbContextFactory,
PullPaymentHostedService pullPaymentHostedService,
StoreRepository storeRepository,
IOptions<LightningNetworkOptions> options,
Expand All @@ -42,7 +41,6 @@ public LightningPendingPayoutListener(
ILogger<LightningPendingPayoutListener> logger) : base(logger)
{
_lightningClientFactoryService = lightningClientFactoryService;
_applicationDbContextFactory = applicationDbContextFactory;
_pullPaymentHostedService = pullPaymentHostedService;
_storeRepository = storeRepository;
_options = options;
Expand All @@ -54,19 +52,18 @@ public LightningPendingPayoutListener(

private async Task Act()
{
await using var context = _applicationDbContextFactory.CreateContext();
var networks = _networkProvider.GetAll()
.OfType<BTCPayNetwork>()
.Where(network => network.SupportLightning)
.ToDictionary(network => PaymentTypes.LN.GetPaymentMethodId(network.CryptoCode));


var payouts = await PullPaymentHostedService.GetPayouts(
var payouts = await _pullPaymentHostedService.GetPayouts(
new PullPaymentHostedService.PayoutQuery()
{
States = new PayoutState[] { PayoutState.InProgress },
PayoutMethods = networks.Keys.Select(id => id.ToString()).ToArray()
}, context);
});
var storeIds = payouts.Select(data => data.StoreDataId).Distinct();
var stores = (await Task.WhenAll(storeIds.Select(_storeRepository.FindStore)))
.Where(data => data is not null).ToDictionary(data => data.Id, data => (StoreData)data);
Expand All @@ -83,9 +80,7 @@ private async Task Act()
.Select(c => (LightningPaymentMethodConfig)c.Value)
.FirstOrDefault();
if (pm is null)
{
continue;
}

var client =
pm.CreateLightningClient(networks[pmi], _options.Value, _lightningClientFactoryService);
Expand All @@ -94,6 +89,9 @@ private async Task Act()
var handler = _payoutHandlers.TryGet(payoutData.GetPayoutMethodId()) as LightningLikePayoutHandler;
if (handler is null || handler.PayoutsPaymentProcessing.Contains(payoutData.Id))
continue;
using var track = handler.PayoutsPaymentProcessing.StartTracking();
if (!track.TryTrack(payoutData.Id))
continue;
var proof = handler.ParseProof(payoutData) as PayoutLightningBlob;

LightningPayment payment = null;
Expand Down Expand Up @@ -122,10 +120,23 @@ private async Task Act()
break;
}
}

foreach (PayoutData payoutData in payoutByStoreByPaymentMethod)
{
if (payoutData.State != PayoutState.InProgress)
{
// This update can fail if the payout has been updated in the meantime
await _pullPaymentHostedService.MarkPaid(new HostedServices.MarkPayoutRequest()
{
PayoutId = payoutData.Id,
State = payoutData.State,
Proof = payoutData.State is PayoutState.Completed ? JObject.Parse(payoutData.Proof) : null
});
}
}
}
}

await context.SaveChangesAsync(CancellationToken);
await Task.Delay(TimeSpan.FromSeconds(SecondsDelay), CancellationToken);
}

Expand Down
1 change: 0 additions & 1 deletion BTCPayServer/Payments/PaymentMethodId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ public override string ToString()
"XMR",
"ZEC",
"LCAD",
"ETB",
"LBTC",
"USDt",
"MONA",
Expand Down
12 changes: 0 additions & 12 deletions BTCPayServer/Plugins/Altcoins/AltcoinsPlugin.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using BTCPayServer.Abstractions.Models;
using BTCPayServer.Hosting;
using BTCPayServer.Logging;
using Microsoft.AspNetCore.HttpOverrides;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using NBitcoin;
using NBitcoin.Protocol;
using NBXplorer;

namespace BTCPayServer.Plugins.Altcoins
Expand Down Expand Up @@ -37,15 +28,12 @@ public override void Execute(IServiceCollection applicationBuilder)
{
// Activating LBTC automatically activate the other liquid assets
InitUSDT(services, selectedChains, liquidNBX);
InitETB(services, selectedChains, liquidNBX);
InitLCAD(services, selectedChains, liquidNBX);
}
else
{
if (selectedChains.Contains("USDT"))
InitUSDT(services, selectedChains, liquidNBX);
if (selectedChains.Contains("ETB"))
InitETB(services, selectedChains, liquidNBX);
if (selectedChains.Contains("LCAD"))
InitLCAD(services, selectedChains, liquidNBX);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ public void InitLiquid(IServiceCollection services, NBXplorer.NBXplorerNetwork n
CryptoImagePath = "imlegacy/liquid.png",
DefaultSettings = BTCPayDefaultSettings.GetDefaultSettings(ChainName),
CoinType = ChainName == ChainName.Mainnet ? new KeyPath("1776'") : new KeyPath("1'"),
SupportRBF = true
SupportRBF = true,
SupportLightning = false,
SupportPayJoin = false,
VaultSupported = false,
ReadonlyWallet = true
}.SetDefaultElectrumMapping(ChainName);

var blockExplorerLink = ChainName == ChainName.Mainnet ? "https://liquid.network/tx/{0}" : "https://liquid.network/testnet/tx/{0}";
Expand Down
45 changes: 11 additions & 34 deletions BTCPayServer/Plugins/Altcoins/Liquid/AltcoinsPlugin.LiquidAssets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,13 @@ private void InitUSDT(IServiceCollection services, SelectedChains selectedChains
DefaultSettings = BTCPayDefaultSettings.GetDefaultSettings(ChainName),
CoinType = ChainName == ChainName.Mainnet ? new KeyPath("1776'") : new KeyPath("1'"),
SupportRBF = true,
SupportLightning = false
SupportLightning = false,
SupportPayJoin = false,
VaultSupported = false,
ReadonlyWallet = true
}.SetDefaultElectrumMapping(ChainName);
services.AddBTCPayNetwork(network)
.AddTransactionLinkProvider(PaymentTypes.CHAIN.GetPaymentMethodId(nbxplorerNetwork.CryptoCode), new DefaultTransactionLinkProvider(LiquidBlockExplorer));
.AddTransactionLinkProvider(PaymentTypes.CHAIN.GetPaymentMethodId("USDt"), new DefaultTransactionLinkProvider(LiquidBlockExplorer));
services.AddCurrencyData(new CurrencyData()
{
Code = "USDt",
Expand All @@ -45,35 +48,6 @@ private void InitUSDT(IServiceCollection services, SelectedChains selectedChains
selectedChains.Add("LBTC");
}

private void InitETB(IServiceCollection services, SelectedChains selectedChains, NBXplorer.NBXplorerNetwork nbxplorerNetwork)
{
var network = new ElementsBTCPayNetwork()
{
CryptoCode = "ETB",
NetworkCryptoCode = "LBTC",
ShowSyncSummary = false,
DefaultRateRules = new[]
{

"ETB_X = ETB_BTC * BTC_X",
"ETB_BTC = bitpay(ETB_BTC)"
},
Divisibility = 2,
AssetId = new uint256("aa775044c32a7df391902b3659f46dfe004ccb2644ce2ddc7dba31e889391caf"),
DisplayName = "Ethiopian Birr",
NBXplorerNetwork = nbxplorerNetwork,
CryptoImagePath = "imlegacy/etb.png",
DefaultSettings = BTCPayDefaultSettings.GetDefaultSettings(ChainName),
CoinType = ChainName == ChainName.Mainnet ? new KeyPath("1776'") : new KeyPath("1'"),
SupportRBF = true,
SupportLightning = false
}.SetDefaultElectrumMapping(ChainName);

services.AddBTCPayNetwork(network)
.AddTransactionLinkProvider(PaymentTypes.CHAIN.GetPaymentMethodId(nbxplorerNetwork.CryptoCode), new DefaultTransactionLinkProvider(LiquidBlockExplorer));
selectedChains.Add("LBTC");
}

string LiquidBlockExplorer => ChainName == ChainName.Mainnet ? "https://liquid.network/tx/{0}" : "https://liquid.network/testnet/tx/{0}";
private void InitLCAD(IServiceCollection services, SelectedChains selectedChains, NBXplorer.NBXplorerNetwork nbxplorerNetwork)
{
Expand All @@ -95,11 +69,14 @@ private void InitLCAD(IServiceCollection services, SelectedChains selectedChains
CryptoImagePath = "imlegacy/lcad.png",
DefaultSettings = BTCPayDefaultSettings.GetDefaultSettings(ChainName),
CoinType = ChainName == ChainName.Mainnet ? new KeyPath("1776'") : new KeyPath("1'"),
SupportRBF = true,
SupportLightning = false
SupportRBF = true,
SupportLightning = false,
SupportPayJoin = false,
VaultSupported = false,
ReadonlyWallet = true
}.SetDefaultElectrumMapping(ChainName);
services.AddBTCPayNetwork(network)
.AddTransactionLinkProvider(PaymentTypes.CHAIN.GetPaymentMethodId(nbxplorerNetwork.CryptoCode), new DefaultTransactionLinkProvider(LiquidBlockExplorer));
.AddTransactionLinkProvider(PaymentTypes.CHAIN.GetPaymentMethodId("LCAD"), new DefaultTransactionLinkProvider(LiquidBlockExplorer));
selectedChains.Add("LBTC");
}

Expand Down
2 changes: 1 addition & 1 deletion BTCPayServer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ static async Task Main(string[] args)
}
catch (Exception e) when (PluginManager.IsExceptionByPlugin(e, out var pluginName))
{
logs.Configuration.LogError(e, $"Disabling plugin {pluginName} as it crashed on startup");
logs.Configuration.LogError(e, $"Plugin crash during startup detected, disabling {pluginName}...");
var pluginDir = new DataDirectories().Configure(conf).PluginDir;
PluginManager.DisablePlugin(pluginDir, pluginName);
}
Expand Down
6 changes: 5 additions & 1 deletion BTCPayServer/Views/Shared/PointOfSale/Public/VueLight.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@
</template>
</div>
<div class="keypad">
<button v-for="k in keys" :key="k" :disabled="k === '+' && mode !== 'amounts'" v-on:click.prevent="keyPressed(k)" v-on:dblclick.prevent="doubleClick(k)" type="button" class="btn btn-secondary btn-lg" :data-key="k">{{ k }}</button>
<button v-for="k in keys" :key="k" :disabled="k === '+' && mode !== 'amounts'" v-on:click.prevent="keyPressed(k)" v-on:dblclick.prevent="doubleClick(k)" type="button" class="btn btn-secondary btn-lg" :data-key="k">
<template v-if="k === 'C'"><vc:icon symbol="keypad-clear"/></template>
<template v-else-if="k === '+'"><vc:icon symbol="keypad-plus"/></template>
<template v-else>{{ k }}</template>
</button>
</div>
<button class="btn btn-lg btn-primary mx-3" type="submit" :disabled="payButtonLoading || totalNumeric <= 0" id="pay-button">
<div v-if="payButtonLoading" class="spinner-border spinner-border-sm" id="pay-button-spinner" role="status">
Expand Down
5 changes: 4 additions & 1 deletion BTCPayServer/Views/UIServer/Logs.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
@foreach (var file in Model.LogFiles)
{
<li>
<a asp-action="LogsView" asp-route-file="@file.Name">@file.Name</a>
<a asp-action="LogsView" asp-route-file="@file.Name" asp-route-offset="@Model.LogFileOffset">@file.Name</a>
<a asp-action="LogsView" asp-route-file="@file.Name" asp-route-offset="@Model.LogFileOffset" asp-route-download="true" class="mx-2">
<vc:icon symbol="actions-download" />
</a>
</li>
}
</ul>
Expand Down
Loading

0 comments on commit 46aebf1

Please sign in to comment.