Skip to content
Permalink
Browse files

Make roundId unique

Resolves #803
  • Loading branch information...
nopara73 committed Nov 10, 2018
1 parent d0cd699 commit 303b5d2e95ace186567a3ee2a8711b9b7410b769
Showing with 34 additions and 1 deletion.
  1. +1 −1 WalletWasabi/Models/ChaumianCoinJoin/CcjRound.cs
  2. +33 −0 WalletWasabi/Services/CcjCoordinator.cs
@@ -14,7 +14,7 @@ namespace WalletWasabi.Models.ChaumianCoinJoin
{
public class CcjRound
{
private static long RoundCount = 0; // First time initializes (so the first constructor will increment it and we'll start from 1.)
public static long RoundCount;
public long RoundId { get; }

public RPCClient RpcClient { get; }
@@ -112,6 +112,27 @@ public CcjCoordinator(Network network, string folderPath, RPCClient rpc, CcjRoun
File.Delete(CoinJoinsFilePath);
}
}

try
{
string roundCountFilePath = Path.Combine(folderPath, "RoundCount.txt");
if (File.Exists(roundCountFilePath))
{
string roundCount = File.ReadAllText(roundCountFilePath);
CcjRound.RoundCount = long.Parse(roundCount);
}
else
{
// First time initializes (so the first constructor will increment it and we'll start from 1.)
CcjRound.RoundCount = 0;
}
}
catch (Exception ex)
{
CcjRound.RoundCount = 0;
Logger.LogInfo<CcjCoordinator>($"{nameof(CcjRound.RoundCount)} file was corrupt. Resetting to 0.");
Logger.LogDebug<CcjCoordinator>(ex);
}
}

public async Task ProcessBlockAsync(Block block)
@@ -347,6 +368,18 @@ protected virtual void Dispose(bool disposing)
round.StatusChanged -= Round_StatusChangedAsync;
round.CoinJoinBroadcasted -= Round_CoinJoinBroadcasted;
}

try
{
string roundCountFilePath = Path.Combine(FolderPath, "RoundCount.txt");

IoHelpers.EnsureContainingDirectoryExists(roundCountFilePath);
File.WriteAllText(roundCountFilePath, CcjRound.RoundCount.ToString());
}
catch (Exception ex)
{
Logger.LogDebug<CcjCoordinator>(ex);
}
}
}

0 comments on commit 303b5d2

Please sign in to comment.
You can’t perform that action at this time.