diff --git a/BTCPayServer.Tests/UnitTest1.cs b/BTCPayServer.Tests/UnitTest1.cs index 9ba40becd..92c209762 100644 --- a/BTCPayServer.Tests/UnitTest1.cs +++ b/BTCPayServer.Tests/UnitTest1.cs @@ -45,7 +45,7 @@ namespace BTCPayServer.Tests [Fact] public void CanCalculateCryptoDue2() { - var dummy = new Key().PubKey.GetAddress(Network.RegTest); + var dummy = new Key().PubKey.GetAddress(Network.RegTest).ToString(); #pragma warning disable CS0618 InvoiceEntity invoiceEntity = new InvoiceEntity(); invoiceEntity.Payments = new System.Collections.Generic.List(); diff --git a/BTCPayServer/Payments/Bitcoin/BitcoinLikeOnChainPaymentMethod.cs b/BTCPayServer/Payments/Bitcoin/BitcoinLikeOnChainPaymentMethod.cs index 7f83e7ac2..d283a5458 100644 --- a/BTCPayServer/Payments/Bitcoin/BitcoinLikeOnChainPaymentMethod.cs +++ b/BTCPayServer/Payments/Bitcoin/BitcoinLikeOnChainPaymentMethod.cs @@ -17,7 +17,7 @@ namespace BTCPayServer.Payments.Bitcoin public string GetPaymentDestination() { - return DepositAddress?.ToString(); + return DepositAddress; } public decimal GetTxFee() @@ -33,10 +33,7 @@ namespace BTCPayServer.Payments.Bitcoin public void SetPaymentDestination(string newPaymentDestination) { - if (newPaymentDestination == null) - DepositAddress = null; - else - DepositAddress = BitcoinAddress.Create(newPaymentDestination, DepositAddress.Network); + DepositAddress = newPaymentDestination; } // Those properties are JsonIgnore because their data is inside CryptoData class for legacy reason @@ -45,7 +42,11 @@ namespace BTCPayServer.Payments.Bitcoin [JsonIgnore] public Money TxFee { get; set; } [JsonIgnore] - public BitcoinAddress DepositAddress { get; set; } + public String DepositAddress { get; set; } + public BitcoinAddress GetDepositAddress(Network network) + { + return string.IsNullOrEmpty(DepositAddress) ? null : BitcoinAddress.Create(DepositAddress, network); + } /////////////////////////////////////////////////////////////////////////////////////// } } diff --git a/BTCPayServer/Payments/Bitcoin/BitcoinLikePaymentHandler.cs b/BTCPayServer/Payments/Bitcoin/BitcoinLikePaymentHandler.cs index 47e9a2410..64c68532a 100644 --- a/BTCPayServer/Payments/Bitcoin/BitcoinLikePaymentHandler.cs +++ b/BTCPayServer/Payments/Bitcoin/BitcoinLikePaymentHandler.cs @@ -34,7 +34,7 @@ namespace BTCPayServer.Payments.Bitcoin Payments.Bitcoin.BitcoinLikeOnChainPaymentMethod onchainMethod = new Payments.Bitcoin.BitcoinLikeOnChainPaymentMethod(); onchainMethod.FeeRate = await getFeeRate; onchainMethod.TxFee = onchainMethod.FeeRate.GetFee(100); // assume price for 100 bytes - onchainMethod.DepositAddress = await getAddress; + onchainMethod.DepositAddress = (await getAddress).ToString(); return onchainMethod; } diff --git a/BTCPayServer/Payments/Bitcoin/NBXplorerListener.cs b/BTCPayServer/Payments/Bitcoin/NBXplorerListener.cs index 3f65f730a..e33b9a9e7 100644 --- a/BTCPayServer/Payments/Bitcoin/NBXplorerListener.cs +++ b/BTCPayServer/Payments/Bitcoin/NBXplorerListener.cs @@ -351,11 +351,11 @@ namespace BTCPayServer.Payments.Bitcoin var paymentMethod = invoice.GetPaymentMethod(wallet.Network, PaymentTypes.BTCLike, _ExplorerClients.NetworkProviders); if (paymentMethod != null && paymentMethod.GetPaymentMethodDetails() is BitcoinLikeOnChainPaymentMethod btc && - btc.DepositAddress.ScriptPubKey == paymentData.Output.ScriptPubKey && + btc.GetDepositAddress(wallet.Network.NBitcoinNetwork).ScriptPubKey == paymentData.Output.ScriptPubKey && paymentMethod.Calculate().Due > Money.Zero) { var address = await wallet.ReserveAddressAsync(strategy); - btc.DepositAddress = address; + btc.DepositAddress = address.ToString(); await _InvoiceRepository.NewAddress(invoiceId, btc, wallet.Network); _Aggregator.Publish(new InvoiceNewAddressEvent(invoiceId, address.ToString(), wallet.Network)); paymentMethod.SetPaymentMethodDetails(btc); diff --git a/BTCPayServer/Services/Invoices/InvoiceEntity.cs b/BTCPayServer/Services/Invoices/InvoiceEntity.cs index d164c44cd..92d964675 100644 --- a/BTCPayServer/Services/Invoices/InvoiceEntity.cs +++ b/BTCPayServer/Services/Invoices/InvoiceEntity.cs @@ -582,7 +582,7 @@ namespace BTCPayServer.Services.Invoices return new Payments.Bitcoin.BitcoinLikeOnChainPaymentMethod() { FeeRate = FeeRate, - DepositAddress = string.IsNullOrEmpty(DepositAddress) ? null : BitcoinAddress.Create(DepositAddress, Network?.NBitcoinNetwork), + DepositAddress = string.IsNullOrEmpty(DepositAddress) ? null : DepositAddress, TxFee = TxFee }; } @@ -592,7 +592,7 @@ namespace BTCPayServer.Services.Invoices if (details is Payments.Bitcoin.BitcoinLikeOnChainPaymentMethod btcLike) { btcLike.TxFee = TxFee; - btcLike.DepositAddress = BitcoinAddress.Create(DepositAddress, Network?.NBitcoinNetwork); + btcLike.DepositAddress = string.IsNullOrEmpty(DepositAddress) ? null : DepositAddress; btcLike.FeeRate = FeeRate; } return details; diff --git a/BTCPayServer/Services/Invoices/InvoiceRepository.cs b/BTCPayServer/Services/Invoices/InvoiceRepository.cs index 5fdc5d17a..fafec2908 100644 --- a/BTCPayServer/Services/Invoices/InvoiceRepository.cs +++ b/BTCPayServer/Services/Invoices/InvoiceRepository.cs @@ -130,7 +130,7 @@ namespace BTCPayServer.Services.Invoices throw new InvalidOperationException("CryptoCode unsupported"); var paymentDestination = paymentMethod.GetPaymentMethodDetails().GetPaymentDestination(); - string address = GetDestination(paymentMethod); + string address = GetDestination(paymentMethod, paymentMethod.Network.NBitcoinNetwork); context.AddressInvoices.Add(new AddressInvoiceData() { InvoiceDataId = invoice.Id, @@ -162,12 +162,12 @@ namespace BTCPayServer.Services.Invoices return invoice; } - private static string GetDestination(PaymentMethod paymentMethod) + private static string GetDestination(PaymentMethod paymentMethod, Network network) { // For legacy reason, BitcoinLikeOnChain is putting the hashes of addresses in database if (paymentMethod.GetId().PaymentType == Payments.PaymentTypes.BTCLike) { - return ((Payments.Bitcoin.BitcoinLikeOnChainPaymentMethod)paymentMethod.GetPaymentMethodDetails()).DepositAddress.ScriptPubKey.Hash.ToString(); + return ((Payments.Bitcoin.BitcoinLikeOnChainPaymentMethod)paymentMethod.GetPaymentMethodDetails()).GetDepositAddress(network).ScriptPubKey.Hash.ToString(); } /////////////// return paymentMethod.GetPaymentMethodDetails().GetPaymentDestination(); @@ -209,7 +209,7 @@ namespace BTCPayServer.Services.Invoices InvoiceDataId = invoiceId, CreatedTime = DateTimeOffset.UtcNow } - .Set(GetDestination(currencyData), currencyData.GetId())); + .Set(GetDestination(currencyData, network.NBitcoinNetwork), currencyData.GetId())); context.HistoricalAddressInvoices.Add(new HistoricalAddressInvoiceData() { InvoiceDataId = invoiceId, diff --git a/BTCPayServer/Views/Invoice/ListInvoices.cshtml b/BTCPayServer/Views/Invoice/ListInvoices.cshtml index 35781fd26..96707d2a5 100644 --- a/BTCPayServer/Views/Invoice/ListInvoices.cshtml +++ b/BTCPayServer/Views/Invoice/ListInvoices.cshtml @@ -48,7 +48,7 @@ InvoiceId Status Amount - Actions + Actions