Support namecoin standard 'map' for subdomain name (#1856)

* Support namecoin standard 'map' for subdomain name

* Proper naming for variables

*  naming fix and added one case for namecoin standard
This commit is contained in:
Lola Dam 2019-01-15 16:25:33 +01:00 committed by ZeroNet
parent 8ee8acf655
commit 1f1e6006ec

View file

@ -22,9 +22,33 @@ def processNameOp(domain, value, test=False):
except Exception, err: except Exception, err:
print "Json load error: %s" % err print "Json load error: %s" % err
return False return False
if "zeronet" not in data: if "zeronet" not in data and "map" not in data:
print "No zeronet in ", data.keys() # Namecoin standard use {"map": { "blog": {"zeronet": "1D..."} }}
print "No zeronet and no map in ", data.keys()
return False return False
if "map" in data:
# If subdomains using the Namecoin standard is present, just re-write in the Zeronet way
# and call the function again
data_map = data["map"]
new_value = {}
for subdomain in data_map:
if "zeronet" in data_map[subdomain]:
new_value[subdomain] = data_map[subdomain]["zeronet"]
if "zeronet" in data and isinstance(data["zeronet"], basestring):
# {
# "zeronet":"19rXKeKptSdQ9qt7omwN82smehzTuuq6S9",
# ....
# }
new_value[""] = data["zeronet"]
if len(new_value) > 0:
return processNameOp(domain, json.dumps({"zeronet": new_value}), test)
else:
return False
if "zeronet" in data and isinstance(data["zeronet"], basestring):
# {
# "zeronet":"19rXKeKptSdQ9qt7omwN82smehzTuuq6S9"
# } is valid
return processNameOp(domain, json.dumps({"zeronet": { "": data["zeronet"]}}), test)
if not isinstance(data["zeronet"], dict): if not isinstance(data["zeronet"], dict):
print "Not dict: ", data["zeronet"] print "Not dict: ", data["zeronet"]
return False return False