private void MintBlock(List <Transaction> transactions, Chain chain) { var hashes = new HashSet <Hash>(transactions.Select(tx => tx.Hash)); var lastBlockHash = chain.GetLastBlockHash(); var lastBlock = chain.GetBlockByHash(lastBlockHash); var isFirstBlock = lastBlock == null; var protocol = (uint)Nexus.GetGovernanceValue(Nexus.RootStorage, Nexus.NexusProtocolVersionTag); while (hashes.Count > 0) { var block = new Block(isFirstBlock ? 1 : (lastBlock.Height + 1), chain.Address, Timestamp.Now, hashes, isFirstBlock ? Hash.Null : lastBlock.Hash, protocol); try { chain.BakeBlock(ref block, ref transactions, MinimumFee, _validatorKeys, Timestamp.Now); chain.AddBlock(block, transactions, MinimumFee); } catch (InvalidTransactionException e) { var tx = transactions.First(x => x.Hash == e.Hash); Interlocked.Decrement(ref _size); hashes.Remove(e.Hash); lock (_rejections) { _rejections[e.Hash] = e.Message; } transactions.Remove(tx); OnTransactionFailed?.Invoke(tx); continue; } lock (_entries) { foreach (var tx in transactions) { _pendingSet.Remove(tx.Hash); } } foreach (var tx in transactions) { Interlocked.Decrement(ref _size); OnTransactionCommitted?.Invoke(tx); } break; } lock (_pendingBlocks) { _pendingBlocks.Remove(chain); } }
public void Can_publish_comment_notifications() { var ws = new InMemWorkspace(); int numberOfSentNotifications = 0; using (var context = GetDomainContext(ws)) using (var scope = new TransactionScope()) { //register a handler for CommentNotifications, in this test, increase a local variable to //hold the number of sent CommentNotifications context.MessageBus.RegisterHandler <RepliedToPostEvent>(MessageHandlerType.Synchronous, commentCreated => OnTransactionCommitted.Invoke(() => numberOfSentNotifications++), false); var post = new Post(); post.Edit("AOP for dummies", "..."); post.Publish(); post.EnableComments(); //pass the DomainEvent container to the method so we can raise domain events in the current context. post.ReplyTo("Roger Alsing", "*****@*****.**", "http://www.rogeralsing.com", "Hi there"); //ensure that no comment notifications have been processed yet Assert.AreEqual(0, numberOfSentNotifications); ws.Commit(); scope.Complete(); } //ensure that one comment notification have been processed Assert.AreEqual(1, numberOfSentNotifications); }