BTCPayWallet should be singleton per cryptcode

This commit is contained in:
nicolas.dorier
2018-02-15 15:17:12 +09:00
parent 335dd9e66d
commit c3684eb064
2 changed files with 10 additions and 5 deletions

View File

@@ -102,6 +102,7 @@ namespace BTCPayServer.Services.Wallets
public void InvalidateCache(DerivationStrategyBase strategy)
{
_MemoryCache.Remove("CACHEDCOINS_" + strategy.ToString());
_FetchingUTXOs.TryRemove(strategy.ToString(), out var unused);
}
ConcurrentDictionary<string, TaskCompletionSource<UTXOChanges>> _FetchingUTXOs = new ConcurrentDictionary<string, TaskCompletionSource<UTXOChanges>>();

View File

@@ -21,8 +21,15 @@ namespace BTCPayServer.Services.Wallets
_Client = client;
_NetworkProvider = networkProvider;
_Options = memoryCacheOption;
foreach(var network in networkProvider.GetAll())
{
_Wallets.Add(network.CryptoCode, new BTCPayWallet(_Client.GetExplorerClient(network.CryptoCode), new MemoryCache(_Options), network));
}
}
Dictionary<string, BTCPayWallet> _Wallets = new Dictionary<string, BTCPayWallet>();
public BTCPayWallet GetWallet(BTCPayNetwork network)
{
if (network == null)
@@ -33,11 +40,8 @@ namespace BTCPayServer.Services.Wallets
{
if (cryptoCode == null)
throw new ArgumentNullException(nameof(cryptoCode));
var network = _NetworkProvider.GetNetwork(cryptoCode);
var client = _Client.GetExplorerClient(cryptoCode);
if (network == null || client == null)
return null;
return new BTCPayWallet(client, new MemoryCache(_Options), network);
_Wallets.TryGetValue(cryptoCode, out var result);
return result;
}
public bool IsAvailable(BTCPayNetwork network)