public async Task <HistoryBlock> AddHistoryBlockToChainAsync(int chainId, HistoryBlock block) { if (await chainReadService.IsChainValidAsync(chainId)) { var chain = await chainReadRepository.GetByIdAsync(chainId); var blocks = await historyBlockReadRepository.GetBlocksByChainIdAsync(chainId); block.ChainId = chainId; if (blocks?.Count > 0) { var lastBlock = await historyBlockReadRepository.GetByIdAsync(chain.LastBlockId.Value); block.PreviousHash = lastBlock.Hash; } var newBlock = await historyBlockWriteRepository.AddAsync(block); //reload chain chain = await chainReadRepository.GetByIdAsync(chainId); chain.LastBlockId = newBlock.Id; await chainWriteRepository.UpdateAsync(chain); return(newBlock); } return(null); }
public Task <Chain> GetChainByIdAsync(int chainId) { var result = chainReadRepository.GetByIdAsync(chainId); return(result); }