public Block(Database.Block block, IEnumerable <EncryptedMessage> messages) { BlockHash = block.BlockHash; BlockHashPrevious = string.IsNullOrEmpty(block.BlockHashPrevious) ? string.Empty : block.BlockHashPrevious; Timestamp = block.Timestamp; Nonce = block.Nonce; Length = block.Length; Messages = block.BlockMessages .Where(b => b.EncryptedMessageStore != null) .Select(bm => new EncryptedMessage(bm.EncryptedMessageStore)); }
public bool Handle(AddBlockQuery query) { if (query.IsLongRunning) { _applicationDatabase.Database.SetCommandTimeout(new TimeSpan(1, 0, 0)); } try { var dbNewBlock = new Database.Block() { BlockHash = query.NewBlock.BlockHash, BlockHashPrevious = query.NewBlock.BlockHashPrevious, Length = query.NewBlock.Length, Nonce = query.NewBlock.Nonce, Timestamp = query.NewBlock.Timestamp }; _applicationDatabase.BlockChain.AddAsync(dbNewBlock); _applicationDatabase.SaveChanges(); foreach (var bm in query.NewBlock.Messages) { var msg = _applicationDatabase.Messages.Single(e => e.Id == bm.Id); _applicationDatabase.BlockMessages.Add(new BlockMessages() { StoreId = msg.StoreId, BlockHash = dbNewBlock.BlockHash }); } _applicationDatabase.SaveChanges(); return(true); } catch (Exception ex) { Console.WriteLine("AddBlockQueryHandler: {0} \n{1}", ex.Message, ex.StackTrace); return(false); } }