public void GetBlock_With_good_Hash_IsValid()
        {
            var requestWithNoHash = new SearchByHashRequest()
            {
                Hash       = "some good hash",
                OutputJson = true
            };

            var validationContext = new ValidationContext(requestWithNoHash);

            Validator.TryValidateObject(requestWithNoHash, validationContext, null, true).Should().BeTrue();
        }
        public IActionResult GetBlock([FromQuery] SearchByHashRequest query)
        {
            if (!this.ModelState.IsValid)
            {
                return(ModelStateErrors.BuildErrorResponse(this.ModelState));
            }

            try
            {
                uint256 blockId = uint256.Parse(query.Hash);

                ChainedHeader chainedHeader = this.chainIndexer.GetHeader(blockId);

                if (chainedHeader == null)
                {
                    return(this.Ok("Block not found"));
                }

                Block block = chainedHeader.Block ?? this.blockStore.GetBlock(blockId);

                // In rare occasions a block that is found in the
                // indexer may not have been pushed to the store yet.
                if (block == null)
                {
                    return(this.Ok("Block not found"));
                }

                if (!query.OutputJson)
                {
                    return(this.Json(block));
                }

                BlockModel blockModel = query.ShowTransactionDetails
                    ? new BlockTransactionDetailsModel(block, chainedHeader, this.chainIndexer.Tip, this.network)
                    : new BlockModel(block, chainedHeader, this.chainIndexer.Tip, this.network);

                if (this.network.Consensus.IsProofOfStake)
                {
                    var posBlock = block as PosBlock;

                    blockModel.PosBlockSignature = posBlock.BlockSignature.ToHex(this.network);
                    blockModel.PosBlockTrust     = new Target(chainedHeader.GetBlockProof()).ToUInt256().ToString();
                    blockModel.PosChainTrust     = chainedHeader.ChainWork.ToString(); // this should be similar to ChainWork
                }

                return(this.Json(blockModel));
            }
            catch (Exception e)
            {
                this.logger.LogError("Exception occurred: {0}", e.ToString());
                return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, e.Message, e.ToString()));
            }
        }