diff --git a/BTCPayServer.Tests/UnitTest1.cs b/BTCPayServer.Tests/UnitTest1.cs index 364584a95..855e43915 100644 --- a/BTCPayServer.Tests/UnitTest1.cs +++ b/BTCPayServer.Tests/UnitTest1.cs @@ -493,14 +493,14 @@ namespace BTCPayServer.Tests [Fact] public void CanSendLightningPaymentLnd() { - // For easier debugging and testing - LightningLikePaymentHandler.LIGHTNING_TIMEOUT = int.MaxValue; - ProcessLightningPayment(LightningConnectionType.Lnd); } void ProcessLightningPayment(LightningConnectionType type) { + // For easier debugging and testing + LightningLikePaymentHandler.LIGHTNING_TIMEOUT = int.MaxValue; + using (var tester = ServerTester.Create()) { tester.Start(); diff --git a/BTCPayServer/Payments/Lightning/Lnd/LndInvoiceClient.cs b/BTCPayServer/Payments/Lightning/Lnd/LndInvoiceClient.cs index 7a86c4b20..896461ff8 100644 --- a/BTCPayServer/Payments/Lightning/Lnd/LndInvoiceClient.cs +++ b/BTCPayServer/Payments/Lightning/Lnd/LndInvoiceClient.cs @@ -57,10 +57,16 @@ namespace BTCPayServer.Payments.Lightning.Lnd NodeId = resp.Identity_pubkey }; - // Lnd doesn't return this data as Clightning, find alternative ways to supply - // it always should be merchant_lnd:9735 because of docker - nodeInfo.Address = null; - nodeInfo.P2PPort = 9735; + + var node = await _rpcClient.GetNodeInfoAsync(resp.Identity_pubkey, cancellation); + if (node.Node.Addresses == null || node.Node.Addresses.Count == 0) + throw new Exception("Lnd External IP not set, make sure you use --externalip=$EXTERNALIP parameter on lnd"); + + var firstNodeInfo = node.Node.Addresses.First(); + var externalHostPort = firstNodeInfo.Addr.Split(':'); + + nodeInfo.Address = externalHostPort[0]; + nodeInfo.P2PPort = ConvertInv.ToInt32(externalHostPort[1]); return nodeInfo; } @@ -129,6 +135,11 @@ namespace BTCPayServer.Payments.Lightning.Lnd // Invariant culture conversion public static class ConvertInv { + public static int ToInt32(string str) + { + return Convert.ToInt32(str, CultureInfo.InvariantCulture.NumberFormat); + } + public static long ToInt64(string str) { return Convert.ToInt64(str, CultureInfo.InvariantCulture.NumberFormat);