2018-02-26 00:48:12 +09:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace BTCPayServer.Payments.Lightning
|
|
|
|
|
{
|
|
|
|
|
public class LightningSupportedPaymentMethod : ISupportedPaymentMethod
|
|
|
|
|
{
|
|
|
|
|
public string CryptoCode { get; set; }
|
2018-06-23 23:16:39 -05:00
|
|
|
|
public PaymentMethodId PaymentId => new PaymentMethodId(CryptoCode, PaymentTypes.LightningLike);
|
|
|
|
|
|
2018-03-21 00:31:19 +09:00
|
|
|
|
[Obsolete("Use Get/SetLightningUrl")]
|
2018-02-26 00:48:12 +09:00
|
|
|
|
public string LightningChargeUrl { get; set; }
|
|
|
|
|
|
2018-06-23 23:16:39 -05:00
|
|
|
|
[Obsolete("Use Get/SetLightningUrl")]
|
|
|
|
|
public string Username { get; set; }
|
|
|
|
|
[Obsolete("Use Get/SetLightningUrl")]
|
|
|
|
|
public string Password { get; set; }
|
|
|
|
|
|
|
|
|
|
[Obsolete("Use Get/SetLightningUrl")]
|
|
|
|
|
public string Macaroon { get; set; }
|
|
|
|
|
[Obsolete("Use Get/SetLightningUrl")]
|
|
|
|
|
public string Tls { get; set; }
|
|
|
|
|
|
2018-03-21 00:31:19 +09:00
|
|
|
|
public LightningConnectionString GetLightningUrl()
|
2018-02-26 00:48:12 +09:00
|
|
|
|
{
|
|
|
|
|
#pragma warning disable CS0618 // Type or member is obsolete
|
2018-03-21 00:31:19 +09:00
|
|
|
|
var fullUri = new UriBuilder(LightningChargeUrl) { UserName = Username, Password = Password }.Uri.AbsoluteUri;
|
|
|
|
|
if(!LightningConnectionString.TryParse(fullUri, out var connectionString, out var error))
|
2018-02-26 00:48:12 +09:00
|
|
|
|
{
|
2018-03-21 00:31:19 +09:00
|
|
|
|
throw new FormatException(error);
|
2018-02-26 00:48:12 +09:00
|
|
|
|
}
|
2018-06-23 23:16:39 -05:00
|
|
|
|
connectionString.Macaroon = Macaroon;
|
|
|
|
|
connectionString.Tls = Tls;
|
2018-03-21 00:31:19 +09:00
|
|
|
|
return connectionString;
|
2018-02-26 00:48:12 +09:00
|
|
|
|
#pragma warning restore CS0618 // Type or member is obsolete
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-21 00:31:19 +09:00
|
|
|
|
public void SetLightningUrl(LightningConnectionString connectionString)
|
2018-02-26 00:48:12 +09:00
|
|
|
|
{
|
2018-03-21 00:31:19 +09:00
|
|
|
|
if (connectionString == null)
|
|
|
|
|
throw new ArgumentNullException(nameof(connectionString));
|
|
|
|
|
|
2018-02-26 00:48:12 +09:00
|
|
|
|
#pragma warning disable CS0618 // Type or member is obsolete
|
2018-03-21 00:31:19 +09:00
|
|
|
|
Username = connectionString.Username;
|
|
|
|
|
Password = connectionString.Password;
|
2018-06-23 23:16:39 -05:00
|
|
|
|
Macaroon = connectionString.Macaroon;
|
|
|
|
|
Tls = connectionString.Tls;
|
|
|
|
|
|
2018-03-21 00:31:19 +09:00
|
|
|
|
LightningChargeUrl = connectionString.BaseUri.AbsoluteUri;
|
2018-02-26 00:48:12 +09:00
|
|
|
|
#pragma warning restore CS0618 // Type or member is obsolete
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|