Logging
This commit is contained in:
parent
5d349cf5f4
commit
6b69a4373b
@ -1,4 +1,5 @@
|
||||
using FASTER.core;
|
||||
using Nostr.Client.Json;
|
||||
using Nostr.Client.Keys;
|
||||
using Nostr.Client.Messages;
|
||||
using Nostr.Client.Requests;
|
||||
@ -11,18 +12,21 @@ namespace PayForReactions;
|
||||
|
||||
public class ZapperRelay : INostrRelay, IDisposable
|
||||
{
|
||||
private readonly ILogger<ZapperRelay> _logger;
|
||||
private readonly Config _config;
|
||||
private readonly Lnurl _lnurl;
|
||||
private readonly AlbyApi _albyApi;
|
||||
private readonly NostrServicesClient _nostrServices;
|
||||
private readonly EventSession _session;
|
||||
|
||||
public ZapperRelay(Lnurl lnurl, AlbyApi albyApi, NostrServicesClient nostrServices, Config config, NostrStore store)
|
||||
public ZapperRelay(Lnurl lnurl, AlbyApi albyApi, NostrServicesClient nostrServices, Config config, NostrStore store,
|
||||
ILogger<ZapperRelay> logger)
|
||||
{
|
||||
_lnurl = lnurl;
|
||||
_albyApi = albyApi;
|
||||
_nostrServices = nostrServices;
|
||||
_config = config;
|
||||
_logger = logger;
|
||||
_session = store.MainStore.For(new SimpleFunctions<byte[], byte[]>()).NewSession<SimpleFunctions<byte[], byte[]>>();
|
||||
}
|
||||
|
||||
@ -44,6 +48,7 @@ public class ZapperRelay : INostrRelay, IDisposable
|
||||
var id = Convert.FromHexString(ev.Id!);
|
||||
var obj = NostrBuf.Encode(ev);
|
||||
(await _session.UpsertAsync(ref id, ref obj)).Complete();
|
||||
_logger.LogInformation("Got targets event, saving {ev}", NostrJson.Serialize(ev));
|
||||
return new(true, "");
|
||||
}
|
||||
|
||||
@ -96,6 +101,7 @@ public class ZapperRelay : INostrRelay, IDisposable
|
||||
$"blocked: so sad... couldn't send a zap because you don't have a lightning address in your profile {senderProfile.Name}!");
|
||||
}
|
||||
|
||||
_logger.LogInformation("Starting payment for {name} - {addr}", senderProfile.Name, senderProfile.LightningAddress);
|
||||
var svc = await _lnurl.LoadAsync(parsedTarget.ToString());
|
||||
if (svc == default)
|
||||
{
|
||||
@ -124,6 +130,7 @@ public class ZapperRelay : INostrRelay, IDisposable
|
||||
return new(false, $"blocked: failed to get invoice from {parsedTarget}");
|
||||
}
|
||||
|
||||
_logger.LogInformation("Paying invoice {pr}", invoice.Pr);
|
||||
if (!await _albyApi.PayInvoice(invoice.Pr))
|
||||
{
|
||||
return new(false, "blocked: failed to pay invoice!");
|
||||
@ -132,6 +139,7 @@ public class ZapperRelay : INostrRelay, IDisposable
|
||||
var seenEvent = NostrBuf.Encode(ev);
|
||||
(await _session.UpsertAsync(ref seenId, ref seenEvent)).Complete();
|
||||
|
||||
_logger.LogInformation("Zapped {name}!", senderProfile.Name);
|
||||
return new(true, "Zapped!");
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user