Remember parsed target
This commit is contained in:
@ -1,4 +1,5 @@
|
|||||||
using FASTER.core;
|
using FASTER.core;
|
||||||
|
using Microsoft.Extensions.Caching.Memory;
|
||||||
using Nostr.Client.Json;
|
using Nostr.Client.Json;
|
||||||
using Nostr.Client.Keys;
|
using Nostr.Client.Keys;
|
||||||
using Nostr.Client.Messages;
|
using Nostr.Client.Messages;
|
||||||
@ -13,6 +14,7 @@ namespace PayForReactions;
|
|||||||
public class ZapperRelay : INostrRelay, IDisposable
|
public class ZapperRelay : INostrRelay, IDisposable
|
||||||
{
|
{
|
||||||
private readonly ILogger<ZapperRelay> _logger;
|
private readonly ILogger<ZapperRelay> _logger;
|
||||||
|
private readonly IMemoryCache _cache;
|
||||||
private readonly Config _config;
|
private readonly Config _config;
|
||||||
private readonly Lnurl _lnurl;
|
private readonly Lnurl _lnurl;
|
||||||
private readonly AlbyApi _albyApi;
|
private readonly AlbyApi _albyApi;
|
||||||
@ -20,13 +22,14 @@ public class ZapperRelay : INostrRelay, IDisposable
|
|||||||
private readonly EventSession _session;
|
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)
|
ILogger<ZapperRelay> logger, IMemoryCache cache)
|
||||||
{
|
{
|
||||||
_lnurl = lnurl;
|
_lnurl = lnurl;
|
||||||
_albyApi = albyApi;
|
_albyApi = albyApi;
|
||||||
_nostrServices = nostrServices;
|
_nostrServices = nostrServices;
|
||||||
_config = config;
|
_config = config;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
|
_cache = cache;
|
||||||
_session = store.MainStore.For(new SimpleFunctions<byte[], byte[]>()).NewSession<SimpleFunctions<byte[], byte[]>>();
|
_session = store.MainStore.For(new SimpleFunctions<byte[], byte[]>()).NewSession<SimpleFunctions<byte[], byte[]>>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,6 +111,15 @@ public class ZapperRelay : INostrRelay, IDisposable
|
|||||||
return new(false, "blocked: wallet is down, no zap for you!");
|
return new(false, "blocked: wallet is down, no zap for you!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var keyEventWalletSeen = $"zapaped:{refEvent.Id}:{parsedTarget}";
|
||||||
|
var eventWalletZapTry = _cache.Get<int>(keyEventWalletSeen);
|
||||||
|
if (eventWalletZapTry > 0)
|
||||||
|
{
|
||||||
|
return new(false, $"blocked: hey i already zapped you! (count={eventWalletZapTry}");
|
||||||
|
}
|
||||||
|
|
||||||
|
_cache.Set(keyEventWalletSeen, ++eventWalletZapTry);
|
||||||
|
|
||||||
var key = NostrPrivateKey.FromBech32(_config.PrivateKey);
|
var key = NostrPrivateKey.FromBech32(_config.PrivateKey);
|
||||||
var myPubkey = key.DerivePublicKey().Hex;
|
var myPubkey = key.DerivePublicKey().Hex;
|
||||||
var zap = new NostrEvent
|
var zap = new NostrEvent
|
||||||
|
Reference in New Issue
Block a user