示例#1
0
        public async Task <LightningNodeInformation> GetInfo(CancellationToken cancellation = default(CancellationToken))
        {
            var resp = await _rpcClient.GetInfoAsync(cancellation);

            var nodeInfo = new LightningNodeInformation
            {
                BlockHeight = (int?)resp.Block_height ?? 0,
                NodeId      = resp.Identity_pubkey
            };


            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);
        }
示例#2
0
        public async Task <bool> TestAccess(bool isOnion)
        {
            var data    = GetData();
            var summary = _nbXplorerSummaryProvider.GetSummary(data.CryptoCode);

            if (summary.State != NBXplorerState.Ready)
            {
                return(false);
            }

            try
            {
                using (var cts = new CancellationTokenSource(LIGHTNING_TIMEOUT))
                {
                    var client = ConstructClient(data);
                    LightningNodeInformation info = null;
                    try
                    {
                        info = await client.GetInfo(cts.Token);
                    }
                    catch (OperationCanceledException) when(cts.IsCancellationRequested)
                    {
                        throw new Exception($"The lightning node did not reply in a timely manner");
                    }
                    catch (Exception ex)
                    {
                        throw new Exception($"Error while connecting to the API ({ex.Message})");
                    }

                    var nodeInfo = info.NodeInfoList.FirstOrDefault(i => i.IsTor == isOnion) ??
                                   info.NodeInfoList.FirstOrDefault();
                    if (nodeInfo == null)
                    {
                        throw new Exception($"No lightning node public address has been configured");
                    }

                    var blocksGap = summary.Status.ChainHeight - info.BlockHeight;
                    if (blocksGap > 10)
                    {
                        throw new Exception($"The lightning node is not synched ({blocksGap} blocks left)");
                    }

                    if (!EndPointParser.TryParse(nodeInfo.Host, nodeInfo.Port, out var endpoint))
                    {
                        throw new Exception($"Could not parse the endpoint {nodeInfo.Host}");
                    }

                    using (await _socketFactory.ConnectAsync(endpoint, cts.Token))
                    {
                    }
                }

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
示例#3
0
        public static LightningNodeInformation ToLightningNodeInformation(GetInfoResponse info)
        {
            var pubkey   = new PubKey(info.Id);
            var nodeInfo = new LightningNodeInformation()
            {
                BlockHeight = info.BlockHeight
            };

            if (info.Address != null)
            {
                nodeInfo.NodeInfoList.AddRange(info.Address.Select(addr => new NodeInfo(pubkey, addr.Address, addr.Port == 0 ? 9735 : addr.Port)));
            }
            return(nodeInfo);
        }
        public async Task <LightningNodeInformation> GetInfo(CancellationToken cancellation = default(CancellationToken))
        {
            var info = await _ptarmiganClient.GetInfo(cancellation);

            var nodeInfo = new LightningNodeInformation()
            {
                BlockHeight = info.Result.BlockCount ?? 0
            };

            if (!String.IsNullOrEmpty(info.Result.AnnounceIp))
            {
                nodeInfo.NodeInfoList.Add(new NodeInfo(new PubKey(info.Result.NodeId),
                                                       info.Result.AnnounceIp.Split(':')[0],
                                                       info.Result.NodePort));
            }
            return(nodeInfo);
        }
示例#5
0
        public async Task <LightningNodeInformation> GetInfo(CancellationToken cancellation = default)
        {
            var data = await _client.GetInfo(cancellation);

            var nodeInfo = new LightningNodeInformation
            {
                BlockHeight = data.BlockHeight
            };

            foreach (var nodeUri in data.NodeURIs)
            {
                if (NodeInfo.TryParse(nodeUri, out var info))
                {
                    nodeInfo.NodeInfoList.Add(info);
                }
            }

            return(nodeInfo);
        }
示例#6
0
        public async Task <LightningNodeInformation> GetInfo(CancellationToken cancellation = default(CancellationToken))
        {
            var info = await _eclairClient.GetInfo(cancellation);

            var nodeInfo = new LightningNodeInformation()
            {
                BlockHeight = info.BlockHeight
            };

            if (info.PublicAddresses != null)
            {
                nodeInfo.NodeInfoList.AddRange(info.PublicAddresses.Select(s =>
                {
                    var split = s.Split(':');
                    return(new NodeInfo(new PubKey(info.NodeId), split[0], int.Parse(split[1])));
                }));
            }
            return(nodeInfo);
        }