diff --git a/api/resolver.py b/api/resolver.py index 42ed670c4..b17cd2a80 100644 --- a/api/resolver.py +++ b/api/resolver.py @@ -35,6 +35,7 @@ from flask_crossdomain import crossdomain from time import time from blockstack_proofs import profile_to_proofs, profile_v3_to_proofs +import blockstack_zones import blockstack from blockstack.lib.schemas import OP_NAME_PATTERN, OP_NAMESPACE_PATTERN @@ -145,6 +146,14 @@ def format_profile(profile, fqa, zone_file, address, public_key): 1) Insert verifications 2) Check if profile data is valid JSON """ + + # if the zone file is a string, then parse it + if isinstance(zone_file, (str,unicode)): + try: + zone_file = blockstack_zones.parse_zone_file(zone_file) + except: + # leave as text + pass data = {'profile' : profile, 'zone_file' : zone_file, @@ -178,8 +187,12 @@ def get_profile(fqa): fqa = fqa.lower() try: - res = blockstack.lib.client.resolve_profile( - fqa, include_name_record=True, hostport=blockstack_indexer_url) + try: + res = blockstack.lib.client.resolve_profile( + fqa, include_name_record=True, hostport=blockstack_indexer_url) + except ValueError: + # invalid name + res = {'error': 'Invalid name', 'status_code': 400} if 'error' in res: log.error('Error from profile.get_profile: {}'.format(res['error'])) @@ -187,6 +200,12 @@ def get_profile(fqa): res['status_code'] = 404 if "Failed to load user profile" in res['error']: res['status_code'] = 404 + + if res.get('http_status'): + # pass along + res['status_code'] = res['http_status'] + del res['http_status'] + return res log.warn(json.dumps(res['name_record'])) diff --git a/api/search/fetch_data.py b/api/search/fetch_data.py index 119b6b262..37cfc8a12 100644 --- a/api/search/fetch_data.py +++ b/api/search/fetch_data.py @@ -255,6 +255,27 @@ if __name__ == "__main__": option = sys.argv[1] + # wait for blockstack-core to come alive + # wait for up to an hour + start_time = time.time() + alive = False + while time.time() < start_time + 3600: + info_resp = {} + try: + info_resp = blockstack.lib.client.getinfo(hostport=blockstack_indexer_url) + assert 'error' not in info_resp + alive = True + break + except: + if 'error' in info_resp: + time.sleep(5.0) + continue + else: + raise + + if not alive: + raise Exception("Could not contact blockstack-core") + if(option == '--fetch_namespace'): # Step 1 fetch_namespace() diff --git a/api/server.py b/api/server.py index 56e54a244..3c2468612 100644 --- a/api/server.py +++ b/api/server.py @@ -56,20 +56,6 @@ blockstack_indexer_url = blockstack_config['blockstack-api']['indexer_url'] log = virtualchain.get_logger() -""" -# starting internal API logic should go somewhere else -# local_api_start(password='temptemptemp') - -# Check first if API daemon is running -status = local_api_action('status') - -if(status): - log.debug("API daemon is running") -else: - log.debug("Start API daemon first") - exit(0) -""" - # Import app from . import app @@ -167,9 +153,7 @@ def catch_all_post(path): @app.route('/') @cache_control(10*60) def index(): - current_dir = os.path.abspath(os.path.dirname(__file__)) server_info = blockstack.lib.client.getinfo(hostport=blockstack_indexer_url) - return render_template('index.html', server_info=server_info, server_url=PUBLIC_NODE_URL)