Example #1
0
        public async Task Vote(List <Vote> votes, string privateKey)
        {
            Wallet wallet = new Wallet(privateKey);

            foreach (var vote in votes)
            {
                var election =
                    await _commonContext.Elections.SingleOrDefaultAsync(e => e.Address == vote.ElectionAddress);

                if (election == null)
                {
                    throw new NotFoundException("election");
                }

                if (election.Status == ElectionStatus.Closed)
                {
                    throw new ValidationException($"election {election.Address} It is finished");
                }
            }

            foreach (var vote in votes)
            {
                Transaction transaction =
                    await _walletService.CreateTransaction(wallet, vote.ElectionAddress, vote.Candidate);

                _p2PNetwork.BroadcastTransaction(transaction);
            }
        }
Example #2
0
        public async Task Vote(List <Vote> votes, string privateKey)
        {
            Wallet wallet = new Wallet(privateKey);

            foreach (var vote in votes)
            {
                Transaction transaction =
                    await _walletService.CreateTransaction(wallet, vote.ElectionAddress, vote.Candidate);

                _p2PNetwork.BroadcastTransaction(transaction);
            }
        }