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); } } }
private async Task <LightningNodeInformation> WaitLNSynched(params ILightningInvoiceClient[] clients) { while (true) { var blockCount = await ExplorerNode.GetBlockCountAsync(); var synching = clients.Select(c => WaitLNSynchedCore(blockCount, c)).ToArray(); await Task.WhenAll(synching); if (synching.All(c => c.Result != null)) { return(synching[0].Result); } await Task.Delay(1000); } }
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()); } } }
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); } }
private async Task <GetInfoResponse> WaitLNSynched() { while (true) { var merchantInfo = await MerchantCharge.Client.GetInfoAsync(); var blockCount = await ExplorerNode.GetBlockCountAsync(); if (merchantInfo.BlockHeight != blockCount) { await Task.Delay(1000); } else { return(merchantInfo); } } }
private async Task <LightningNodeInformation> WaitLNSynched() { while (true) { var merchantInfo = await InvoiceClient.GetInfo(); var blockCount = await ExplorerNode.GetBlockCountAsync(); if (merchantInfo.BlockHeight != blockCount) { await Task.Delay(500); } else { return(merchantInfo); } } }