<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def default_blockstack_api_opts(working_dir, config_file=None):
 """ Get our default blockstack RESTful API opts from a config file, or from sane defaults. """


   from .util import url_to_host_port, url_protocol

   if config_file is None:
      config_file = virtualchain.get_config_filename(get_default_virtualchain_impl(), working_dir)

   parser = SafeConfigParser()
   parser.read(config_file)

   blockstack_api_opts = {}
   indexer_url = None
   api_port = DEFAULT_API_PORT
   api_host = DEFAULT_API_HOST
   run_api = True

   if parser.has_section('blockstack-api'):
      if parser.has_option('blockstack-api', 'enabled'):
          run_api = parser.get('blockstack-api', 'enabled').lower() in ['true', '1', 'on']

      if parser.has_option('blockstack-api', 'api_port'):
          api_port = int(parser.get('blockstack-api', 'api_port'))

      if parser.has_option('blockstack-api', 'api_host'):
          api_host = parser.get('blockstack-api', 'api_host')

      if parser.has_option('blockstack-api', 'indexer_url'):
          indexer_host, indexer_port = url_to_host_port(parser.get('blockstack-api', 'indexer_url'))
          indexer_protocol = url_protocol(parser.get('blockstack-api', 'indexer_url'))
          if indexer_protocol is None:
              indexer_protocol = 'http'

          indexer_url = parser.get('blockstack-api', 'indexer_url')

   if indexer_url is None:
       # try defaults
       indexer_url = 'http://localhost:{}'.format(RPC_SERVER_PORT)

   blockstack_api_opts = {
        'indexer_url': indexer_url,
        'api_host': api_host,
        'api_port': api_port,
        'enabled': run_api
   }

   # strip Nones
   for (k, v) in blockstack_api_opts.items():
      if v is None:
         del blockstack_api_opts[k]

   return blockstack_api_opts