Beispiel #1
0
        public async Task PrepareLightningAsync()
        {
            // Activate segwit
            var blockCount = ExplorerNode.GetBlockCountAsync();
            // Fetch node info, but that in cache
            var merchantInfo = MerchantCharge.Client.GetInfoAsync();
            var customer     = CustomerEclair.GetNodeInfoAsync();
            var channels     = CustomerEclair.RPC.ChannelsAsync();

            var info       = await merchantInfo;
            var clightning = new NodeInfo(info.Id, MerchantCharge.P2PHost, info.Port);
            var connect    = CustomerEclair.RPC.ConnectAsync(clightning);
            await Task.WhenAll(blockCount, customer, channels, connect);

            // Mine until segwit is activated
            if (blockCount.Result <= 432)
            {
                ExplorerNode.Generate(433 - blockCount.Result);
            }

            if (channels.Result.Length == 0)
            {
                await CustomerEclair.RPC.OpenAsync(clightning, Money.Satoshis(16777215));

                while ((await CustomerEclair.RPC.ChannelsAsync())[0].State != "NORMAL")
                {
                    ExplorerNode.Generate(1);
                }
            }
        }
        public async Task PrepareLightningAsync()
        {
            // Activate segwit
            var blockCount = ExplorerNode.GetBlockCountAsync();
            // Fetch node info, but that in cache
            var merchantInfo = MerchantCharge.Client.GetInfoAsync();
            var customer     = CustomerEclair.GetNodeInfoAsync();
            var channels     = CustomerEclair.RPC.ChannelsAsync();

            var info       = await merchantInfo;
            var clightning = new NodeInfo(info.Id, MerchantCharge.P2PHost, info.Port);
            var connect    = CustomerEclair.RPC.ConnectAsync(clightning);
            await Task.WhenAll(blockCount, customer, channels, connect);

            // If the channel is not created, let's do it
            if (channels.Result.Length == 0)
            {
                var  c                          = (await CustomerEclair.RPC.ChannelsAsync());
                bool generated                  = false;
                bool createdChannel             = false;
                CancellationTokenSource timeout = new CancellationTokenSource();
                timeout.CancelAfter(10000);
                while (c.Length == 0 || c[0].State != "NORMAL")
                {
                    if (timeout.IsCancellationRequested)
                    {
                        timeout = new CancellationTokenSource();
                        timeout.CancelAfter(10000);
                        createdChannel = c.Length == 0;
                        generated      = false;
                    }
                    if (!createdChannel)
                    {
                        await CustomerEclair.RPC.OpenAsync(clightning, Money.Satoshis(16777215));

                        createdChannel = true;
                    }
                    if (!generated && c.Length != 0 && c[0].State == "WAIT_FOR_FUNDING_CONFIRMED")
                    {
                        ExplorerNode.Generate(6);
                        generated = true;
                    }
                    c = (await CustomerEclair.RPC.ChannelsAsync());
                }
            }
        }
Beispiel #3
0
        public async Task PrepareLightningAsync()
        {
            // Activate segwit
            var blockCount = ExplorerNode.GetBlockCountAsync();
            // Fetch node info, but that in cache
            var merchant = MerchantEclair.GetNodeInfoAsync();
            var customer = CustomerEclair.GetNodeInfoAsync();
            var channels = CustomerEclair.RPC.ChannelsAsync();
            var connect  = CustomerEclair.RPC.ConnectAsync(merchant.Result);
            await Task.WhenAll(blockCount, merchant, customer, channels, connect);

            // Mine until segwit is activated
            if (blockCount.Result <= 432)
            {
                ExplorerNode.Generate(433 - blockCount.Result);
            }
        }