public ILightningInvoiceClient CreateClient(LightningSupportedPaymentMethod supportedPaymentMethod, BTCPayNetwork network)
        {
            var uri = supportedPaymentMethod.GetLightningUrl();

            if (uri.ConnectionType == LightningConnectionType.Charge)
            {
                return(new ChargeClient(uri.ToUri(true), network.NBitcoinNetwork));
            }
            else if (uri.ConnectionType == LightningConnectionType.CLightning)
            {
                return(new CLightningRPCClient(uri.ToUri(false), network.NBitcoinNetwork));
            }
            else
            {
                throw new NotSupportedException($"Unsupported connection string for lightning server ({uri.ConnectionType})");
            }
        }
Пример #2
0
        private async Task Listen(LightningSupportedPaymentMethod supportedPaymentMethod, BTCPayNetwork network)
        {
            ILightningInvoiceListener session = null;

            try
            {
                Logs.PayServer.LogInformation($"{supportedPaymentMethod.CryptoCode} (Lightning): Start listening {supportedPaymentMethod.GetLightningUrl().BaseUri}");
                var lightningClient = supportedPaymentMethod.CreateClient(network);
                session = await lightningClient.Listen(_Cts.Token);

                while (true)
                {
                    var notification = await session.WaitInvoice(_Cts.Token);

                    ListenedInvoice listenedInvoice = GetListenedInvoice(notification.Id);
                    if (listenedInvoice == null)
                    {
                        continue;
                    }
                    if (notification.Id == listenedInvoice.PaymentMethodDetails.InvoiceId &&
                        notification.BOLT11 == listenedInvoice.PaymentMethodDetails.BOLT11)
                    {
                        if (notification.Status == LightningInvoiceStatus.Paid &&
                            notification.PaidAt.HasValue && notification.Amount != null)
                        {
                            await AddPayment(network, notification, listenedInvoice);

                            if (DoneListening(listenedInvoice))
                            {
                                break;
                            }
                        }
                        if (notification.Status == LightningInvoiceStatus.Expired)
                        {
                            if (DoneListening(listenedInvoice))
                            {
                                break;
                            }
                        }
                    }
                }
            }
            catch when(_Cts.IsCancellationRequested)
            {
            }
Пример #3
0
        public ILightningInvoiceClient CreateClient(LightningSupportedPaymentMethod supportedPaymentMethod, BTCPayNetwork network)
        {
            var uri = supportedPaymentMethod.GetLightningUrl();

            return(CreateClient(uri, network.NBitcoinNetwork));
        }