mirror of
https://github.com/aljazceru/BTCPayServerPlugins.git
synced 2025-12-17 07:34:24 +01:00
bump n
This commit is contained in:
@@ -1,48 +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;
|
||||
}
|
||||
}
|
||||
}
|
||||
// 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;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
Reference in New Issue
Block a user