public List <MinedBlockInfoResponse> GetBlocks()
        {
            List <MinedBlockInfoResponse> response = dbService.GetAllBlocks().OrderByDescending(b => b.DateCreated)
                                                     .ToList().ConvertAll(b => MinedBlockInfoResponse.FromMinedBlockInfo(b));

            return(response);
        }
        public IActionResult Get(string hash)
        {
            MinedBlockInfoResponse result = _blockchainService.GetBlock(hash);

            if (result != null)
            {
                return(Ok(result));
            }
            return(NotFound());
        }
        public CollectionContext <MinedBlockInfoResponse> GetBlocksCollection(int pageNumber, int pageSize)
        {
            CollectionContext <MinedBlockInfoResponse> response = new CollectionContext <MinedBlockInfoResponse>();

            response.Total = dbService.GetAllBlocks().Count;
            response.Items = dbService.GetAllBlocks().OrderByDescending(b => b.DateCreated)
                             .Skip(pageNumber * pageSize).Take(pageSize).ToList()
                             .ConvertAll(b => MinedBlockInfoResponse.FromMinedBlockInfo(b));
            return(response);
        }
        public MinedBlockInfoResponse GetBlock(string blockHash)
        {
            MinedBlockInfo block = dbService.GetAllBlocks().Where(b => b.BlockHash.Equals(blockHash) ||
                                                                  b.BlockDataHash.Equals(blockHash)).FirstOrDefault();

            if (block != null)
            {
                return(MinedBlockInfoResponse.FromMinedBlockInfo(block));
            }
            return(null);
        }
        private void PropagateBlockToPeers(MinedBlockInfo block)
        {
            var tasks = new List <Task>();
            var body  = new NewBlockNotification
            {
                LastBlock = MinedBlockInfoResponse.FromMinedBlockInfo(block),
                Sender    = thisPeer
            };

            dbService.GetPeers().ForEach(p =>
            {
                tasks.Add(Task.Run(() =>
                                   HttpUtils.DoApiPost <NewBlockNotification, object>(p.Url, NOTIFY_API_PATH, body)));
            });

            Task.WaitAll(tasks.ToArray());
        }
 public MinedBlockInfoResponse GetBlock(int index)
 {
     return(MinedBlockInfoResponse.FromMinedBlockInfo(dbService.GetAllBlocks()[index]));
 }