add nwc and bump nostr

This commit is contained in:
Kukks
2024-05-08 08:35:27 +02:00
parent 6e95ddb8b1
commit 3db5b5537d
10 changed files with 717 additions and 8 deletions

View File

@@ -0,0 +1,48 @@
using System;
using System.Threading;
using NNostr.Client;
namespace BTCPayServer.Plugins.NIP05;
public class NostrClientWrapper : IDisposable
{
public INostrClient Client { get; private set; }
private int _usageCount = 0;
private bool _isDisposed = false;
private DateTimeOffset _lastUsed;
public NostrClientWrapper(INostrClient client)
{
Client = client;
_lastUsed = DateTimeOffset.UtcNow;
}
public void IncrementUsage()
{
_lastUsed = DateTimeOffset.UtcNow;
Interlocked.Increment(ref _usageCount);
}
public void DecrementUsage()
{
_lastUsed = DateTimeOffset.UtcNow;
if (Interlocked.Decrement(ref _usageCount) == 0 && IsExpired())
{
Dispose();
}
}
public bool IsExpired()
{
return DateTimeOffset.UtcNow - _lastUsed > TimeSpan.FromMinutes(5);
}
public void Dispose()
{
if (!_isDisposed)
{
Client.Dispose();
_isDisposed = true;
}
}
}