From 35e45333b15baad5441760932da6b10a22bb4153 Mon Sep 17 00:00:00 2001 From: rockstardev Date: Mon, 9 Nov 2020 23:57:48 -0600 Subject: [PATCH] Uppercasing destination address in QR code if it's Bech32 --- BTCPayServer.Tests/UnitTest1.cs | 4 +++- .../Payments/Bitcoin/BitcoinLikePaymentHandler.cs | 10 +++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/BTCPayServer.Tests/UnitTest1.cs b/BTCPayServer.Tests/UnitTest1.cs index e4085bcea..a362fff11 100644 --- a/BTCPayServer.Tests/UnitTest1.cs +++ b/BTCPayServer.Tests/UnitTest1.cs @@ -2006,7 +2006,7 @@ namespace BTCPayServer.Tests await tester.EnsureChannelsSetup(); var user = tester.NewAccount(); user.GrantAccess(); - user.RegisterDerivationScheme("BTC"); + user.RegisterDerivationScheme("BTC", ScriptPubKeyType.Segwit); user.RegisterLightningNode("BTC", LightningConnectionType.CLightning); var invoice = user.BitPay.CreateInvoice( @@ -2043,6 +2043,8 @@ namespace BTCPayServer.Tests ); Assert.Contains("&lightning=", paymentMethodSecond.InvoiceBitcoinUrlQR); Assert.StartsWith("BITCOIN:", paymentMethodSecond.InvoiceBitcoinUrlQR); + var split = paymentMethodSecond.InvoiceBitcoinUrlQR.Split('?')[0]; + Assert.True($"BITCOIN:{paymentMethodSecond.BtcAddress.ToUpperInvariant()}" == split); } } diff --git a/BTCPayServer/Payments/Bitcoin/BitcoinLikePaymentHandler.cs b/BTCPayServer/Payments/Bitcoin/BitcoinLikePaymentHandler.cs index 2d380ac34..465d0af9d 100644 --- a/BTCPayServer/Payments/Bitcoin/BitcoinLikePaymentHandler.cs +++ b/BTCPayServer/Payments/Bitcoin/BitcoinLikePaymentHandler.cs @@ -71,8 +71,16 @@ namespace BTCPayServer.Payments.Bitcoin model.InvoiceBitcoinUrlQR = cryptoInfo.PaymentUrls.BIP21 .Replace("bitcoin:", "BITCOIN:", StringComparison.OrdinalIgnoreCase) + lightningFallback.ToUpperInvariant().Replace("LIGHTNING=", "lightning=", StringComparison.OrdinalIgnoreCase); - ; + + if (bech32Prefixes.Any(a => model.BtcAddress.StartsWith(a, StringComparison.OrdinalIgnoreCase))) + { + model.InvoiceBitcoinUrlQR = model.InvoiceBitcoinUrlQR.Replace( + $"BITCOIN:{model.BtcAddress}", $"BITCOIN:{model.BtcAddress.ToUpperInvariant()}", + StringComparison.OrdinalIgnoreCase + ); + } } + private static string[] bech32Prefixes = new[] { "bc1", "tb1", "bcrt1" }; public override string GetCryptoImage(PaymentMethodId paymentMethodId) {