diff --git a/src/BTCPayServer.Lightning.CLightning/CLightningClient.cs b/src/BTCPayServer.Lightning.CLightning/CLightningClient.cs index da6f9a96..3a2779d5 100644 --- a/src/BTCPayServer.Lightning.CLightning/CLightningClient.cs +++ b/src/BTCPayServer.Lightning.CLightning/CLightningClient.cs @@ -119,7 +119,7 @@ public async Task ListPeersAsync(CancellationToken cancellation = de return peers; } - public Task FundChannelAsync(OpenChannelRequest openChannelRequest, CancellationToken cancellation) + public Task FundChannelAsync(OpenChannelRequest openChannelRequest, CancellationToken cancellation) { OpenChannelRequest.AssertIsSane(openChannelRequest); List parameters = new List(); @@ -127,7 +127,31 @@ public Task FundChannelAsync(OpenChannelRequest openChannelRequest, Cancellation parameters.Add(openChannelRequest.ChannelAmount.Satoshi); if (openChannelRequest.FeeRate != null) parameters.Add($"{openChannelRequest.FeeRate.FeePerK.Satoshi * 4}perkw"); - return SendCommandAsync("fundchannel", parameters.ToArray(), true, cancellation: cancellation); + else + { + parameters.Add("normal"); + } + + if (openChannelRequest.Private != null) + { + parameters.Add(openChannelRequest.Private.ToString().ToLowerInvariant()); + + } + return SendCommandAsync("fundchannel", parameters.ToArray(), true, cancellation: cancellation); + } + + public class FundChannelResponse + { + [JsonProperty("tx")] + public string Transaction { get; set; } + [JsonProperty("txid")] + public string TransactionId { get; set; } + [JsonProperty("outnum")] + public string FundingOutputIndex { get; set; } + [JsonProperty("channel_id")] + public string ChannelId { get; set; } + [JsonProperty("close_to")] + public string CloseToScriptPubKey { get; set; } } public Task ConnectAsync(NodeInfo nodeInfo, CancellationToken cancellation = default) @@ -398,6 +422,7 @@ async Task ILightningClient.ListChannels(CancellationToken c { channels.Add(new LightningChannel() { + Id = channel.ShortChannelId.ToString(), RemoteNode = new PubKey(peer.Id), IsPublic = !channel.Private, LocalBalance = channel.ToUs, @@ -486,10 +511,11 @@ async Task ILightningClient.GetBalance(CancellationToken c async Task ILightningClient.OpenChannel(OpenChannelRequest openChannelRequest, CancellationToken cancellation) { retry: - try - { - await FundChannelAsync(openChannelRequest, cancellation); - } +FundChannelResponse response; +try +{ + response = await FundChannelAsync(openChannelRequest, cancellation); +} catch (LightningRPCException ex) when (ex.Code == CLightningErrorCode.STILL_SYNCING_BITCOIN) { await Task.Delay(1000, cancellation); @@ -522,7 +548,10 @@ async Task ILightningClient.OpenChannel(OpenChannelRequest { return new OpenChannelResponse(OpenChannelResult.AlreadyExists); } - return new OpenChannelResponse(OpenChannelResult.Ok); + return new OpenChannelResponse(OpenChannelResult.Ok) + { + ChannelId = response.ChannelId + }; } async Task ILightningClient.GetDepositAddress(CancellationToken cancellation) diff --git a/src/BTCPayServer.Lightning.Common/LightningChannel.cs b/src/BTCPayServer.Lightning.Common/LightningChannel.cs index 8ec3fe08..fe80c487 100644 --- a/src/BTCPayServer.Lightning.Common/LightningChannel.cs +++ b/src/BTCPayServer.Lightning.Common/LightningChannel.cs @@ -4,6 +4,7 @@ namespace BTCPayServer.Lightning { public class LightningChannel { + public string Id { get; set; } public PubKey RemoteNode { get; set; } public bool IsPublic { get; set; } public bool IsActive { get; set; } diff --git a/src/BTCPayServer.Lightning.Common/OpenChannelRequest.cs b/src/BTCPayServer.Lightning.Common/OpenChannelRequest.cs index 182783a3..a9bb6341 100644 --- a/src/BTCPayServer.Lightning.Common/OpenChannelRequest.cs +++ b/src/BTCPayServer.Lightning.Common/OpenChannelRequest.cs @@ -19,6 +19,8 @@ public FeeRate FeeRate { get; set; } + + public bool? Private { get; set; } public static void AssertIsSane(OpenChannelRequest openChannelRequest) { if (openChannelRequest == null) diff --git a/src/BTCPayServer.Lightning.Common/OpenChannelResponse.cs b/src/BTCPayServer.Lightning.Common/OpenChannelResponse.cs index dbceb31d..5178f77b 100644 --- a/src/BTCPayServer.Lightning.Common/OpenChannelResponse.cs +++ b/src/BTCPayServer.Lightning.Common/OpenChannelResponse.cs @@ -19,5 +19,7 @@ public OpenChannelResult Result { get; set; } + + public string ChannelId { get; set; } } } diff --git a/src/BTCPayServer.Lightning.Eclair/EclairClient.cs b/src/BTCPayServer.Lightning.Eclair/EclairClient.cs index ff389776..5591bac1 100644 --- a/src/BTCPayServer.Lightning.Eclair/EclairClient.cs +++ b/src/BTCPayServer.Lightning.Eclair/EclairClient.cs @@ -73,17 +73,19 @@ public async Task Connect(PubKey nodeId, string host, int? port = null, }, cts); } - public async Task Open(PubKey nodeId, long fundingSatoshis, int? pushMsat = null, - long? fundingFeerateSatByte = null, ChannelFlags? channelFlags = null, + public async Task Open(PubKey nodeId, long fundingSatoshis, string channelType = null,int? pushMsat = null, + long? fundingFeerateSatByte = null, bool? announceChannel = null, int? openTimeoutSeconds = null, CancellationToken cts = default) { return await SendCommandAsync("open", new OpenRequest() { NodeId = nodeId.ToString(), FundingSatoshis = fundingSatoshis, - ChannelFlags = channelFlags, + AnnounceChannel = announceChannel, + ChannelType = channelType, PushMsat = pushMsat, - FundingFeerateSatByte = fundingFeerateSatByte + FundingFeerateSatByte = fundingFeerateSatByte, + OpenTimeoutSeconds = openTimeoutSeconds }, cts); } diff --git a/src/BTCPayServer.Lightning.Eclair/EclairLightningClient.cs b/src/BTCPayServer.Lightning.Eclair/EclairLightningClient.cs index 8c3eb9cd..d72b68be 100644 --- a/src/BTCPayServer.Lightning.Eclair/EclairLightningClient.cs +++ b/src/BTCPayServer.Lightning.Eclair/EclairLightningClient.cs @@ -330,13 +330,15 @@ public async Task OpenChannel(OpenChannelRequest openChanne try { var result = await _eclairClient.Open(openChannelRequest.NodeInfo.NodeId, - openChannelRequest.ChannelAmount.Satoshi - , null, - Convert.ToInt64(openChannelRequest.FeeRate.SatoshiPerByte), null, cancellation); - + openChannelRequest.ChannelAmount.Satoshi, null, null, + (openChannelRequest.FeeRate is null + ? (long?)null + : Convert.ToInt64(openChannelRequest.FeeRate.SatoshiPerByte)), openChannelRequest.Private, null, + cancellation); + if (result.Contains("created channel", StringComparison.OrdinalIgnoreCase)) { - var channelId = result.Replace("created channel", "").Trim(); + string channelId = result.Replace("created channel", "").Trim(); var channel = await _eclairClient.Channel(channelId, cancellation); switch (channel.State) { @@ -346,7 +348,10 @@ public async Task OpenChannel(OpenChannelRequest openChanne case "WAIT_FOR_FUNDING_SIGNED": case "WAIT_FOR_FUNDING_LOCKED": case "WAIT_FOR_FUNDING_CONFIRMED": - return new OpenChannelResponse(OpenChannelResult.NeedMoreConf); + return new OpenChannelResponse(OpenChannelResult.NeedMoreConf) + { + ChannelId = channelId + }; } } diff --git a/src/BTCPayServer.Lightning.Eclair/Models/ChannelFlags.cs b/src/BTCPayServer.Lightning.Eclair/Models/ChannelFlags.cs deleted file mode 100644 index 9a7e9792..00000000 --- a/src/BTCPayServer.Lightning.Eclair/Models/ChannelFlags.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace BTCPayServer.Lightning.Eclair.Models -{ - public enum ChannelFlags - { - Private = 0, - Public = 1 - } -} diff --git a/src/BTCPayServer.Lightning.Eclair/Models/OpenRequest.cs b/src/BTCPayServer.Lightning.Eclair/Models/OpenRequest.cs index 4ec75a60..f062c10f 100644 --- a/src/BTCPayServer.Lightning.Eclair/Models/OpenRequest.cs +++ b/src/BTCPayServer.Lightning.Eclair/Models/OpenRequest.cs @@ -6,6 +6,8 @@ public class OpenRequest public long FundingSatoshis { get; set; } public long? PushMsat { get; set; } public long? FundingFeerateSatByte { get; set; } - public ChannelFlags? ChannelFlags { get; set; } + public string ChannelType { get; set; } + public bool? AnnounceChannel { get; set; } + public int? OpenTimeoutSeconds { get; set; } } } diff --git a/src/BTCPayServer.Lightning.LND/LndClient.cs b/src/BTCPayServer.Lightning.LND/LndClient.cs index 708abcb4..e1bec4f4 100644 --- a/src/BTCPayServer.Lightning.LND/LndClient.cs +++ b/src/BTCPayServer.Lightning.LND/LndClient.cs @@ -681,12 +681,14 @@ async Task ILightningClient.OpenChannel(OpenChannelRequest { Local_funding_amount = openChannelRequest.ChannelAmount.Satoshi.ToString(CultureInfo.InvariantCulture), Node_pubkey_string = openChannelRequest.NodeInfo.NodeId.ToString(), + Private = openChannelRequest.Private }; if (openChannelRequest.FeeRate != null) { req.Sat_per_byte = ((int)openChannelRequest.FeeRate.SatoshiPerByte).ToString(); } var result = await this.SwaggerClient.OpenChannelSyncAsync(req, cancellation); + result. return new OpenChannelResponse(OpenChannelResult.Ok); } catch (SwaggerException ex) when