Exemplo n.º 1
0
        public async Task <LightningChannel[]> ListChannels(CancellationToken cancellation = default(CancellationToken))
        {
            var channels = await _eclairClient.Channels(null, cancellation);

            return(channels.Select(response =>
            {
                OutPoint.TryParse(response.Data.Commitments.CommitInput.OutPoint.Replace(":", "-"),
                                  out var outPoint);

                return new LightningChannel()
                {
                    IsPublic = ((ChannelFlags)response.Data.Commitments.ChannelFlags) == ChannelFlags.Public,
                    RemoteNode = new PubKey(response.NodeId),
                    IsActive = response.State == "NORMAL",
                    LocalBalance = new LightMoney(response.Data.Commitments.LocalCommit.Spec.ToLocalMsat),
                    Capacity = new LightMoney(response.Data.Commitments.CommitInput.AmountSatoshis),
                    ChannelPoint = outPoint,
                };
            }).ToArray());
        }
Exemplo n.º 2
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            if (reader.TokenType == JsonToken.Null)
            {
                return(null);
            }

            reader.AssertJsonType(JsonToken.String);
            try
            {
                if (!OutPoint.TryParse((string)reader.Value, out var outpoint))
                {
                    throw new JsonObjectException("Invalid bitcoin object of type OutPoint", reader);
                }
                return(outpoint);
            }
            catch (EndOfStreamException)
            {
            }
            throw new JsonObjectException("Invalid bitcoin object of type OutPoint", reader);
        }