diff --git a/BTCPayServer.Common/BTCPayServer.Common.csproj b/BTCPayServer.Common/BTCPayServer.Common.csproj
index 481dab15f..74ab3799a 100644
--- a/BTCPayServer.Common/BTCPayServer.Common.csproj
+++ b/BTCPayServer.Common/BTCPayServer.Common.csproj
@@ -4,7 +4,7 @@
-
-
+
+
diff --git a/BTCPayServer.Tests/UnitTest1.cs b/BTCPayServer.Tests/UnitTest1.cs
index 3d1589f0e..402879c50 100644
--- a/BTCPayServer.Tests/UnitTest1.cs
+++ b/BTCPayServer.Tests/UnitTest1.cs
@@ -702,7 +702,7 @@ namespace BTCPayServer.Tests
FullNotifications = true,
ExtendedNotifications = true
});
- BitcoinUrlBuilder url = new BitcoinUrlBuilder(invoice.PaymentUrls.BIP21);
+ BitcoinUrlBuilder url = new BitcoinUrlBuilder(invoice.PaymentUrls.BIP21, tester.NetworkProvider.BTC.NBitcoinNetwork);
bool receivedPayment = false;
bool paid = false;
bool confirmed = false;
diff --git a/BTCPayServer/Controllers/HomeController.cs b/BTCPayServer/Controllers/HomeController.cs
index 5363081e1..a3af749d6 100644
--- a/BTCPayServer/Controllers/HomeController.cs
+++ b/BTCPayServer/Controllers/HomeController.cs
@@ -121,7 +121,7 @@ namespace BTCPayServer.Controllers
try
{
- BitcoinUrlBuilder urlBuilder = new BitcoinUrlBuilder(vm.BitpayLink);
+ BitcoinUrlBuilder urlBuilder = new BitcoinUrlBuilder(vm.BitpayLink, Network.Main);
#pragma warning disable CS0618 // Type or member is obsolete
if (!urlBuilder.PaymentRequestUrl.DnsSafeHost.EndsWith("bitpay.com", StringComparison.OrdinalIgnoreCase))
{
diff --git a/BTCPayServer/Services/Invoices/InvoiceRepository.cs b/BTCPayServer/Services/Invoices/InvoiceRepository.cs
index 9b3c940e9..170177c12 100644
--- a/BTCPayServer/Services/Invoices/InvoiceRepository.cs
+++ b/BTCPayServer/Services/Invoices/InvoiceRepository.cs
@@ -21,6 +21,7 @@ using BTCPayServer.Models.InvoicingModels;
using BTCPayServer.Logging;
using BTCPayServer.Payments;
using System.Data.Common;
+using Newtonsoft.Json.Linq;
namespace BTCPayServer.Services.Invoices
{
@@ -448,8 +449,19 @@ retry:
#pragma warning disable CS0618
entity.Payments = invoice.Payments.Select(p =>
{
- var paymentEntity = ToObject(p.Blob, null);
- paymentEntity.Network = _Networks.GetNetwork(paymentEntity.CryptoCode);
+ var unziped = ZipUtils.Unzip(p.Blob);
+ var cryptoCode = GetCryptoCode(unziped);
+ var network = _Networks.GetNetwork(cryptoCode);
+ PaymentEntity paymentEntity = null;
+ if (network == null)
+ {
+ paymentEntity = NBitcoin.JsonConverters.Serializer.ToObject(unziped, null);
+ }
+ else
+ {
+ paymentEntity = network.ToObject(unziped);
+ }
+ paymentEntity.Network = network;
paymentEntity.Accounted = p.Accounted;
// PaymentEntity on version 0 does not have their own fee, because it was assumed that the payment method have fixed fee.
// We want to hide this legacy detail in InvoiceRepository, so we fetch the fee from the PaymentMethod and assign it to the PaymentEntity.
@@ -491,6 +503,13 @@ retry:
return entity;
}
+ private string GetCryptoCode(string json)
+ {
+ if (JObject.Parse(json).TryGetValue("cryptoCode", out var v) && v.Type == JTokenType.String)
+ return v.Value();
+ return "BTC";
+ }
+
private IQueryable GetInvoiceQuery(ApplicationDbContext context, InvoiceQuery queryObject)
{
IQueryable query = context.Invoices;
@@ -688,7 +707,7 @@ retry:
PaymentData data = new PaymentData
{
Id = paymentData.GetPaymentId(),
- Blob = ToBytes(entity, null),
+ Blob = ToBytes(entity, network),
InvoiceDataId = invoiceId,
Accounted = accounted
};
@@ -717,7 +736,7 @@ retry:
var data = new PaymentData();
data.Id = paymentData.GetPaymentId();
data.Accounted = payment.Accounted;
- data.Blob = ToBytes(payment, null);
+ data.Blob = ToBytes(payment, payment.Network);
context.Attach(data);
context.Entry(data).Property(o => o.Accounted).IsModified = true;
context.Entry(data).Property(o => o.Blob).IsModified = true;
@@ -732,14 +751,6 @@ retry:
entity.Networks = _Networks;
return entity;
}
- private T ToObject(byte[] value, BTCPayNetworkBase network)
- {
- if (network == null)
- {
- return NBitcoin.JsonConverters.Serializer.ToObject(ZipUtils.Unzip(value), null);
- }
- return network.ToObject(ZipUtils.Unzip(value));
- }
private byte[] ToBytes(T obj, BTCPayNetworkBase network = null)
{