Skip to content

Commit fd90ba2

Browse files
committed
Replace connection in Monero RPC Provider
1 parent 4c41d31 commit fd90ba2

1 file changed

Lines changed: 10 additions & 11 deletions

File tree

Plugins/Monero/Services/MoneroRPCProvider.cs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
using BTCPayServer.Plugins.Monero.RPC;
99
using BTCPayServer.Plugins.Monero.RPC.Models;
1010

11+
using Monero.Common;
12+
1113
using NBitcoin;
1214

1315
namespace BTCPayServer.Plugins.Monero.Services
@@ -16,12 +18,9 @@ public class MoneroRPCProvider
1618
{
1719
private readonly MoneroLikeConfiguration _moneroLikeConfiguration;
1820
private readonly EventAggregator _eventAggregator;
19-
public ImmutableDictionary<string, JsonRpcClient> DaemonRpcClients;
20-
public ImmutableDictionary<string, JsonRpcClient> WalletRpcClients;
21-
22-
private readonly ConcurrentDictionary<string, MoneroLikeSummary> _summaries = new();
23-
24-
public ConcurrentDictionary<string, MoneroLikeSummary> Summaries => _summaries;
21+
public ImmutableDictionary<string, MoneroRpcConnection> DaemonRpcClients;
22+
public ImmutableDictionary<string, MoneroRpcConnection> WalletRpcClients;
23+
public ConcurrentDictionary<string, MoneroLikeSummary> Summaries { get; } = new();
2524

2625
public MoneroRPCProvider(MoneroLikeConfiguration moneroLikeConfiguration,
2726
EventAggregator eventAggregator,
@@ -31,19 +30,19 @@ public MoneroRPCProvider(MoneroLikeConfiguration moneroLikeConfiguration,
3130
_eventAggregator = eventAggregator;
3231
DaemonRpcClients =
3332
_moneroLikeConfiguration.MoneroLikeConfigurationItems.ToImmutableDictionary(pair => pair.Key,
34-
pair => new JsonRpcClient(pair.Value.DaemonRpcUri, pair.Value.Username, pair.Value.Password,
33+
pair => new MoneroRpcConnection(pair.Value.DaemonRpcUri, pair.Value.Username, pair.Value.Password,
3534
httpClientFactory.CreateClient($"{pair.Key}client")));
3635
WalletRpcClients =
3736
_moneroLikeConfiguration.MoneroLikeConfigurationItems.ToImmutableDictionary(pair => pair.Key,
38-
pair => new JsonRpcClient(pair.Value.InternalWalletRpcUri, "", "",
37+
pair => new MoneroRpcConnection(pair.Value.InternalWalletRpcUri, "", "",
3938
httpClientFactory.CreateClient($"{pair.Key}client")));
4039
}
4140

4241
public bool IsConfigured(string cryptoCode) => WalletRpcClients.ContainsKey(cryptoCode) && DaemonRpcClients.ContainsKey(cryptoCode);
4342
public bool IsAvailable(string cryptoCode)
4443
{
4544
cryptoCode = cryptoCode.ToUpperInvariant();
46-
return _summaries.ContainsKey(cryptoCode) && IsAvailable(_summaries[cryptoCode]);
45+
return Summaries.ContainsKey(cryptoCode) && IsAvailable(Summaries[cryptoCode]);
4746
}
4847

4948
private bool IsAvailable(MoneroLikeSummary summary)
@@ -90,9 +89,9 @@ public async Task<MoneroLikeSummary> UpdateSummary(string cryptoCode)
9089
summary.WalletAvailable = false;
9190
}
9291

93-
var changed = !_summaries.ContainsKey(cryptoCode) || IsAvailable(cryptoCode) != IsAvailable(summary);
92+
var changed = !Summaries.ContainsKey(cryptoCode) || IsAvailable(cryptoCode) != IsAvailable(summary);
9493

95-
_summaries.AddOrReplace(cryptoCode, summary);
94+
Summaries.AddOrReplace(cryptoCode, summary);
9695
if (changed)
9796
{
9897
_eventAggregator.Publish(new MoneroDaemonStateChange() { Summary = summary, CryptoCode = cryptoCode });

0 commit comments

Comments
 (0)