//Returns whether or not the chain has been added to the blockchain public bool OnReceiveChain(Chain chain) { var success = false; var transactions = chain.GetTransactions(); manipulateBufferedTransactions.WaitOne(); manipulateChain.WaitOne(); var participantHandler_Clone = participantHandler.Clone(); success = chain.ValidateContextual(participantHandler_Clone, new List <Chain>() { this.chain }); if (success) { var deletedBlocks = this.chain.Add(chain); var bufferedTransactions = transactionBuffer.Peek().GetTransactions(); var receivedTransaction = chain.GetTransactions(); foreach (var b in deletedBlocks) { foreach (var t in b.TransactionList) { if (!bufferedTransactions.Where(bt => bt.TransactionId == t.TransactionId).Any() || !receivedTransaction.Where(rt => rt.TransactionId == t.TransactionId).Any()) { transactionBuffer.RecordTransaction(t); } } } var transactionsToUnbuffer = bufferedTransactions.Where(t => receivedTransaction.Where(rt => rt.TransactionId == t.TransactionId).Any()); foreach (var t in transactionsToUnbuffer) { transactionBuffer.UnrecordTransaction(t); } participantHandler = new ParticipantHandler(); this.chain.ProcessContracts(participantHandler, new List <Chain>() { }); participantHandler_Buffered = participantHandler.Clone(); transactionBuffer.Peek().ProcessContracts(participantHandler_Buffered, new List <Chain>() { this.chain }); } manipulateChain.Release(); manipulateBufferedTransactions.Release(); CLI.DisplayLine("Added " + transactions.Count + " transactions " + (success ? "successfully" : "unsuccessfully")); foreach (var t in transactions) { CLI.DisplayLine("\t" + t.AsString()); } return(success); }