feat: zap2boost

This commit is contained in:
2024-01-13 20:07:27 +00:00
parent fb3559eb84
commit d1cb619316
16 changed files with 630 additions and 35 deletions

View File

@ -0,0 +1,45 @@
using System.Net.Http.Headers;
using Newtonsoft.Json;
namespace PayForReactions;
public class AlbyApi
{
private readonly HttpClient _client;
public AlbyApi(HttpClient client, Config config)
{
_client = client;
_client.BaseAddress = new("https://api.getalby.com");
_client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(config.Alby.Type, config.Alby.Token);
}
public async Task<long> GetBalance()
{
var json = await _client.GetStringAsync("/balance");
var obj = JsonConvert.DeserializeObject<BalanceResponse>(json);
return (long?)obj?.Balance ?? 0L;
}
public async Task<bool> PayInvoice(string pr)
{
var rsp = await _client.PostAsync("/payments/bolt11", new StringContent(JsonConvert.SerializeObject(new
{
invoice = pr
}), new MediaTypeHeaderValue("application/json")));
return rsp.IsSuccessStatusCode;
}
class BalanceResponse
{
[JsonProperty("balance")]
public decimal Balance { get; init; }
[JsonProperty("currency")]
public string Currency { get; init; } = "BTC";
[JsonProperty("unit")]
public string Unit { get; init; } = "sat";
}
}