From d54a9474d16502500128f3e7e3d6ca11b5afacff Mon Sep 17 00:00:00 2001 From: "nicolas.dorier" Date: Sat, 13 Jan 2018 17:23:09 +0900 Subject: [PATCH] Fixing exception thrown when invoice is paid and supporting only LTC --- BTCPayServer.Tests/docker-compose.yml | 2 +- BTCPayServer/BTCPayServer.csproj | 2 +- .../Services/Invoices/InvoiceEntity.cs | 19 +++++++++++-------- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/BTCPayServer.Tests/docker-compose.yml b/BTCPayServer.Tests/docker-compose.yml index 51a05c4ab..bf5b0c9f5 100644 --- a/BTCPayServer.Tests/docker-compose.yml +++ b/BTCPayServer.Tests/docker-compose.yml @@ -37,7 +37,7 @@ services: - postgres nbxplorer: - image: nicolasdorier/nbxplorer:1.0.0.61 + image: nicolasdorier/nbxplorer:1.0.0.64 ports: - "32838:32838" expose: diff --git a/BTCPayServer/BTCPayServer.csproj b/BTCPayServer/BTCPayServer.csproj index b516b0281..b2c8b1932 100644 --- a/BTCPayServer/BTCPayServer.csproj +++ b/BTCPayServer/BTCPayServer.csproj @@ -2,7 +2,7 @@ Exe netcoreapp2.0 - 1.0.0.76 + 1.0.0.77 diff --git a/BTCPayServer/Services/Invoices/InvoiceEntity.cs b/BTCPayServer/Services/Invoices/InvoiceEntity.cs index 8c586309d..ddf16ee9d 100644 --- a/BTCPayServer/Services/Invoices/InvoiceEntity.cs +++ b/BTCPayServer/Services/Invoices/InvoiceEntity.cs @@ -369,8 +369,8 @@ namespace BTCPayServer.Services.Invoices dto.PaymentUrls = cryptoInfo.PaymentUrls; } #pragma warning restore CS0618 - - dto.CryptoInfo.Add(cryptoInfo); + if(!info.IsPhantomBTC) + dto.CryptoInfo.Add(cryptoInfo); } Populate(ProductInformation, dto); @@ -410,22 +410,22 @@ namespace BTCPayServer.Services.Invoices public Dictionary GetCryptoData(BTCPayNetworkProvider networkProvider, bool alwaysIncludeBTC = false) { Dictionary rates = new Dictionary(); - bool btcAdded = false; var serializer = new Serializer(Dummy); + CryptoData phantom = null; #pragma warning disable CS0618 // Legacy if (alwaysIncludeBTC) { var btcNetwork = networkProvider?.GetNetwork("BTC"); - rates.Add("BTC", new CryptoData() { ParentEntity = this, Rate = Rate, CryptoCode = "BTC", TxFee = TxFee, FeeRate = new FeeRate(TxFee, 100), DepositAddress = DepositAddress, Network = btcNetwork }); - btcAdded = true; + phantom = new CryptoData() { ParentEntity = this, IsPhantomBTC = true, Rate = Rate, CryptoCode = "BTC", TxFee = TxFee, FeeRate = new FeeRate(TxFee, 100), DepositAddress = DepositAddress, Network = btcNetwork } + rates.Add("BTC", phantom); } if (CryptoData != null) { foreach (var prop in CryptoData.Properties()) { - if (prop.Name == "BTC" && btcAdded) - continue; + if (prop.Name == "BTC" && phantom != null) + rates.Remove("BTC"); var r = serializer.ToObject(prop.Value.ToString()); r.CryptoCode = prop.Name; r.ParentEntity = this; @@ -511,9 +511,12 @@ namespace BTCPayServer.Services.Invoices [JsonProperty(PropertyName = "depositAddress")] public string DepositAddress { get; set; } + [JsonIgnore] + public bool IsPhantomBTC { get; set; } + public CryptoDataAccounting Calculate() { - var cryptoData = ParentEntity.GetCryptoData(null); + var cryptoData = ParentEntity.GetCryptoData(null, IsPhantomBTC); var totalDue = Money.Coins(ParentEntity.ProductInformation.Price / Rate); var paid = Money.Zero; var cryptoPaid = Money.Zero;