Implement errors for calling stuff the wrong time
MODIFY
WalletWasabi/Wallets/Wallet.cs
WalletWasabi/Wallets/Wallet.cs
@@ -79,6 +79,11 @@ namespace WalletWasabi.Wallets
IFeeProvider feeProvider,
CoreNode coreNode = null)
{
+ if (State != WalletState.Uninitialized)
+ {
+ throw new InvalidOperationException($"{nameof(State)} must be {WalletState.Uninitialized}. Current state: {State}.");
+ }
+
BitcoinStore = Guard.NotNull(nameof(bitcoinStore), bitcoinStore);
Nodes = Guard.NotNull(nameof(nodes), nodes);
Synchronizer = Guard.NotNull(nameof(syncer), syncer);
@@ -159,7 +164,11 @@ namespace WalletWasabi.Wallets
/// <inheritdoc/>
public override async Task StartAsync(CancellationToken cancel)
{
- var prevState = State;
+ if (State != WalletState.Initialized)
+ {
+ throw new InvalidOperationException($"{nameof(State)} must be {WalletState.Initialized}. Current state: {State}.");
+ }
+
try
{
State = WalletState.Starting;
@@ -198,7 +207,7 @@ namespace WalletWasabi.Wallets
}
catch
{
- State = prevState;
+ State = WalletState.Initialized;
throw;
}
finally

MODIFY
WalletWasabi/Wallets/WalletManager.cs
WalletWasabi/Wallets/WalletManager.cs
@@ -146,11 +146,6 @@ namespace WalletWasabi.Wallets
{
Guard.NotNull(nameof(wallet), wallet);
- if (wallet.State == WalletState.Starting)
- {
- return wallet;
- }
-
using (await StartStopWalletLock.LockAsync(CancelAllInitialization.Token).ConfigureAwait(false))
{
try

Implement errors for calling stuff the wrong time