2020-05-29 02:00:13 +02:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Net.Http;
|
|
|
|
using System.Threading;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using BTCPayServer.Client.Models;
|
|
|
|
|
|
|
|
namespace BTCPayServer.Client
|
|
|
|
{
|
|
|
|
public partial class BTCPayServerClient
|
|
|
|
{
|
2021-07-27 14:11:47 +02:00
|
|
|
public virtual async Task<LightningNodeInformationData> GetLightningNodeInfo(string cryptoCode,
|
2020-05-29 02:00:13 +02:00
|
|
|
CancellationToken token = default)
|
|
|
|
{
|
|
|
|
var response = await _httpClient.SendAsync(
|
|
|
|
CreateHttpRequest($"api/v1/server/lightning/{cryptoCode}/info",
|
|
|
|
method: HttpMethod.Get), token);
|
|
|
|
return await HandleResponse<LightningNodeInformationData>(response);
|
|
|
|
}
|
|
|
|
|
2021-07-27 14:11:47 +02:00
|
|
|
public virtual async Task ConnectToLightningNode(string cryptoCode, ConnectToNodeRequest request,
|
2020-05-29 02:00:13 +02:00
|
|
|
CancellationToken token = default)
|
|
|
|
{
|
|
|
|
if (request == null)
|
|
|
|
throw new ArgumentNullException(nameof(request));
|
|
|
|
var response = await _httpClient.SendAsync(
|
|
|
|
CreateHttpRequest($"api/v1/server/lightning/{cryptoCode}/connect", bodyPayload: request,
|
|
|
|
method: HttpMethod.Post), token);
|
2020-06-08 16:40:58 +02:00
|
|
|
await HandleResponse(response);
|
2020-05-29 02:00:13 +02:00
|
|
|
}
|
|
|
|
|
2021-07-27 14:11:47 +02:00
|
|
|
public virtual async Task<IEnumerable<LightningChannelData>> GetLightningNodeChannels(string cryptoCode,
|
2020-05-29 02:00:13 +02:00
|
|
|
CancellationToken token = default)
|
|
|
|
{
|
|
|
|
var response = await _httpClient.SendAsync(
|
|
|
|
CreateHttpRequest($"api/v1/server/lightning/{cryptoCode}/channels",
|
|
|
|
method: HttpMethod.Get), token);
|
|
|
|
return await HandleResponse<IEnumerable<LightningChannelData>>(response);
|
|
|
|
}
|
|
|
|
|
2021-07-27 14:11:47 +02:00
|
|
|
public virtual async Task OpenLightningChannel(string cryptoCode, OpenLightningChannelRequest request,
|
2020-05-29 02:00:13 +02:00
|
|
|
CancellationToken token = default)
|
|
|
|
{
|
|
|
|
var response = await _httpClient.SendAsync(
|
|
|
|
CreateHttpRequest($"api/v1/server/lightning/{cryptoCode}/channels", bodyPayload: request,
|
|
|
|
method: HttpMethod.Post), token);
|
2021-07-27 14:11:47 +02:00
|
|
|
await HandleResponse(response);
|
2020-05-29 02:00:13 +02:00
|
|
|
}
|
|
|
|
|
2021-07-27 14:11:47 +02:00
|
|
|
public virtual async Task<string> GetLightningDepositAddress(string cryptoCode, CancellationToken token = default)
|
2020-05-29 02:00:13 +02:00
|
|
|
{
|
|
|
|
var response = await _httpClient.SendAsync(
|
|
|
|
CreateHttpRequest($"api/v1/server/lightning/{cryptoCode}/address", method: HttpMethod.Post), token);
|
|
|
|
return await HandleResponse<string>(response);
|
|
|
|
}
|
|
|
|
|
2022-02-17 10:01:39 +01:00
|
|
|
public virtual async Task<LightningPaymentData> PayLightningInvoice(string cryptoCode, PayLightningInvoiceRequest request,
|
2020-05-29 02:00:13 +02:00
|
|
|
CancellationToken token = default)
|
|
|
|
{
|
|
|
|
if (request == null)
|
|
|
|
throw new ArgumentNullException(nameof(request));
|
|
|
|
var response = await _httpClient.SendAsync(
|
2020-06-08 16:40:58 +02:00
|
|
|
CreateHttpRequest($"api/v1/server/lightning/{cryptoCode}/invoices/pay", bodyPayload: request,
|
2020-05-29 02:00:13 +02:00
|
|
|
method: HttpMethod.Post), token);
|
2022-02-17 10:01:39 +01:00
|
|
|
return await HandleResponse<LightningPaymentData>(response);
|
2020-05-29 02:00:13 +02:00
|
|
|
}
|
|
|
|
|
2021-07-27 14:11:47 +02:00
|
|
|
public virtual async Task<LightningInvoiceData> GetLightningInvoice(string cryptoCode,
|
2020-05-29 02:00:13 +02:00
|
|
|
string invoiceId, CancellationToken token = default)
|
|
|
|
{
|
|
|
|
if (invoiceId == null)
|
|
|
|
throw new ArgumentNullException(nameof(invoiceId));
|
|
|
|
var response = await _httpClient.SendAsync(
|
|
|
|
CreateHttpRequest($"api/v1/server/lightning/{cryptoCode}/invoices/{invoiceId}",
|
|
|
|
method: HttpMethod.Get), token);
|
|
|
|
return await HandleResponse<LightningInvoiceData>(response);
|
|
|
|
}
|
|
|
|
|
2021-07-27 14:11:47 +02:00
|
|
|
public virtual async Task<LightningInvoiceData> CreateLightningInvoice(string cryptoCode, CreateLightningInvoiceRequest request,
|
2020-05-29 02:00:13 +02:00
|
|
|
CancellationToken token = default)
|
|
|
|
{
|
|
|
|
if (request == null)
|
|
|
|
throw new ArgumentNullException(nameof(request));
|
|
|
|
var response = await _httpClient.SendAsync(
|
|
|
|
CreateHttpRequest($"api/v1/server/lightning/{cryptoCode}/invoices", bodyPayload: request,
|
|
|
|
method: HttpMethod.Post), token);
|
|
|
|
return await HandleResponse<LightningInvoiceData>(response);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|