From 5e7eb6635f758248880337f1a544ecdaf9e85f7b Mon Sep 17 00:00:00 2001 From: rockstardev Date: Mon, 1 Mar 2021 09:33:02 -0600 Subject: [PATCH 1/2] Initializing NextNetworkFee values if GetFee returns null --- BTCPayServer/Payments/Bitcoin/BitcoinLikePaymentHandler.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/BTCPayServer/Payments/Bitcoin/BitcoinLikePaymentHandler.cs b/BTCPayServer/Payments/Bitcoin/BitcoinLikePaymentHandler.cs index 30ccc8374..e5b81aaff 100644 --- a/BTCPayServer/Payments/Bitcoin/BitcoinLikePaymentHandler.cs +++ b/BTCPayServer/Payments/Bitcoin/BitcoinLikePaymentHandler.cs @@ -154,6 +154,8 @@ namespace BTCPayServer.Payments.Bitcoin onchainMethod.NetworkFeeRate = (await prepare.GetNetworkFeeRate); onchainMethod.NextNetworkFee = onchainMethod.NetworkFeeRate.GetFee(100); // assume price for 100 bytes + if (onchainMethod.NextNetworkFee == null) + onchainMethod.NextNetworkFee = Money.Zero; break; case NetworkFeeMode.Never: onchainMethod.NetworkFeeRate = FeeRate.Zero; From e65e46f6644b11250c1cbf6dd68265b164f90919 Mon Sep 17 00:00:00 2001 From: rockstardev Date: Mon, 1 Mar 2021 09:56:57 -0600 Subject: [PATCH 2/2] NextNetworkFee is not directly initialized, falling back to null check --- .../Payments/Bitcoin/BitcoinLikeOnChainPaymentMethod.cs | 3 ++- .../Payments/Bitcoin/BitcoinLikePaymentHandler.cs | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/BTCPayServer/Payments/Bitcoin/BitcoinLikeOnChainPaymentMethod.cs b/BTCPayServer/Payments/Bitcoin/BitcoinLikeOnChainPaymentMethod.cs index ee10290ce..cbd7cab9c 100644 --- a/BTCPayServer/Payments/Bitcoin/BitcoinLikeOnChainPaymentMethod.cs +++ b/BTCPayServer/Payments/Bitcoin/BitcoinLikeOnChainPaymentMethod.cs @@ -17,7 +17,8 @@ namespace BTCPayServer.Payments.Bitcoin public decimal GetNextNetworkFee() { - return NextNetworkFee.ToDecimal(MoneyUnit.BTC); + // NextNetworkFee is sometimes not initialized properly, so we return 0 in that case + return NextNetworkFee?.ToDecimal(MoneyUnit.BTC) ?? 0; } public decimal GetFeeRate() diff --git a/BTCPayServer/Payments/Bitcoin/BitcoinLikePaymentHandler.cs b/BTCPayServer/Payments/Bitcoin/BitcoinLikePaymentHandler.cs index e5b81aaff..88b001ff6 100644 --- a/BTCPayServer/Payments/Bitcoin/BitcoinLikePaymentHandler.cs +++ b/BTCPayServer/Payments/Bitcoin/BitcoinLikePaymentHandler.cs @@ -143,9 +143,11 @@ namespace BTCPayServer.Payments.Bitcoin if (!_ExplorerProvider.IsAvailable(network)) throw new PaymentMethodUnavailableException($"Full node not available"); var prepare = (Prepare)preparePaymentObject; - Payments.Bitcoin.BitcoinLikeOnChainPaymentMethod onchainMethod = - new Payments.Bitcoin.BitcoinLikeOnChainPaymentMethod(); + var onchainMethod = new BitcoinLikeOnChainPaymentMethod(); var blob = store.GetStoreBlob(); + + // TODO: this needs to be refactored to move this logic into BitcoinLikeOnChainPaymentMethod + // This is likely a constructor code onchainMethod.NetworkFeeMode = blob.NetworkFeeMode; onchainMethod.FeeRate = await prepare.GetFeeRate; switch (onchainMethod.NetworkFeeMode) @@ -154,8 +156,6 @@ namespace BTCPayServer.Payments.Bitcoin onchainMethod.NetworkFeeRate = (await prepare.GetNetworkFeeRate); onchainMethod.NextNetworkFee = onchainMethod.NetworkFeeRate.GetFee(100); // assume price for 100 bytes - if (onchainMethod.NextNetworkFee == null) - onchainMethod.NextNetworkFee = Money.Zero; break; case NetworkFeeMode.Never: onchainMethod.NetworkFeeRate = FeeRate.Zero;