Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b1b3b5a5b2 | ||
|
|
35aeda799c |
@ -3,7 +3,7 @@
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net6.0;netstandard2.0</TargetFrameworks>
|
||||
<RootNamespace>BTCPayServer.Lightning</RootNamespace>
|
||||
<Version>1.4.11</Version>
|
||||
<Version>1.4.12</Version>
|
||||
<LangVersion>10</LangVersion>
|
||||
<PackageId>BTCPayServer.Lightning.All</PackageId>
|
||||
<Description>Client library for lightning network implementations to build Lightning Network Apps in C#.</Description>
|
||||
|
||||
@ -139,7 +139,7 @@ namespace BTCPayServer.Lightning.Tests
|
||||
|
||||
private static async Task<PayResponse> Pay(ILightningClient sender, string payreq)
|
||||
{
|
||||
using (var cts = new CancellationTokenSource(5000))
|
||||
using (var cts = new CancellationTokenSource(30_000))
|
||||
{
|
||||
retry:
|
||||
try
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net6.0;netstandard2.0</TargetFrameworks>
|
||||
<Version>1.3.18</Version>
|
||||
<Version>1.3.19</Version>
|
||||
<LangVersion>10</LangVersion>
|
||||
<PackageId>BTCPayServer.Lightning.CLightning</PackageId>
|
||||
<Description>Client library for c-lightning to build Lightning Network Apps in C#.</Description>
|
||||
|
||||
@ -354,7 +354,7 @@ namespace BTCPayServer.Lightning.CLightning
|
||||
: PayResult.Error;
|
||||
return new PayResponse(result, ex.Message);
|
||||
}
|
||||
catch (Exception ex) when (cts.Token.IsCancellationRequested)
|
||||
catch (Exception ex) when (cts.Token.IsCancellationRequested && !cancellation.IsCancellationRequested)
|
||||
{
|
||||
if (bolt11 != null)
|
||||
{
|
||||
@ -414,12 +414,62 @@ namespace BTCPayServer.Lightning.CLightning
|
||||
var msat = amount == LightMoney.Zero ? "any" : amount.MilliSatoshi.ToString();
|
||||
var expiry = Math.Max(0, (int)req.Expiry.TotalSeconds);
|
||||
var id = InvoiceIdEncoder.EncodeData(RandomUtils.GetBytes(20));
|
||||
var cmd = req.DescriptionHash == null ? "invoice" : "invoicewithdescriptionhash";
|
||||
var opts = req.DescriptionHash == null
|
||||
? new object[] { msat, id, req.Description ?? "", expiry, null, null, req.PrivateRouteHints }
|
||||
: new object[] { msat, id, req.DescriptionHash.ToString(), expiry, null, null, req.PrivateRouteHints };
|
||||
|
||||
var invoice = await SendCommandAsync<CLightningInvoice>(cmd, opts, cancellation: cancellation);
|
||||
List<object> args = new List<object>();
|
||||
args.Add(msat);
|
||||
args.Add(id);
|
||||
args.Add(req.Description ?? "");
|
||||
args.Add(expiry);
|
||||
args.Add(null); // [fallbacks]
|
||||
args.Add(null); // [preimage]
|
||||
args.Add(req.PrivateRouteHints);
|
||||
|
||||
bool usePlugin;
|
||||
if (req.DescriptionHashOnly)
|
||||
{
|
||||
args.Add(null); // [cltv]
|
||||
args.Add(true);
|
||||
usePlugin = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
usePlugin = req.DescriptionHash is not null;
|
||||
}
|
||||
|
||||
// Pre 22.11, we needed to use a plugin to support bolt11 with description hash.
|
||||
// This is not the case anymore, but we may fallback to using the plugin for old nodes.
|
||||
CLightningInvoice invoice = null;
|
||||
if (!usePlugin)
|
||||
{
|
||||
try
|
||||
{
|
||||
invoice = await SendCommandAsync<CLightningInvoice>(
|
||||
"invoice",
|
||||
args.ToArray(),
|
||||
cancellation: cancellation);
|
||||
}
|
||||
// Old nodes doesn't support descriptionHashOnly
|
||||
catch (LightningRPCException ex) when (req.DescriptionHashOnly && ex.Code == CLightningErrorCode.WRONG_PARAMETERS)
|
||||
{
|
||||
// Remove two last parameters
|
||||
args.RemoveAt(args.Count - 1);
|
||||
args.RemoveAt(args.Count - 1);
|
||||
usePlugin = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (usePlugin)
|
||||
{
|
||||
args[2] = req.DescriptionHash.ToString();
|
||||
invoice = await SendCommandAsync<CLightningInvoice>(
|
||||
"invoicewithdescriptionhash",
|
||||
args.ToArray(),
|
||||
cancellation: cancellation);
|
||||
}
|
||||
|
||||
if (invoice is null)
|
||||
throw new InvalidOperationException("Bug in BTCPayServer.Lightning library, contact developers, code 52917");
|
||||
|
||||
invoice.Label = id;
|
||||
invoice.MilliSatoshi = amount;
|
||||
invoice.Status = "unpaid";
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net6.0;netstandard2.0</TargetFrameworks>
|
||||
<Version>1.3.15</Version>
|
||||
<Version>1.3.16</Version>
|
||||
<LangVersion>10</LangVersion>
|
||||
<PackageId>BTCPayServer.Lightning.Charge</PackageId>
|
||||
<Description>Client library for lightning charge to build Lightning Network Apps in C#.</Description>
|
||||
|
||||
@ -219,7 +219,7 @@ namespace BTCPayServer.Lightning.Charge
|
||||
}
|
||||
Task<LightningInvoice> ILightningClient.CreateInvoice(CreateInvoiceParams req, CancellationToken cancellation)
|
||||
{
|
||||
if (req.DescriptionHash != null)
|
||||
if (req.DescriptionHash is not null)
|
||||
{
|
||||
throw new NotSupportedException("Lightning Charge does not support creating an invoice with description_hash");
|
||||
}
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<RootNamespace>BTCPayServer.Lightning</RootNamespace>
|
||||
<Version>1.3.16</Version>
|
||||
<Version>1.3.17</Version>
|
||||
<LangVersion>10</LangVersion>
|
||||
<PackageId>BTCPayServer.Lightning.Common</PackageId>
|
||||
<Description>Client library for lightning network implementations to build Lightning Network Apps in C#.</Description>
|
||||
|
||||
@ -4,6 +4,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using NBitcoin;
|
||||
using NBitcoin.Crypto;
|
||||
|
||||
namespace BTCPayServer.Lightning
|
||||
{
|
||||
@ -20,6 +21,7 @@ namespace BTCPayServer.Lightning
|
||||
Description = description;
|
||||
Expiry = expiry;
|
||||
}
|
||||
[Obsolete("Set the Description and turn DescriptionHashOnly to true instead")]
|
||||
public CreateInvoiceParams(LightMoney amount, uint256 descriptionHash, TimeSpan expiry)
|
||||
{
|
||||
if (amount == null)
|
||||
@ -34,7 +36,22 @@ namespace BTCPayServer.Lightning
|
||||
|
||||
public LightMoney Amount { get; set; }
|
||||
public string Description { get; set; }
|
||||
public uint256 DescriptionHash { get; set; }
|
||||
uint256 _DescriptionHash;
|
||||
public uint256 DescriptionHash
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_DescriptionHash is null && (Description is null || !DescriptionHashOnly))
|
||||
return null;
|
||||
return _DescriptionHash ?? new uint256(Hashes.SHA256(Encoding.UTF8.GetBytes(Description)), false);
|
||||
}
|
||||
[Obsolete("Set the Description and turn DescriptionHashOnly to true instead")]
|
||||
set
|
||||
{
|
||||
_DescriptionHash = value;
|
||||
}
|
||||
}
|
||||
public bool DescriptionHashOnly { get; set; }
|
||||
public TimeSpan Expiry { get; set; }
|
||||
public bool PrivateRouteHints { get; set; }
|
||||
}
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net6.0;netstandard2.0</TargetFrameworks>
|
||||
<Version>1.3.15</Version>
|
||||
<Version>1.3.16</Version>
|
||||
<LangVersion>10</LangVersion>
|
||||
<PackageId>BTCPayServer.Lightning.Eclair</PackageId>
|
||||
<Description>Client library for Eclair to build Lightning Network Apps in C#.</Description>
|
||||
|
||||
@ -167,9 +167,9 @@ namespace BTCPayServer.Lightning.Eclair
|
||||
}
|
||||
Task<LightningInvoice> ILightningClient.CreateInvoice(CreateInvoiceParams req, CancellationToken cancellation)
|
||||
{
|
||||
if (req.DescriptionHash != null)
|
||||
if (req.DescriptionHash is not null)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
throw new NotSupportedException("DescriptionHash isn't supported");
|
||||
}
|
||||
return (this as ILightningClient).CreateInvoice(req.Amount, req.Description, req.Expiry, cancellation);
|
||||
}
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net6.0;netstandard2.0</TargetFrameworks>
|
||||
<Version>1.4.8</Version>
|
||||
<Version>1.4.9</Version>
|
||||
<LangVersion>10</LangVersion>
|
||||
<PackageId>BTCPayServer.Lightning.LND</PackageId>
|
||||
<Description>Client library for LND to build Lightning Network Apps in C#.</Description>
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net6.0;netstandard2.0</TargetFrameworks>
|
||||
<Version>1.0.11</Version>
|
||||
<Version>1.0.12</Version>
|
||||
<PackageId>BTCPayServer.Lightning.LNDhub</PackageId>
|
||||
<Description>Client library for BlueWallet LNDhub to build Lightning Network Apps in C#.</Description>
|
||||
<PackageProjectUrl>https://github.com/btcpayserver/BTCPayServer.Lightning</PackageProjectUrl>
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net6.0;netstandard2.0</TargetFrameworks>
|
||||
<Version>1.3.17</Version>
|
||||
<Version>1.3.18</Version>
|
||||
<PackageId>BTCPayServer.Lightning.LNBank</PackageId>
|
||||
<Description>Client library for LNBank to build Lightning Network Apps in C#.</Description>
|
||||
<PackageProjectUrl>https://github.com/btcpayserver/BTCPayServer.Lightning</PackageProjectUrl>
|
||||
|
||||
@ -81,13 +81,16 @@ namespace BTCPayServer.Lightning.Tests
|
||||
[Fact(Timeout = Timeout)]
|
||||
public async Task CanCreateInvoiceWithDescriptionHash()
|
||||
{
|
||||
var hashToUse =
|
||||
new uint256(SHA256.Create().ComputeHash(Encoding.UTF8.GetBytes("CanCreateInvoiceWithDescriptionHash")));
|
||||
var expectedHash = new uint256("1d8adbd8794116cfd6044e1d25446685a7c6c750a9e2cec1845acc23656466d1");
|
||||
var create = new CreateInvoiceParams(10000, "CanCreateInvoiceWithDescriptionHash", TimeSpan.FromMinutes(5))
|
||||
{
|
||||
DescriptionHashOnly = true
|
||||
};
|
||||
Assert.Equal(expectedHash, create.DescriptionHash);
|
||||
|
||||
async Task<LightningInvoice> CreateWithHash(ILightningClient lightningClient)
|
||||
{
|
||||
return await lightningClient.CreateInvoice(new CreateInvoiceParams(10000, hashToUse,
|
||||
TimeSpan.FromMinutes(5)));
|
||||
return await lightningClient.CreateInvoice(create);
|
||||
}
|
||||
await WaitServersAreUp();
|
||||
foreach (var client in Tester.GetLightningClients())
|
||||
@ -106,7 +109,7 @@ namespace BTCPayServer.Lightning.Tests
|
||||
var createdInvoiceBOLT = BOLT11PaymentRequest.Parse(createdInvoice.BOLT11, Network.RegTest);
|
||||
var retrievedInvoiceBOLT = BOLT11PaymentRequest.Parse(retrievedInvoice.BOLT11, Network.RegTest);
|
||||
Assert.Equal(createdInvoiceBOLT.PaymentHash, retrievedInvoiceBOLT.PaymentHash);
|
||||
Assert.Equal(hashToUse, createdInvoiceBOLT.DescriptionHash);
|
||||
Assert.Equal(expectedHash, createdInvoiceBOLT.DescriptionHash);
|
||||
break;
|
||||
case LndHubLightningClient _:
|
||||
// Once this gets merged, we can support it too: https://github.com/BlueWallet/LndHub/pull/319
|
||||
|
||||
@ -34,7 +34,7 @@ services:
|
||||
lightningd:
|
||||
restart: unless-stopped
|
||||
stop_signal: SIGKILL
|
||||
image: btcpayserver/lightning:v22.11-dev
|
||||
image: btcpayserver/lightning:v22.11.1-dev
|
||||
environment:
|
||||
EXPOSE_TCP: "true"
|
||||
LIGHTNINGD_NETWORK: regtest
|
||||
@ -47,6 +47,7 @@ services:
|
||||
log-level=debug
|
||||
dev-fast-gossip
|
||||
dev-bitcoind-poll=1
|
||||
database-upgrade=true
|
||||
ports:
|
||||
- "48532:9835" # api port
|
||||
expose:
|
||||
@ -61,7 +62,7 @@ services:
|
||||
lightningd_dest:
|
||||
restart: unless-stopped
|
||||
stop_signal: SIGKILL
|
||||
image: btcpayserver/lightning:v22.11-dev
|
||||
image: btcpayserver/lightning:v22.11.1-dev
|
||||
environment:
|
||||
EXPOSE_TCP: "true"
|
||||
LIGHTNINGD_NETWORK: regtest
|
||||
@ -74,6 +75,7 @@ services:
|
||||
log-level=debug
|
||||
dev-fast-gossip
|
||||
dev-bitcoind-poll=1
|
||||
database-upgrade=true
|
||||
ports:
|
||||
- "42549:9835" # api port
|
||||
expose:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user