Move Rpc plumbing to WalletWasabi libr project
MODIFY
WalletWasabi.Fluent/Global.cs
WalletWasabi.Fluent/Global.cs
@@ -17,13 +17,12 @@ using WalletWasabi.Blockchain.Mempool;
using WalletWasabi.Blockchain.TransactionBroadcasting;
using WalletWasabi.Blockchain.Transactions;
using WalletWasabi.CoinJoin.Client;
-using WalletWasabi.Fluent.Models;
-using WalletWasabi.Fluent.Rpc;
using WalletWasabi.Helpers;
using WalletWasabi.Logging;
using WalletWasabi.Services;
using WalletWasabi.Services.Terminate;
using WalletWasabi.Stores;
+using WalletWasabi.Rpc;
using WalletWasabi.Tor;
using WalletWasabi.Tor.Socks5.Pool.Circuits;
using WalletWasabi.WabiSabi.Client;
@@ -207,10 +206,11 @@ namespace WalletWasabi.Fluent
private async Task StartRpcServerAsync(TerminateService terminateService, CancellationToken cancel)
{
- var jsonRpcServerConfig = new JsonRpcServerConfiguration(Config);
+ var jsonRpcServerConfig = new JsonRpcServerConfiguration(Config.JsonRpcServerEnabled, Config.JsonRpcUser, Config.JsonRpcPassword, Config.JsonRpcServerPrefixes);
if (jsonRpcServerConfig.IsEnabled)
{
- RpcServer = new JsonRpcServer(this, jsonRpcServerConfig, terminateService);
+ var wasabiJsonRpcService = new Rpc.WasabiJsonRpcService(this, terminateService);
+ RpcServer = new JsonRpcServer(wasabiJsonRpcService, jsonRpcServerConfig);
try
{
await RpcServer.StartAsync(cancel).ConfigureAwait(false);

DELETE
WalletWasabi.Fluent/Models/JsonRpcServerConfiguration.cs
-namespace WalletWasabi.Fluent.Models
-{
- public class JsonRpcServerConfiguration
- {
- private Config _config;
-
- public JsonRpcServerConfiguration(Config config)
- {
- _config = config;
- }
-
- public bool IsEnabled => _config.JsonRpcServerEnabled;
- public string JsonRpcUser => _config.JsonRpcUser;
- public string JsonRpcPassword => _config.JsonRpcPassword;
- public string[] Prefixes => _config.JsonRpcServerPrefixes;
-
- public bool RequiresCredentials => !string.IsNullOrEmpty(JsonRpcUser) && !string.IsNullOrEmpty(JsonRpcPassword);
- }
-}

MODIFY
WalletWasabi.Fluent/Rpc/WasabiJsonRpcService.cs
WalletWasabi.Fluent/Rpc/WasabiJsonRpcService.cs
@@ -8,12 +8,13 @@ using WalletWasabi.Blockchain.TransactionBuilding;
using WalletWasabi.Blockchain.Transactions;
using WalletWasabi.Helpers;
using WalletWasabi.Models;
+using WalletWasabi.Rpc;
using WalletWasabi.Services.Terminate;
using WalletWasabi.Wallets;
namespace WalletWasabi.Fluent.Rpc
{
- public partial class WasabiJsonRpcService
+ public class WasabiJsonRpcService : IJsonRpcService
{
public WasabiJsonRpcService(Global global, TerminateService terminateService)
{

MODIFY
WalletWasabi.Tests/RpcTests.cs
WalletWasabi.Tests/RpcTests.cs
@@ -3,7 +3,7 @@ using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Newtonsoft.Json;
-using WalletWasabi.Fluent.Rpc;
+using WalletWasabi.Rpc;
using Xunit;
namespace WalletWasabi.Tests

MODIFY
WalletWasabi.Tests/TestableRpcService.cs
WalletWasabi.Tests/TestableRpcService.cs
using System.Threading;
using System.Threading.Tasks;
-using WalletWasabi.Fluent.Rpc;
+using WalletWasabi.Rpc;
namespace WalletWasabi.Tests
{

ADD
WalletWasabi/Rpc/IJsonRpcService.cs
+namespace WalletWasabi.Rpc
+{
+ public interface IJsonRpcService
+ {
+ }
+}

RENAME
WalletWasabi.Fluent/Rpc/JsonRpcErrorCodes.cs
WalletWasabi/Rpc/JsonRpcErrorCodes.cs
-namespace WalletWasabi.Fluent.Rpc
+namespace WalletWasabi.Rpc
{
public enum JsonRpcErrorCodes
{

RENAME
WalletWasabi.Fluent/Rpc/JsonRpcMethodAttribute.cs
WalletWasabi/Rpc/JsonRpcMethodAttribute.cs
-namespace WalletWasabi.Fluent.Rpc
+namespace WalletWasabi.Rpc
{
/// <summary>
/// Class used to decorate service methods and map them with their rpc method name.

RENAME
WalletWasabi.Fluent/Rpc/JsonRpcMethodMetadata.cs
WalletWasabi/Rpc/JsonRpcMethodMetadata.cs
using System.Collections.Generic;
using System.Reflection;
-namespace WalletWasabi.Fluent.Rpc
+namespace WalletWasabi.Rpc
{
/// <summary>
/// Represents the collection of metadata needed to execute the remote procedure.

RENAME
WalletWasabi.Fluent/Rpc/JsonRpcRequest.cs
WalletWasabi/Rpc/JsonRpcRequest.cs
@@ -2,7 +2,7 @@ using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Diagnostics.CodeAnalysis;
-namespace WalletWasabi.Fluent.Rpc
+namespace WalletWasabi.Rpc
{
/// <summary>
/// A rpc call is represented by sending a Request object to a Server. The Request object has the following members:

RENAME
WalletWasabi.Fluent/Rpc/JsonRpcRequestHandler.cs
WalletWasabi/Rpc/JsonRpcRequestHandler.cs
@@ -7,7 +7,7 @@ using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using WalletWasabi.JsonConverters;
-namespace WalletWasabi.Fluent.Rpc
+namespace WalletWasabi.Rpc
{
/// <summary>
/// This class coordinates all the major steps in processing the RPC call.
@@ -33,7 +33,7 @@ namespace WalletWasabi.Fluent.Rpc
public JsonRpcRequestHandler(TService service)
{
Service = service;
- MetadataProvider = new JsonRpcServiceMetadataProvider(typeof(TService));
+ MetadataProvider = new JsonRpcServiceMetadataProvider(service.GetType());
}
private TService Service { get; }

RENAME
WalletWasabi.Fluent/Rpc/JsonRpcResponse.cs
WalletWasabi/Rpc/JsonRpcResponse.cs
using System.Collections.Generic;
using Newtonsoft.Json;
-namespace WalletWasabi.Fluent.Rpc
+namespace WalletWasabi.Rpc
{
public class JsonRpcResponse
{

RENAME
WalletWasabi.Fluent/Rpc/JsonRpcServer.cs
WalletWasabi/Rpc/JsonRpcServer.cs
@@ -5,14 +5,12 @@ using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Hosting;
using WalletWasabi.Logging;
-using WalletWasabi.Fluent.Models;
-using WalletWasabi.Services.Terminate;
-namespace WalletWasabi.Fluent.Rpc
+namespace WalletWasabi.Rpc
{
public class JsonRpcServer : BackgroundService
{
- public JsonRpcServer(Global global, JsonRpcServerConfiguration config, TerminateService terminateService)
+ public JsonRpcServer(IJsonRpcService service, JsonRpcServerConfiguration config)
{
Config = config;
Listener = new HttpListener();
@@ -21,11 +19,11 @@ namespace WalletWasabi.Fluent.Rpc
{
Listener.Prefixes.Add(prefix);
}
- Service = new WasabiJsonRpcService(global, terminateService);
+ Service = service;
}
private HttpListener Listener { get; }
- private WasabiJsonRpcService Service { get; }
+ private IJsonRpcService Service { get; }
private JsonRpcServerConfiguration Config { get; }
public override async Task StartAsync(CancellationToken cancellationToken)
@@ -42,7 +40,7 @@ namespace WalletWasabi.Fluent.Rpc
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
- var handler = new JsonRpcRequestHandler<WasabiJsonRpcService>(Service);
+ var handler = new JsonRpcRequestHandler<IJsonRpcService>(Service);
while (!stoppingToken.IsCancellationRequested)
{

ADD
WalletWasabi/Rpc/JsonRpcServerConfiguration.cs
+namespace WalletWasabi.Rpc
+{
+ public class JsonRpcServerConfiguration
+ {
+ public JsonRpcServerConfiguration(bool enabled, string jsonRpcUser, string jsonRpcPassword, string[] prefixes)
+ {
+ IsEnabled = enabled;
+ JsonRpcUser = jsonRpcUser;
+ JsonRpcPassword = jsonRpcPassword;
+ Prefixes = prefixes;
+ }
+
+ public bool IsEnabled { get; }
+ public string JsonRpcUser { get; }
+ public string JsonRpcPassword { get; }
+ public string[] Prefixes { get; }
+
+ public bool RequiresCredentials => !string.IsNullOrEmpty(JsonRpcUser) && !string.IsNullOrEmpty(JsonRpcPassword);
+ }
+}

RENAME
WalletWasabi.Fluent/Rpc/JsonRpcService.cs
WalletWasabi/Rpc/JsonRpcService.cs
@@ -2,7 +2,7 @@ using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
-namespace WalletWasabi.Fluent.Rpc
+namespace WalletWasabi.Rpc
{
/// <summary>
/// Base class for service classes.

RENAME
WalletWasabi.Fluent/Rpc/PaymentInfo.cs
WalletWasabi/Rpc/PaymentInfo.cs
using NBitcoin;
-namespace WalletWasabi.Fluent.Rpc
+namespace WalletWasabi.Rpc
{
public class PaymentInfo
{

Move Rpc plumbing to WalletWasabi libr project