コード例 #1
0
        protected override void ProcessRecord()
        {
            base.ProcessRecord();
            PayInvoiceRequest request;

            try
            {
                request = new PayInvoiceRequest
                {
                    OspHomeRegion     = OspHomeRegion,
                    InternalInvoiceId = InternalInvoiceId,
                    CompartmentId     = CompartmentId,
                    PayInvoiceDetails = PayInvoiceDetails,
                    IfMatch           = IfMatch,
                    OpcRetryToken     = OpcRetryToken,
                    OpcRequestId      = OpcRequestId
                };

                response = client.PayInvoice(request).GetAwaiter().GetResult();
                WriteOutput(response, response.PayInvoiceReceipt);
                FinishProcessing(response);
            }
            catch (Exception ex)
            {
                TerminatingErrorDuringExecution(ex);
            }
        }
コード例 #2
0
        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));
        }
コード例 #3
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));
        }
コード例 #4
0
 public async Task <string> PayInvoice(PayInvoiceRequest payInvoiceRequest, CancellationToken cts = default(CancellationToken))
 {
     return(await SendCommandAsync <PayInvoiceRequest, string>("payinvoice", payInvoiceRequest, cts));
 }