public bool ValidateContextual(ParticipantHandler participantHandler, List <Chain> context) { var blockIsValid = true; //Handle initializing block if (Index == 0) { blockIsValid &= TransactionList.Count() == 2; var registration = (from t in TransactionList where t.GetType() == typeof(PublisherRegistrationTransaction) select(PublisherRegistrationTransaction) t).FirstOrDefault(); var vote = (from t in TransactionList where t.GetType() == typeof(VotingTransaction) select(VotingTransaction) t).FirstOrDefault(); blockIsValid &= registration != null && vote != null; blockIsValid &= ValidateBlockIntegrity(registration.PublicKey); blockIsValid &= participantHandler.ProcessTransaction(registration, context); blockIsValid &= participantHandler.ProcessTransaction(vote, context); } //Handle new Publisher registration else if (TransactionList.Count() == 1 && TransactionList[0].GetType() == typeof(PublisherRegistrationTransaction)) { var registration = (PublisherRegistrationTransaction)TransactionList[0]; blockIsValid &= ValidateBlockIntegrity(registration.PublicKey); blockIsValid &= participantHandler.ProcessTransaction(registration, context); } //Handle regular block else if (participantHandler.HasPublisher(Publisher)) { blockIsValid &= ValidateBlockIntegrity(participantHandler.GetPublisherKey(Publisher)); foreach (var t in TransactionList) { if (t.GetType() == typeof(PhysicianRegistrationTransaction)) { PhysicianRegistrationTransaction temp = (PhysicianRegistrationTransaction)t; blockIsValid &= temp.ValidateTransactionIntegrity(temp.PublicKey); blockIsValid &= participantHandler.ProcessTransaction(temp, context); } else if (participantHandler.HasSender(t.SenderAddress)) { blockIsValid &= t.ValidateTransactionIntegrity(participantHandler.GetSenderKey(t.SenderAddress)); blockIsValid &= participantHandler.ProcessTransaction(t, context); } else { blockIsValid = false; } } } //Fallback - Block definitely invalid else { blockIsValid = false; } return(blockIsValid); }