Skip to content

Commit

Permalink
musicbox: how do I set up coordinator menuitem follow up (WalletWasab…
Browse files Browse the repository at this point in the history
  • Loading branch information
MarnixCroes authored Sep 19, 2024
1 parent 705f516 commit b961578
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 21 deletions.
4 changes: 2 additions & 2 deletions WalletWasabi.Daemon/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ public Uri GetBackendUri()
throw new NotSupportedNetworkException(Network);
}

public Uri GetCoordinatorUri()
public Uri? GetCoordinatorUri()
{
var result = Network switch
{
Expand All @@ -260,7 +260,7 @@ public Uri GetCoordinatorUri()
_ => throw new NotSupportedNetworkException(Network)
};

return new Uri(result);
return result is "" ? null : new Uri(result);
}

public IEnumerable<(string ParameterName, string Hint)> GetConfigOptionsMetadata() =>
Expand Down
32 changes: 24 additions & 8 deletions WalletWasabi.Daemon/Global.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,17 @@ public Global(string dataDir, string configFilePath, Config config)

BitcoinStore = new BitcoinStore(IndexStore, AllTransactionStore, mempoolService, smartHeaderChain, blocks);
HttpClientFactory = BuildHttpClientFactory(() => Config.GetBackendUri());
CoordinatorHttpClientFactory = BuildHttpClientFactory(() => Config.GetCoordinatorUri());

if (Config.GetCoordinatorUri() is { } coordinatorUri)
{
CoordinatorHttpClientFactory = BuildHttpClientFactory(() => coordinatorUri);
var prisonForCoordinator = Path.Combine(DataDir, coordinatorUri.Host);
CoinPrison = CoinPrison.CreateOrLoadFromFile(prisonForCoordinator);
}
else
{
CoinPrison = CoinPrison.CreateDummyPrison();
}

HostedServices.Register<UpdateManager>(() => new UpdateManager(TimeSpan.FromDays(1), DataDir, Config.DownloadNewVersion, HttpClientFactory.NewHttpClient(Mode.DefaultCircuit, maximumRedirects: 10), HttpClientFactory.SharedWasabiClient), "Update Manager");
UpdateManager = HostedServices.Get<UpdateManager>();
Expand Down Expand Up @@ -157,8 +167,6 @@ public Global(string dataDir, string configFilePath, Config config)

TransactionBroadcaster = new TransactionBroadcaster(broadcasters.ToArray(), BitcoinStore.MempoolService, WalletManager);

var prisonForCoordinator = Path.Combine(DataDir, config.GetCoordinatorUri().Host);
CoinPrison = CoinPrison.CreateOrLoadFromFile(prisonForCoordinator);
WalletManager.WalletStateChanged += WalletManager_WalletStateChanged;
}

Expand All @@ -178,7 +186,7 @@ public Global(string dataDir, string configFilePath, Config config)
/// <summary>HTTP client factory for sending HTTP requests.</summary>
public WasabiHttpClientFactory HttpClientFactory { get; }

public WasabiHttpClientFactory CoordinatorHttpClientFactory { get; }
public WasabiHttpClientFactory? CoordinatorHttpClientFactory { get; }

public string ConfigFilePath { get; }
public Config Config { get; }
Expand All @@ -197,7 +205,7 @@ public Global(string dataDir, string configFilePath, Config config)
public Network Network => Config.Network;

public IMemoryCache Cache { get; private set; }
public CoinPrison CoinPrison { get; }
private CoinPrison CoinPrison { get; }
public JsonRpcServer? RpcServer { get; private set; }

