public async Task <PayResponse> Pay(string bolt11, PayInvoiceParams payParams, CancellationToken cancellation) { var payload = new PayInvoiceRequest { PaymentRequest = bolt11, MaxFeePercent = payParams?.MaxFeePercent, MaxFeeFlat = payParams?.MaxFeeFlat?.Satoshi }; return(await Post <PayInvoiceRequest, PayResponse>("pay", payload, cancellation)); }
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)); }
public async Task <PayResponse> Pay(string bolt11, PayInvoiceParams payParams, CancellationToken cancellation = default) { return(await _client.Pay(bolt11, payParams, cancellation)); }
Task <PayResponse> ILightningClient.Pay(string bolt11, PayInvoiceParams payParams, CancellationToken cancellation) { throw new NotSupportedException(); }