コード例 #1
0
        public async Task <LightningInvoice> GetInvoice(string invoiceId,
                                                        CancellationToken cancellation = default(CancellationToken))
        {
            InvoiceResponse result = null;

            try
            {
                result = await _eclairClient.GetInvoice(invoiceId, cancellation);
            }
            catch (EclairClient.EclairApiException ex) when(ex.Error.Error == "Not found" || ex.Error.Error.Contains("Invalid hexadecimal", StringComparison.OrdinalIgnoreCase))
            {
                return(null);
            }

            GetReceivedInfoResponse info = null;

            try
            {
                info = await _eclairClient.GetReceivedInfo(invoiceId, null, cancellation);
            }
            catch (EclairClient.EclairApiException)
            {
            }

            var parsed    = BOLT11PaymentRequest.Parse(result.Serialized, _network);
            var lnInvoice = new LightningInvoice()
            {
                Id        = result.PaymentHash,
                Amount    = parsed.MinimumAmount,
                ExpiresAt = parsed.ExpiryDate,
                BOLT11    = result.Serialized
            };

            if (DateTimeOffset.UtcNow >= parsed.ExpiryDate)
            {
                lnInvoice.Status = LightningInvoiceStatus.Expired;
            }
            if (info != null && info.Status.Type == "received")
            {
                lnInvoice.AmountReceived = info.Status.Amount;
                lnInvoice.Status         = info.Status.Amount >= parsed.MinimumAmount ? LightningInvoiceStatus.Paid : LightningInvoiceStatus.Unpaid;
                lnInvoice.PaidAt         = info.Status.ReceivedAt;
            }
            return(lnInvoice);
        }
コード例 #2
0
        public async Task <LightningInvoice> GetInvoice(string invoiceId,
                                                        CancellationToken cancellation = default(CancellationToken))
        {
            var result = await _eclairClient.GetInvoice(invoiceId, cancellation);

            GetReceivedInfoResponse info;

            try
            {
                info = await _eclairClient.GetReceivedInfo(invoiceId, null, cancellation);
            }
            catch (EclairClient.EclairApiException)
            {
                info = new GetReceivedInfoResponse()
                {
                    AmountMsat  = 0,
                    ReceivedAt  = 0,
                    PaymentHash = invoiceId
                };
            }

            var parsed = BOLT11PaymentRequest.Parse(result.Serialized, _network);

            return(new LightningInvoice()
            {
                Id = result.PaymentHash,
                Amount = parsed.MinimumAmount,
                ExpiresAt = parsed.ExpiryDate,
                BOLT11 = result.Serialized,
                AmountReceived = info.AmountMsat,
                Status = info.AmountMsat >= parsed.MinimumAmount ? LightningInvoiceStatus.Paid :
                         DateTime.Now >= parsed.ExpiryDate ? LightningInvoiceStatus.Expired : LightningInvoiceStatus.Unpaid,
                PaidAt = info.ReceivedAt == 0
                    ? (DateTimeOffset?)null
                    : DateTimeOffset.FromUnixTimeMilliseconds(info.ReceivedAt)
            });
        }
コード例 #3
0
        public async Task <LightningInvoice> GetInvoice(string invoiceId,
                                                        CancellationToken cancellation = default(CancellationToken))
        {
            var result = await _eclairClient.GetInvoice(invoiceId, cancellation);

            GetReceivedInfoResponse info = null;

            try
            {
                info = await _eclairClient.GetReceivedInfo(invoiceId, null, cancellation);
            }
            catch (EclairClient.EclairApiException)
            {
            }

            var parsed    = BOLT11PaymentRequest.Parse(result.Serialized, _network);
            var lnInvoice = new LightningInvoice()
            {
                Id        = result.PaymentHash,
                Amount    = parsed.MinimumAmount,
                ExpiresAt = parsed.ExpiryDate,
                BOLT11    = result.Serialized
            };

            if (DateTimeOffset.UtcNow >= parsed.ExpiryDate)
            {
                lnInvoice.Status = LightningInvoiceStatus.Expired;
            }
            if (info != null && info.Status.Type == "received")
            {
                lnInvoice.AmountReceived = info.Status.Amount;
                lnInvoice.Status         = info.Status.Amount >= parsed.MinimumAmount ? LightningInvoiceStatus.Paid : LightningInvoiceStatus.Unpaid;
                lnInvoice.PaidAt         = info.Status.ReceivedAt;
            }
            return(lnInvoice);
        }