public Uri? OnionServiceUri { get; private set; }
Expand Down Expand Up @@ -260,7 +268,7 @@ public async Task InitializeNoWalletAsync(bool initializeSleepInhibitor, Termina

await BlockDownloadService.StartAsync(cancel).ConfigureAwait(false);

if (HasCoordinatorConfigured)
if (HasCoordinatorConfigured && CoordinatorHttpClientFactory is not null)
{
RegisterCoinJoinComponents();

Expand Down Expand Up @@ -421,6 +429,11 @@ private void RegisterFeeRateProviders()

private void RegisterCoinJoinComponents()
{
if (CoordinatorHttpClientFactory is null)
{
return;
}

Tor.Http.IHttpClient roundStateUpdaterHttpClient = CoordinatorHttpClientFactory.NewHttpClient(Mode.SingleCircuitPerLifetime, RoundStateUpdaterCircuit);
HostedServices.Register<RoundStateUpdater>(() => new RoundStateUpdater(TimeSpan.FromSeconds(10), new WabiSabiHttpApiClient(roundStateUpdaterHttpClient)), "Round info updater");

Expand Down Expand Up @@ -516,8 +529,11 @@ public async Task DisposeAsync()
Logger.LogInfo($"{nameof(HttpClientFactory)} is disposed.");
}

await CoordinatorHttpClientFactory.DisposeAsync().ConfigureAwait(false);
Logger.LogInfo($"{nameof(CoordinatorHttpClientFactory)} is disposed.");
if (CoordinatorHttpClientFactory is not null)
{
await CoordinatorHttpClientFactory.DisposeAsync().ConfigureAwait(false);
Logger.LogInfo($"{nameof(CoordinatorHttpClientFactory)} is disposed.");
}

if (BitcoinCoreNode is { } bitcoinCoreNode)
{
Expand Down
4 changes: 2 additions & 2 deletions WalletWasabi.Daemon/PersistentConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ public record PersistentConfig

public string RegTestBackendUri { get; init; } = "http://localhost:37127/";

public string MainNetCoordinatorUri { get; init; } = Constants.BackendUri;
public string MainNetCoordinatorUri { get; init; } = "";

public string TestNetCoordinatorUri { get; init; } = Constants.TestnetBackendUri;
public string TestNetCoordinatorUri { get; init; } = "";

public string RegTestCoordinatorUri { get; init; } = "http://localhost:37127/";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,6 @@ public CoinJoinStateViewModel(UiContext uiContext, IWalletModel wallet, IWalletC
}
});

CoordinatorHelpCommand = ReactiveCommand.CreateFromTask(() => UiContext.FileSystem.OpenBrowserAsync("https://www.google.com"));

IsCoinjoinSupported = _wallet.Coinjoin is not null;
}

Expand Down Expand Up @@ -227,8 +225,6 @@ private enum Trigger
public ICommand StopPauseCommand { get; }
public ICommand NavigateToCoordinatorSettingsCommand { get; }

public ICommand CoordinatorHelpCommand { get; }

private void ConfigureStateMachine()
{
_stateMachine.Configure(State.Disabled);
Expand Down
8 changes: 6 additions & 2 deletions WalletWasabi.Fluent/Views/Wallets/MusicControlsView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,19 @@
<PathIcon Data="{StaticResource coordinator}" />
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="How do I setup a coordinator?" Command="{Binding CoordinatorHelpCommand}" />
<MenuItem Header="How do I find and set up a coordinator?" Command="{Binding CoordinatorHelpCommand}" ToolTip.Tip="{Binding FindCoordinatorLink}" >
<MenuItem.Icon>
<PathIcon Data="{StaticResource book_question_mark_regular}" />
</MenuItem.Icon>
</MenuItem>
</MenuFlyout>
</Button.Flyout>
</Button>
<Separator Classes="vertical" DockPanel.Dock="Right" Margin="2.5 0" />

<StackPanel Spacing="4" HorizontalAlignment="Center">
<TextBlock TextAlignment="Center" Text="Coordinator not configured" />
<TextBlock TextAlignment="Center" Text="Coinjoins are disabled" />
<TextBlock TextAlignment="Center" Text="Coinjoin not available" />
</StackPanel>

</DockPanel>
Expand Down
4 changes: 2 additions & 2 deletions WalletWasabi.Tests/UnitTests/Bases/ConfigManagerNgTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ static string GetConfigString(string localBitcoinCoreDataDir)
"MainNetBackendUri": "https://api.wasabiwallet.io/",
"TestNetBackendUri": "https://api.wasabiwallet.co/",
"RegTestBackendUri": "http://localhost:37127/",
"MainNetCoordinatorUri": "https://api.wasabiwallet.io/",
"TestNetCoordinatorUri": "https://api.wasabiwallet.co/",
"MainNetCoordinatorUri": "",
"TestNetCoordinatorUri": "",
"RegTestCoordinatorUri": "http://localhost:37127/",
"UseTor": "Enabled",
"TerminateTorOnExit": false,
Expand Down
7 changes: 6 additions & 1 deletion WalletWasabi/WabiSabi/Client/Banning/CoinPrison.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace WalletWasabi.WabiSabi.Client.Banning;

public class CoinPrison(string filePath, Dictionary<OutPoint, PrisonedCoinRecord> bannedCoins) : IDisposable
public class CoinPrison(string? filePath, Dictionary<OutPoint, PrisonedCoinRecord> bannedCoins) : IDisposable
{
enum BanningStatus
{
Expand Down Expand Up @@ -74,6 +74,11 @@ public static CoinPrison CreateOrLoadFromFile(string containingDirectory)
}
}

public static CoinPrison CreateDummyPrison()
{
return new CoinPrison(null, []);
}

public void UpdateWallet(Wallet wallet)
{
lock (_lock)
Expand Down

0 comments on commit b961578

Please sign in to comment.