//[ProducesResponseType(typeof(void), 401)] public async Task <IActionResult> GetBlockAsync(string id, [FromQuery] BlockQueryRequest query) { if (!this.ModelState.IsValid) { return(ModelStateErrors.BuildErrorResponse(this.ModelState)); } ChainedHeader chainHeader = null; if (string.IsNullOrWhiteSpace(id)) { throw new ArgumentNullException("id", "id must be block hash or block height"); } // If the id is more than 50 characters, it is likely hash and not height. if (id.Length < 50) { chainHeader = this.chain.GetHeader(int.Parse(id)); } else { chainHeader = this.chain.GetHeader(new uint256(id)); } if (chainHeader == null) { return(new NotFoundObjectResult("Block not found")); } try { BlockStake blockStake = this.stakeChain.Get(chainHeader.HashBlock); Block block = this.blockStoreCache.GetBlock(chainHeader.Header.GetHash()); if (block == null) { return(new NotFoundObjectResult("Block not found")); } PosBlockModel blockModel = new PosBlockModel(block, this.chain); if (blockStake != null) { blockModel.StakeTime = blockStake.StakeTime; blockModel.StakeModifierV2 = blockStake.StakeModifierV2; blockModel.HashProof = blockStake.HashProof; } return(this.Json(blockModel)); } catch (Exception e) { this.logger.LogError("Exception occurred: {0}", e.ToString()); return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, e.Message, e.ToString())); } }
public async Task <IActionResult> GetBlocksPageAsync(int index, [FromQuery] BlockQueryRequest query) { if (!this.ModelState.IsValid) { return(ModelStateErrors.BuildErrorResponse(this.ModelState)); } throw new NotImplementedException("Not implemented"); }
//[ProducesResponseType(typeof(void), 401)] public async Task <IActionResult> GetBlockAsync(string id, [FromQuery] BlockQueryRequest query) { if (!this.ModelState.IsValid) { return(ModelStateErrors.BuildErrorResponse(this.ModelState)); } ChainedHeader chainHeader = null; if (string.IsNullOrWhiteSpace(id)) { throw new ArgumentNullException("id", "id must be block hash or block height"); } // If the id is more than 50 characters, it is likely hash and not height. if (id.Length < 50) { chainHeader = this.chain.GetBlock(int.Parse(id)); } else { chainHeader = this.chain.GetBlock(new uint256(id)); } try { Block block = await this.blockStoreCache.GetBlockAsync(chainHeader.Header.GetHash()).ConfigureAwait(false); if (block == null) { return(new NotFoundObjectResult("Block not found")); } V2.Models.BlockModel blockModel = new V2.Models.BlockModel(block, chainHeader.Height, this.network); return(this.Json(blockModel)); } catch (Exception e) { this.logger.LogError("Exception occurred: {0}", e.ToString()); return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, e.Message, e.ToString())); } }