public async Task <IEnumerable <SmartCoin> > QueueCoinsToMixAsync(string password, params SmartCoin[] coins) { using (await MixLock.LockAsync()) { await DequeueCoinsFromMixNoLockAsync(State.GetSpentCoins().ToArray()); var successful = new List <SmartCoin>(); foreach (SmartCoin coin in coins) { if (State.Contains(coin)) { successful.Add(coin); continue; } if (coin.SpentOrCoinJoinInProgress) { continue; } coin.Secret = KeyManager.GetSecrets(password, coin.ScriptPubKey).Single(); OnePiece = OnePiece ?? password; coin.CoinJoinInProgress = true; State.AddCoinToWaitingList(coin); successful.Add(coin); CoinQueued?.Invoke(this, coin); Logger.LogInfo <CcjClient>($"Coin queued: {coin.Index}:{coin.TransactionId}."); } return(successful); } }
public async Task <IEnumerable <SmartCoin> > QueueCoinsToMixAsync(string password, params SmartCoin[] coins) { if (coins is null || !coins.Any() || IsQuitPending) { return(Enumerable.Empty <SmartCoin>()); } var successful = new List <SmartCoin>(); using (await MixLock.LockAsync()) { await DequeueSpentCoinsFromMixNoLockAsync(); // Every time the user enqueues (intentionally writes in password) then the coordinator fee percent must be noted and dequeue later if changes. CcjClientRound latestRound = State.GetLatestRoundOrDefault(); CoordinatorFeepercentToCheck = latestRound?.State?.CoordinatorFeePercent; var except = new List <SmartCoin>(); foreach (SmartCoin coin in coins) { if (State.Contains(coin)) { successful.Add(coin); except.Add(coin); continue; } if (coin.Unavailable) { except.Add(coin); continue; } } var coinsExcept = coins.Except(except); var secPubs = KeyManager.GetSecretsAndPubKeyPairs(password, coinsExcept.Select(x => x.ScriptPubKey).ToArray()); Cook(password); foreach (SmartCoin coin in coinsExcept) { coin.Secret = secPubs.Single(x => x.pubKey.P2wpkhScript == coin.ScriptPubKey).secret; coin.CoinJoinInProgress = true; State.AddCoinToWaitingList(coin); successful.Add(coin); Logger.LogInfo <CcjClient>($"Coin queued: {coin.Index}:{coin.TransactionId}."); } } foreach (var coin in successful) { CoinQueued?.Invoke(this, coin); } return(successful); }