public async Task <ActionResult> GetBlockByHash(string hash, int noTxList = 1) { if (!Validations.IsValidHash(hash)) { return(BadRequest(hash + " is not a valid block hash")); } Utils.CheckIfChainIsFresh(chain_, config_.AcceptStaleRequests); string key = "block" + noTxList + hash; if (memoryCache_.TryGetValue(key, out JsonResult cachedBlockJson)) { return(cachedBlockJson); } ; var binaryHash = Binary.HexStringToByteArray(hash); using (DisposableApiCallResult <GetBlockHeaderByHashTxSizeResult> getBlockResult = await chain_.FetchBlockHeaderByHashTxSizesAsync(binaryHash)) { Utils.CheckBitprimApiErrorCode(getBlockResult.ErrorCode, "FetchBlockHeaderByHashTxSizesAsync(" + hash + ") failed, check error log"); var getLastHeightResult = await chain_.FetchLastHeightAsync(); Utils.CheckBitprimApiErrorCode(getLastHeightResult.ErrorCode, "FetchLastHeightAsync() failed, check error log"); var blockHeight = getBlockResult.Result.Header.BlockHeight; ApiCallResult <GetBlockHashTimestampResult> getNextBlockResult = null; if (blockHeight != getLastHeightResult.Result) { getNextBlockResult = await chain_.FetchBlockByHeightHashTimestampAsync(blockHeight + 1); Utils.CheckBitprimApiErrorCode(getNextBlockResult.ErrorCode, "FetchBlockByHeightHashTimestampAsync(" + blockHeight + 1 + ") failed, check error log"); } decimal blockReward; PoolInfo poolInfo; using (DisposableApiCallResult <GetTxDataResult> coinbase = await chain_.FetchTransactionAsync(getBlockResult.Result.TransactionHashes[0], true)) { Utils.CheckBitprimApiErrorCode(coinbase.ErrorCode, "FetchTransactionAsync(" + getBlockResult.Result.TransactionHashes[0] + ") failed, check error log"); blockReward = Utils.SatoshisToCoinUnits(coinbase.Result.Tx.TotalOutputValue); poolInfo = poolsInfo_.GetPoolInfo(coinbase.Result.Tx); } JsonResult blockJson = Json(BlockToJSON ( getBlockResult.Result.Header.BlockData, blockHeight, getBlockResult.Result.TransactionHashes, blockReward, getLastHeightResult.Result, getNextBlockResult?.Result.BlockHash, getBlockResult.Result.SerializedBlockSize, poolInfo, noTxList == 0) ); memoryCache_.Set(key, blockJson, new MemoryCacheEntryOptions { Size = Constants.Cache.BLOCK_CACHE_ENTRY_SIZE }); return(blockJson); } }