Exemplo n.º 1
0
        public async Task <PayResponse> Pay(string bolt11, PayInvoiceParams payParams, CancellationToken cancellation = default)
        {
            try
            {
                var req = new PayInvoiceRequest
                {
                    Invoice       = bolt11,
                    AmountMsat    = payParams?.Amount?.MilliSatoshi,
                    MaxFeePct     = payParams?.MaxFeePercent != null ? (int)Math.Round(payParams.MaxFeePercent.Value) : (int?)null,
                    MaxFeeFlatSat = payParams?.MaxFeeFlat?.Satoshi
                };
                var uuid = await _eclairClient.PayInvoice(req, cancellation);

                while (!cancellation.IsCancellationRequested)
                {
                    var status = await _eclairClient.GetSentInfo(null, uuid, cancellation);

                    if (!status.Any())
                    {
                        continue;
                    }

                    var sentInfo = status.First();
                    switch (sentInfo.Status.type)
                    {
                    case "sent":
                        return(new PayResponse(PayResult.Ok, new PayDetails
                        {
                            TotalAmount = sentInfo.Amount,
                            FeeAmount = sentInfo.FeesPaid
                        }));

                    case "failed":
                        return(new PayResponse(PayResult.CouldNotFindRoute));

                    case "pending":
                        await Task.Delay(200, cancellation);

                        break;
                    }
                }
            }
            catch (EclairClient.EclairApiException exception)
            {
                return(new PayResponse(PayResult.Error, exception.Message));
            }

            return(new PayResponse(PayResult.CouldNotFindRoute));
        }
Exemplo n.º 2
0
        public async Task <PayResponse> Pay(string bolt11, CancellationToken cancellation = default(CancellationToken))
        {
            try
            {
                var uuid = await _eclairClient.PayInvoice(bolt11, null, null, cancellation);

                while (!cancellation.IsCancellationRequested)
                {
                    var status = await _eclairClient.GetSentInfo(null, uuid, cancellation);

                    if (!status.Any())
                    {
                        continue;
                    }

                    switch (status.First().Status)
                    {
                    case "SUCCEEDED":
                        return(new PayResponse(PayResult.Ok));

                    case "FAILED":
                        return(new PayResponse(PayResult.CouldNotFindRoute));

                    case "PENDING":
                        await Task.Delay(200, cancellation);

                        break;
                    }
                }
            }
            catch (EclairClient.EclairApiException)
            {
            }

            return(new PayResponse(PayResult.CouldNotFindRoute));
        }