From d4fc632a7ded3c4fe48c4e95e9aaf827ce2e733f Mon Sep 17 00:00:00 2001 From: Muneeb Ali Date: Tue, 22 Jul 2014 00:30:14 -0700 Subject: [PATCH] renamed file plus other updates to ons resolver --- blockstack_cli_0.14.1/opendig/ons_resolver.py | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 blockstack_cli_0.14.1/opendig/ons_resolver.py diff --git a/blockstack_cli_0.14.1/opendig/ons_resolver.py b/blockstack_cli_0.14.1/opendig/ons_resolver.py new file mode 100644 index 000000000..c94fca83a --- /dev/null +++ b/blockstack_cli_0.14.1/opendig/ons_resolver.py @@ -0,0 +1,78 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +""" + Open Name System + ~~~~~ + + :copyright: (c) 2014 by opennamesystem.org + :license: MIT, see LICENSE for more details. +""" + +from opendig import ONS_SERVER, NAMECOIND_PORT, NAMECOIND_USER, NAMECOIND_PASSWD, USE_HTTPS + +import json +import rpc + +#currently using namecoind for storing data (but ONS can use any blockchain) +namecoind = rpc.connect_to_remote(NAMECOIND_USER, NAMECOIND_PASSWD, + host=ONS_SERVER, port=NAMECOIND_PORT, + use_https=USE_HTTPS) + +#--------------------------------- +def error_reply(msg, code = -1): + reply = {} + reply['status'] = code + reply['message'] = "ERROR: " + msg + return reply + +#----------------------------------- +def get_value(input_key): + + reply = {} + + value = namecoind.name_show(input_key) + + try: + profile = json.loads(value.get('value')) + except: + profile = value.get('value') + + if 'code' in value and value.get('code') == -4: + return error_reply("Not found", 404) + + for key in value.keys(): + + reply['namecoin_address'] = value['address'] + + if(key == 'value'): + try: + reply[key] = json.loads(value[key]) + except: + reply[key] = value[key] + + return reply + +#----------------------------------- +def ons_resolver(key): + + check_profile = get_value(key) + + try: + check_profile = check_profile['value'] + except: + return check_profile + + if 'next' in check_profile: + try: + child_data = ons_resolver(check_profile['next']) + except: + return check_profile + + del check_profile['next'] + + merged_data = {key: value for (key, value) in (check_profile.items() + child_data.items())} + + return merged_data + + else: + return check_profile