Parsing of node info and returning it for GetInfo

This commit is contained in:
rockstardev 2018-06-15 13:57:39 -05:00
parent cfd083bed5
commit 9b540273fc
2 changed files with 18 additions and 7 deletions

View file

@ -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();

View file

@ -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);