public static SearchResult <Block> SearchForBlock(this IBlockFinder blockFinder, BlockParameter blockParameter, bool allowNulls = false) { Block block; if (blockParameter.RequireCanonical) { block = blockFinder.FindBlock(blockParameter.BlockHash, BlockTreeLookupOptions.RequireCanonical); if (block == null && !allowNulls) { BlockHeader?header = blockFinder.FindHeader(blockParameter.BlockHash); if (header != null) { return(new SearchResult <Block>($"{blockParameter.BlockHash} block is not canonical", ErrorCodes.InvalidInput)); } } } else { block = blockFinder.FindBlock(blockParameter); } if (block == null) { if (blockParameter.Equals(BlockParameter.Finalized) || blockParameter.Equals(BlockParameter.Safe)) { return(new SearchResult <Block>("Unknown block error", ErrorCodes.UnknownBlockError)); } if (!allowNulls) { return(new SearchResult <Block>( $"Block {blockParameter.BlockHash?.ToString() ?? blockParameter.BlockNumber?.ToString() ?? blockParameter.Type.ToString()} could not be found", ErrorCodes.ResourceNotFound)); } } return(new SearchResult <Block>(block)); }