mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2024-11-20 02:28:31 +01:00
ba165ddd4f
* wip * Local GreenField Client for Plugins * support notification handlers being missing * Initial support for scoped btcpay client * test out scoped local client * wip * small fix * Throw exception if using local greenfield client and it has not been implemented yet * adapt based on new changes in BTCPay * update * fix tests * Allow Local client to bypass authorization handler * Add Misc endpoints to Local API Client * Add new endpoints * Apply code review changes
93 lines
4.3 KiB
C#
93 lines
4.3 KiB
C#
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
|
|
{
|
|
public virtual async Task<LightningNodeInformationData> GetLightningNodeInfo(string storeId, string cryptoCode,
|
|
CancellationToken token = default)
|
|
{
|
|
var response = await _httpClient.SendAsync(
|
|
CreateHttpRequest($"api/v1/stores/{storeId}/lightning/{cryptoCode}/info",
|
|
method: HttpMethod.Get), token);
|
|
return await HandleResponse<LightningNodeInformationData>(response);
|
|
}
|
|
|
|
public virtual async Task ConnectToLightningNode(string storeId, string cryptoCode, ConnectToNodeRequest request,
|
|
CancellationToken token = default)
|
|
{
|
|
if (request == null)
|
|
throw new ArgumentNullException(nameof(request));
|
|
var response = await _httpClient.SendAsync(
|
|
CreateHttpRequest($"api/v1/stores/{storeId}/lightning/{cryptoCode}/connect", bodyPayload: request,
|
|
method: HttpMethod.Post), token);
|
|
await HandleResponse(response);
|
|
}
|
|
|
|
public virtual async Task<IEnumerable<LightningChannelData>> GetLightningNodeChannels(string storeId, string cryptoCode,
|
|
CancellationToken token = default)
|
|
{
|
|
var response = await _httpClient.SendAsync(
|
|
CreateHttpRequest($"api/v1/stores/{storeId}/lightning/{cryptoCode}/channels",
|
|
method: HttpMethod.Get), token);
|
|
return await HandleResponse<IEnumerable<LightningChannelData>>(response);
|
|
}
|
|
|
|
public virtual async Task OpenLightningChannel(string storeId, string cryptoCode, OpenLightningChannelRequest request,
|
|
CancellationToken token = default)
|
|
{
|
|
var response = await _httpClient.SendAsync(
|
|
CreateHttpRequest($"api/v1/stores/{storeId}/lightning/{cryptoCode}/channels", bodyPayload: request,
|
|
method: HttpMethod.Post), token);
|
|
await HandleResponse(response);
|
|
}
|
|
|
|
public virtual async Task<string> GetLightningDepositAddress(string storeId, string cryptoCode,
|
|
CancellationToken token = default)
|
|
{
|
|
var response = await _httpClient.SendAsync(
|
|
CreateHttpRequest($"api/v1/stores/{storeId}/lightning/{cryptoCode}/address", method: HttpMethod.Post),
|
|
token);
|
|
return await HandleResponse<string>(response);
|
|
}
|
|
|
|
public virtual async Task PayLightningInvoice(string storeId, string cryptoCode, PayLightningInvoiceRequest request,
|
|
CancellationToken token = default)
|
|
{
|
|
if (request == null)
|
|
throw new ArgumentNullException(nameof(request));
|
|
var response = await _httpClient.SendAsync(
|
|
CreateHttpRequest($"api/v1/stores/{storeId}/lightning/{cryptoCode}/invoices/pay", bodyPayload: request,
|
|
method: HttpMethod.Post), token);
|
|
await HandleResponse(response);
|
|
}
|
|
|
|
public virtual async Task<LightningInvoiceData> GetLightningInvoice(string storeId, string cryptoCode,
|
|
string invoiceId, CancellationToken token = default)
|
|
{
|
|
if (invoiceId == null)
|
|
throw new ArgumentNullException(nameof(invoiceId));
|
|
var response = await _httpClient.SendAsync(
|
|
CreateHttpRequest($"api/v1/stores/{storeId}/lightning/{cryptoCode}/invoices/{invoiceId}",
|
|
method: HttpMethod.Get), token);
|
|
return await HandleResponse<LightningInvoiceData>(response);
|
|
}
|
|
|
|
public virtual async Task<LightningInvoiceData> CreateLightningInvoice(string storeId, string cryptoCode,
|
|
CreateLightningInvoiceRequest request, CancellationToken token = default)
|
|
{
|
|
if (request == null)
|
|
throw new ArgumentNullException(nameof(request));
|
|
var response = await _httpClient.SendAsync(
|
|
CreateHttpRequest($"api/v1/stores/{storeId}/lightning/{cryptoCode}/invoices", bodyPayload: request,
|
|
method: HttpMethod.Post), token);
|
|
return await HandleResponse<LightningInvoiceData>(response);
|
|
}
|
|
}
|
|
}
|