diff --git a/BTCPayServer.Tests/UnitTestPeusa.cs b/BTCPayServer.Tests/UnitTestPeusa.cs index d53566fcb..d2b99bd80 100644 --- a/BTCPayServer.Tests/UnitTestPeusa.cs +++ b/BTCPayServer.Tests/UnitTestPeusa.cs @@ -55,29 +55,5 @@ namespace BTCPayServer.Tests ExtPubKey pubkey = masterPubKey.Derive(0); Console.WriteLine("PubKey " + 0 + " : " + pubkey.ToString(network)); } - - [Fact] - public async Task TestLndAsync() - { - var tls = File.ReadAllBytes(@"c:\Users\newdawn\AppData\Local\Lnd\tls.cert"); - var macroon = File.ReadAllBytes(@"c:\Users\newdawn\AppData\Local\Lnd\admin.macaroon"); - - var lnd = new LndClient(new Uri("https://localhost:8080"), Network.RegTest, tls, macroon); - var res = await lnd.GetInfo(); - - Console.WriteLine("Address: " + res.Address); - } - - [Fact] - public async Task LndCreateInvoice() - { - var tls = File.ReadAllBytes(@"c:\Users\newdawn\AppData\Local\Lnd\tls.cert"); - var macroon = File.ReadAllBytes(@"c:\Users\newdawn\AppData\Local\Lnd\admin.macaroon"); - - var lnd = new LndClient(new Uri("https://127.0.0.1:8080"), Network.RegTest, tls, macroon); - var res = await lnd.CreateInvoice(10000, "Hello world", TimeSpan.FromSeconds(3600)); - - Console.WriteLine("Result: "+ res.ToJson()); - } } } diff --git a/BTCPayServer.Tests/UnitTests/LndTest.cs b/BTCPayServer.Tests/UnitTests/LndTest.cs new file mode 100644 index 000000000..2433c39f9 --- /dev/null +++ b/BTCPayServer.Tests/UnitTests/LndTest.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading.Tasks; +using BTCPayServer.Payments.Lightning.Lnd; +using NBitcoin; +using Xunit; +using Xunit.Abstractions; + +namespace BTCPayServer.Tests.UnitTests +{ + public class LndTest + { + private readonly ITestOutputHelper output; + + public LndTest(ITestOutputHelper output) + { + this.output = output; + } + + private LndClient Client + { + get + { + var lnd = new LndClient(new Uri("http://localhost:53280"), Network.RegTest); + return lnd; + } + } + + [Fact] + public async Task GetInfo() + { + var res = await Client.GetInfo(); + + output.WriteLine("Result: " + res.ToJson()); + } + + [Fact] + public async Task CreateInvoice() + { + var res = await Client.CreateInvoice(10000, "Hello world", TimeSpan.FromSeconds(3600)); + + output.WriteLine("Result: " + res.ToJson()); + } + } +} diff --git a/BTCPayServer.Tests/docker/lnd/Dockerfile b/BTCPayServer.Tests/docker/lnd/Dockerfile index 1f95ea187..264f5443d 100644 --- a/BTCPayServer.Tests/docker/lnd/Dockerfile +++ b/BTCPayServer.Tests/docker/lnd/Dockerfile @@ -22,4 +22,4 @@ RUN go install . ./cmd/... COPY "start-lnd.sh" . RUN chmod +x start-lnd.sh -ENTRYPOINT ["./start-lnd.sh"] +ENTRYPOINT ["./start-lnd.sh"] \ No newline at end of file diff --git a/BTCPayServer/Payments/Lightning/Lnd/LndClient.cs b/BTCPayServer/Payments/Lightning/Lnd/LndClient.cs index 342f1bd73..0358a4007 100644 --- a/BTCPayServer/Payments/Lightning/Lnd/LndClient.cs +++ b/BTCPayServer/Payments/Lightning/Lnd/LndClient.cs @@ -17,16 +17,19 @@ namespace BTCPayServer.Payments.Lightning.Lnd { public class LndClient : ILightningInvoiceClient, ILightningListenInvoiceSession { - public LndClient(Uri uri, Network network, byte[] tlsCertificate, byte[] grpcMacaroon) + public LndClient(Uri uri, Network network, byte[] tlsCertificate = null, byte[] grpcMacaroon = null) { - _HttpClient = HttpClientFactoryForLnd.Generate(tlsCertificate, grpcMacaroon); + // for now working with custom build of lnd that has no macaroons and is on http + //_HttpClient = HttpClientFactoryForLnd.Generate(tlsCertificate, grpcMacaroon); + + _HttpClient = new HttpClient(); _Decorator = new LndSwaggerClient(uri.ToString().TrimEnd('/'), _HttpClient); } private HttpClient _HttpClient; private LndSwaggerClient _Decorator; - public async Task CreateInvoice(LightMoney amount, string description, TimeSpan expiry, + public async Task CreateInvoice(LightMoney amount, string description, TimeSpan expiry, CancellationToken cancellation = default(CancellationToken)) { var strAmount = ConvertInv.ToString(amount.ToUnit(LightMoneyUnit.Satoshi)); @@ -41,7 +44,6 @@ namespace BTCPayServer.Payments.Lightning.Lnd var invoice = new LightningInvoice { - // TODO: Verify id corresponds to R_hash Id = BitString(resp.R_hash), Amount = amount, BOLT11 = resp.Payment_request, @@ -154,7 +156,9 @@ namespace BTCPayServer.Payments.Lightning.Lnd private static HttpClientHandler GetCertificate(byte[] certFile) { - var clientCertificate = new X509Certificate2(certFile); + X509Certificate2 clientCertificate = null; + if (certFile != null) + clientCertificate = new X509Certificate2(certFile); var handler = new HttpClientHandler { @@ -172,6 +176,9 @@ namespace BTCPayServer.Payments.Lightning.Lnd return false; } + if (clientCertificate == null) + return true; + X509Certificate2 remoteRoot = chain.ChainElements[chain.ChainElements.Count - 1].Certificate; var res = clientCertificate.RawData.SequenceEqual(remoteRoot.RawData);