2020-06-29 04:44:35 +02:00
|
|
|
using System;
|
2018-07-22 11:38:14 +02:00
|
|
|
using System.Collections.Concurrent;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using NBitcoin;
|
|
|
|
|
|
|
|
namespace BTCPayServer.Services
|
|
|
|
{
|
|
|
|
public class LightningConfigurationProvider
|
|
|
|
{
|
2020-06-29 05:07:48 +02:00
|
|
|
readonly ConcurrentDictionary<ulong, (DateTimeOffset expiration, LightningConfigurations config)> _Map = new ConcurrentDictionary<ulong, (DateTimeOffset expiration, LightningConfigurations config)>();
|
2018-07-23 04:53:39 +02:00
|
|
|
public ulong KeepConfig(ulong secret, LightningConfigurations configuration)
|
2018-07-22 11:38:14 +02:00
|
|
|
{
|
|
|
|
CleanExpired();
|
|
|
|
_Map.AddOrReplace(secret, (DateTimeOffset.UtcNow + TimeSpan.FromMinutes(10), configuration));
|
|
|
|
return secret;
|
|
|
|
}
|
|
|
|
|
|
|
|
public LightningConfigurations GetConfig(ulong secret)
|
|
|
|
{
|
|
|
|
CleanExpired();
|
|
|
|
if (!_Map.TryGetValue(secret, out var value))
|
|
|
|
return null;
|
|
|
|
return value.config;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void CleanExpired()
|
|
|
|
{
|
2018-12-20 08:52:04 +01:00
|
|
|
foreach (var item in _Map)
|
2018-07-22 11:38:14 +02:00
|
|
|
{
|
2018-12-20 08:52:04 +01:00
|
|
|
if (item.Value.expiration < DateTimeOffset.UtcNow)
|
2018-07-22 11:38:14 +02:00
|
|
|
{
|
|
|
|
_Map.TryRemove(item.Key, out var unused);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public class LightningConfigurations
|
|
|
|
{
|
2018-12-07 11:31:07 +01:00
|
|
|
public List<object> Configurations { get; set; } = new List<object>();
|
2018-07-22 11:38:14 +02:00
|
|
|
}
|
2018-12-20 08:52:04 +01:00
|
|
|
|
|
|
|
public class LNDConfiguration
|
2018-07-22 11:38:14 +02:00
|
|
|
{
|
2018-08-12 09:19:18 +02:00
|
|
|
public string ChainType { get; set; }
|
2018-07-22 11:38:14 +02:00
|
|
|
public string Type { get; set; }
|
|
|
|
public string CryptoCode { get; set; }
|
2018-12-20 08:52:04 +01:00
|
|
|
public string CertificateThumbprint { get; set; }
|
|
|
|
public string Macaroon { get; set; }
|
|
|
|
public string AdminMacaroon { get; set; }
|
|
|
|
public string ReadonlyMacaroon { get; set; }
|
|
|
|
public string InvoiceMacaroon { get; set; }
|
|
|
|
}
|
|
|
|
public class LightningConfiguration : LNDConfiguration
|
|
|
|
{
|
2018-07-22 11:38:14 +02:00
|
|
|
public string Host { get; set; }
|
|
|
|
public int Port { get; set; }
|
|
|
|
public bool SSL { get; set; }
|
|
|
|
}
|
2018-12-20 08:52:04 +01:00
|
|
|
public class LNDRestConfiguration : LNDConfiguration
|
2018-12-07 11:31:07 +01:00
|
|
|
{
|
|
|
|
public string Uri { get; set; }
|
|
|
|
}
|
2018-07-22 11:38:14 +02:00
|
|
|
}
|