public IEnumerable <PollResult> CalculateResults(long pollId) { var poll = _dataAccessService.GetEcPoll(pollId, true, true); Dictionary <byte[], PollResult> votes = new Dictionary <byte[], PollResult>(new Byte32EqualityComparer()); foreach (var candidate in poll.Candidates) { byte[] assetId = candidate.AssetId.HexStringToByteArray(); byte[] commitment = ConfidentialAssetsHelper.GetNonblindedAssetCommitment(assetId); votes.Add(commitment, new PollResult { Candidate = _translatorsRepository.GetInstance <EcCandidateRecord, Candidate>().Translate(candidate), Votes = 0 }); } foreach (var vote in poll.PollSelections.Where(s => !string.IsNullOrEmpty(s.VoterBlindingFactor))) { byte[] ecCommitment = vote.EcCommitment.HexStringToByteArray(); byte[] ecBf = vote.EcBlindingFactor.HexStringToByteArray(); byte[] voterBf = vote.VoterBlindingFactor.HexStringToByteArray(); byte[] bf = ConfidentialAssetsHelper.SumScalars(ecBf, voterBf); byte[] blindingPoint = ConfidentialAssetsHelper.GetPublicKey(bf); byte[] commitment = ConfidentialAssetsHelper.SubCommitments(ecCommitment, blindingPoint); if (votes.ContainsKey(commitment)) { votes[commitment].Votes++; } } return(votes.Select(d => d.Value)); }