Remember parsed target
This commit is contained in:
parent
6b69a4373b
commit
f6f5473b6b
@ -1,4 +1,5 @@
|
||||
using FASTER.core;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using Nostr.Client.Json;
|
||||
using Nostr.Client.Keys;
|
||||
using Nostr.Client.Messages;
|
||||
@ -13,6 +14,7 @@ namespace PayForReactions;
|
||||
public class ZapperRelay : INostrRelay, IDisposable
|
||||
{
|
||||
private readonly ILogger<ZapperRelay> _logger;
|
||||
private readonly IMemoryCache _cache;
|
||||
private readonly Config _config;
|
||||
private readonly Lnurl _lnurl;
|
||||
private readonly AlbyApi _albyApi;
|
||||
@ -20,13 +22,14 @@ public class ZapperRelay : INostrRelay, IDisposable
|
||||
private readonly EventSession _session;
|
||||
|
||||
public ZapperRelay(Lnurl lnurl, AlbyApi albyApi, NostrServicesClient nostrServices, Config config, NostrStore store,
|
||||
ILogger<ZapperRelay> logger)
|
||||
ILogger<ZapperRelay> logger, IMemoryCache cache)
|
||||
{
|
||||
_lnurl = lnurl;
|
||||
_albyApi = albyApi;
|
||||
_nostrServices = nostrServices;
|
||||
_config = config;
|
||||
_logger = logger;
|
||||
_cache = cache;
|
||||
_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!");
|
||||
}
|
||||
|
||||
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 myPubkey = key.DerivePublicKey().Hex;
|
||||
var zap = new NostrEvent
|
||||
|
Loading…
x
Reference in New Issue
Block a user