From b7f0ce18b3852379b03dac0ff42220dba7959b8f Mon Sep 17 00:00:00 2001 From: "nicolas.dorier" Date: Sat, 12 May 2018 00:23:25 +0900 Subject: [PATCH 1/2] Make sure Lightning charge can't hang out the payment --- BTCPayServer/Payments/Lightning/Charge/ChargeClient.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BTCPayServer/Payments/Lightning/Charge/ChargeClient.cs b/BTCPayServer/Payments/Lightning/Charge/ChargeClient.cs index 062f01bdc..121e6c001 100644 --- a/BTCPayServer/Payments/Lightning/Charge/ChargeClient.cs +++ b/BTCPayServer/Payments/Lightning/Charge/ChargeClient.cs @@ -156,7 +156,7 @@ namespace BTCPayServer.Payments.Lightning.Charge async Task ILightningInvoiceClient.CreateInvoice(LightMoney amount, string description, TimeSpan expiry, CancellationToken cancellation) { - var invoice = await CreateInvoiceAsync(new CreateInvoiceRequest() { Amount = amount, Expiry = expiry, Description = description ?? "" }); + var invoice = await CreateInvoiceAsync(new CreateInvoiceRequest() { Amount = amount, Expiry = expiry, Description = description ?? "" }, cancellation); return new LightningInvoice() { Id = invoice.Id, Amount = amount, BOLT11 = invoice.PayReq, Status = "unpaid" }; } From 26db946392927c3387cd9d263717f6fbf41bf054 Mon Sep 17 00:00:00 2001 From: "nicolas.dorier" Date: Sat, 12 May 2018 00:54:17 +0900 Subject: [PATCH 2/2] BTCPayRateProviderFactory is responsible for getting the supported exchange list --- BTCPayServer/Controllers/StoresController.cs | 7 ++----- .../Services/Rates/BTCPayRateProviderFactory.cs | 15 +++++++++++++++ .../Services/Rates/CoinAverageSettings.cs | 3 +-- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/BTCPayServer/Controllers/StoresController.cs b/BTCPayServer/Controllers/StoresController.cs index 410739b18..12b7cf005 100644 --- a/BTCPayServer/Controllers/StoresController.cs +++ b/BTCPayServer/Controllers/StoresController.cs @@ -53,8 +53,7 @@ namespace BTCPayServer.Controllers ExplorerClientProvider explorerProvider, IFeeProviderFactory feeRateProvider, LanguageService langService, - IHostingEnvironment env, - CoinAverageSettings coinAverage) + IHostingEnvironment env) { _RateFactory = rateFactory; _Dashboard = dashboard; @@ -72,9 +71,7 @@ namespace BTCPayServer.Controllers _ServiceProvider = serviceProvider; _BtcpayServerOptions = btcpayServerOptions; _BTCPayEnv = btcpayEnv; - _CoinAverage = coinAverage; } - CoinAverageSettings _CoinAverage; NBXplorerDashboard _Dashboard; BTCPayServerOptions _BtcpayServerOptions; BTCPayServerEnvironment _BTCPayEnv; @@ -518,7 +515,7 @@ namespace BTCPayServer.Controllers private CoinAverageExchange[] GetSupportedExchanges() { - return _CoinAverage.AvailableExchanges + return _RateFactory.GetSupportedExchanges() .Select(c => c.Value) .OrderBy(s => s.Name, StringComparer.OrdinalIgnoreCase) .ToArray(); diff --git a/BTCPayServer/Services/Rates/BTCPayRateProviderFactory.cs b/BTCPayServer/Services/Rates/BTCPayRateProviderFactory.cs index b115d1d30..4731195b7 100644 --- a/BTCPayServer/Services/Rates/BTCPayRateProviderFactory.cs +++ b/BTCPayServer/Services/Rates/BTCPayRateProviderFactory.cs @@ -2,6 +2,7 @@ using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; +using System.Net.Http; using System.Threading.Tasks; using BTCPayServer.Rating; using ExchangeSharp; @@ -74,6 +75,7 @@ namespace BTCPayServer.Services.Rates // Handmade providers DirectProviders.Add("bitpay", new BitpayRateProvider(new NBitpayClient.Bitpay(new NBitcoin.Key(), new Uri("https://bitpay.com/")))); DirectProviders.Add(QuadrigacxRateProvider.QuadrigacxName, new QuadrigacxRateProvider()); + DirectProviders.Add(CoinAverageRateProvider.CoinAverageName, new CoinAverageRateProvider() { Exchange = CoinAverageRateProvider.CoinAverageName, Authenticator = _CoinAverageSettings }); // Those exchanges make multiple requests when calling GetTickers so we remove them //DirectProviders.Add("kraken", new ExchangeSharpRateProvider("kraken", new ExchangeKrakenAPI(), true)); @@ -84,6 +86,19 @@ namespace BTCPayServer.Services.Rates //DirectProviders.Add("bitstamp", new ExchangeSharpRateProvider("bitstamp", new ExchangeBitstampAPI())); } + public CoinAverageExchanges GetSupportedExchanges() + { + CoinAverageExchanges exchanges = new CoinAverageExchanges(); + foreach(var exchange in _CoinAverageSettings.AvailableExchanges) + { + exchanges.Add(exchange.Value); + } + + // Add other exchanges supported here + exchanges.Add(new CoinAverageExchange(CoinAverageRateProvider.CoinAverageName, "Coin Average")); + + return exchanges; + } private readonly Dictionary _DirectProviders = new Dictionary(); public Dictionary DirectProviders diff --git a/BTCPayServer/Services/Rates/CoinAverageSettings.cs b/BTCPayServer/Services/Rates/CoinAverageSettings.cs index f3da666f6..9d0c06df2 100644 --- a/BTCPayServer/Services/Rates/CoinAverageSettings.cs +++ b/BTCPayServer/Services/Rates/CoinAverageSettings.cs @@ -43,12 +43,11 @@ namespace BTCPayServer.Services.Rates { public CoinAverageExchanges() { - Add(new CoinAverageExchange(CoinAverageRateProvider.CoinAverageName, "Coin Average")); } public void Add(CoinAverageExchange exchange) { - Add(exchange.Name, exchange); + TryAdd(exchange.Name, exchange); } } public class CoinAverageSettings : ICoinAverageAuthenticator