public bool CastVoteForPhysician(ParticipantHandler participantHandler, Guid physicianAddress, Guid senderAddress)
        {
            //If the physician has already been confirmed, do nothing
            if (participantHandler.HasPhysician(physicianAddress))
            {
                return(true);
            }
            if (!(participantHandler.proposedPhysicians.Where(p => p.Address == physicianAddress).Count() > 0))
            {
                return(false);
            }

            //If the physician is still proposed
            //Add Vote to list of votes (if not already present from the current sender)
            var votesFromSender = from v in participantHandler.pendingVotes
                                  where v.VoteFor == physicianAddress && v.VoteFrom == senderAddress
                                  select v;

            if (votesFromSender.Count() > 0)
            {
                var hit = votesFromSender.FirstOrDefault();
                hit.Confirmed = true;
            }
            else
            {
                participantHandler.pendingVotes.Add(new Vote()
                {
                    VoteFor = physicianAddress
                    ,
                    VoteFrom = senderAddress
                    ,
                    Confirmed = true
                });
            }

            //Count list of valid votes for physician => Valid votes must be at least 3 in total (or equal to number of confirmed publishers)
            //If publisher is confirmed: Transfer to confirmed publishers, remove all votes from list
            var votesForPhysician = from v in participantHandler.pendingVotes
                                    where v.VoteFor == physicianAddress && v.Confirmed
                                    select v;

            if (votesForPhysician.Count() > 3 || votesForPhysician.Count() == participantHandler.confirmedPublishers.Count())
            {
                var tranfer = participantHandler.proposedPhysicians.Where(p => p.Address == physicianAddress);
                participantHandler.confirmedPhysicians.AddRange(tranfer);
                participantHandler.proposedPhysicians.RemoveAll(p => p.Address == physicianAddress);
                participantHandler.pendingVotes.RemoveAll(v => v.VoteFor == physicianAddress);
            }

            return(true);
        }
        public bool CastVoteAgainstPhysician(ParticipantHandler participantHandler, Guid physicianAddress, Guid senderAddress)
        {
            //If the publisher is not confirmed, do nothing
            if (!participantHandler.HasPhysician(physicianAddress))
            {
                return(false);
            }

            //Add Vote to list of votes (if not already present from the current sender)
            var votesFromSender = from v in participantHandler.pendingVotes
                                  where v.VoteFor == physicianAddress && v.VoteFrom == senderAddress
                                  select v;

            if (votesFromSender.Count() > 0)
            {
                var hit = votesFromSender.FirstOrDefault();
                hit.Confirmed = false;
            }
            else
            {
                participantHandler.pendingVotes.Add(new Vote()
                {
                    VoteFor = physicianAddress
                    ,
                    VoteFrom = senderAddress
                    ,
                    Confirmed = false
                });
            }

            //Count list of valid votes against publisher => Valid votes must be more than half of currently confirmed publishers
            //If publisher is dismissed: Delete from List
            var votesAgainstPhysician = from v in participantHandler.pendingVotes
                                        where v.VoteFor == physicianAddress && !v.Confirmed
                                        select v;

            if (votesAgainstPhysician.Count() > Math.Floor(participantHandler.confirmedPublishers.Count() / 2.0))
            {
                participantHandler.confirmedPhysicians.RemoveAll(p => p.Address == physicianAddress);
                participantHandler.pendingVotes.RemoveAll(v => v.VoteFor == physicianAddress);
            }

            return(true);
        }
Beispiel #3
0
 public override bool ValidateContextual(ParticipantHandler participantHandler, List <Chain> chains)
 {
     return(SenderAddress == TransactionId &&
            ValidateTransactionIntegrity(PublicKey) &&
            !participantHandler.HasPhysician(TransactionId));
 }