Skip to content

Commit

Permalink
Namecoin: Add support for NS DNS records
Browse files Browse the repository at this point in the history
  • Loading branch information
JeremyRand committed Dec 12, 2019
1 parent b555866 commit e7ae37e
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
15 changes: 15 additions & 0 deletions electrum_nmc/electrum/gui/qt/configure_dns_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ def __init__(self, value, parent):

self.ui.btnACreate.clicked.connect(self.create_address_record)
self.ui.btnCNAMECreate.clicked.connect(self.create_cname_record)
self.ui.btnNSCreate.clicked.connect(self.create_ns_record)
self.ui.btnDSCreate.clicked.connect(self.create_ds_record)
self.ui.btnTXTCreate.clicked.connect(self.create_txt_record)

Expand Down Expand Up @@ -165,6 +166,17 @@ def create_cname_record(self):

self.insert_record(idx, record)

def create_ns_record(self):
model = self.ui.listDNSRecords.model()
idx = model.rowCount()

domain = self.get_selected_domain()
data = self.ui.editNSHosts.text()

record = [domain, "ns", data]

self.insert_record(idx, record)

def create_ds_record(self):
model = self.ui.listDNSRecords.model()
idx = model.rowCount()
Expand Down Expand Up @@ -247,6 +259,9 @@ def insert_record(self, idx, record):
elif record_type == "cname":
formatted_record_type = "CNAME"
formatted_data = data
elif record_type == "ns":
formatted_record_type = "NS"
formatted_data = data
elif record_type == "ds":
formatted_record_type = "DS"
formatted_data = json.dumps(data)
Expand Down
44 changes: 44 additions & 0 deletions electrum_nmc/electrum/names.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,12 @@ def get_domain_records(domain, value):
if value["alias"] == None:
del value["alias"]

if "ns" in value:
new_records, value["ns"] = get_domain_records_ns(domain, value["ns"])
records.extend(new_records)
if value["ns"] == []:
del value["ns"]

if "ds" in value:
new_records, value["ds"] = get_domain_records_ds(domain, value["ds"])
records.extend(new_records)
Expand Down Expand Up @@ -692,6 +698,34 @@ def get_domain_records_cname(domain, value):

return records, remaining

def get_domain_records_ns(domain, value):
# Convert string to array (only 1 NS record exists)
if type(value) == str:
value = [value]

# Must be array
if type(value) != list:
return [], value

# Parse each array item
records = []
remaining = []
for raw_address in value:
single_record, single_remaining = get_domain_records_ns_single(domain, raw_address)
if single_record is not None:
records.append(single_record)
if single_remaining is not None:
remaining.append(single_remaining)

return records, remaining

def get_domain_records_ns_single(domain, value):
# Must be string
if type(value) != str:
return None, value

return [domain, "ns", value], None

def get_domain_records_ds(domain, value):
# Must be array
if type(value) != list:
Expand Down Expand Up @@ -820,6 +854,8 @@ def add_domain_record(base_domain, value, record):
add_domain_record_address(subdomain_value, data)
elif record_type == "cname":
add_domain_record_cname(subdomain_value, data)
elif record_type == "ns":
add_domain_record_ns(subdomain_value, data)
elif record_type == "ds":
add_domain_record_ds(subdomain_value, data)
elif record_type == "txt":
Expand Down Expand Up @@ -903,6 +939,14 @@ def add_domain_record_cname(value, data):
# Add the record
value["alias"] = data

def add_domain_record_ns(value, data):
# Make sure the field exists
if "ns" not in value:
value["ns"] = []

# Add the record
value["ns"].append(data)

def add_domain_record_ds(value, data):
# Make sure the field exists
if "ds" not in value:
Expand Down

0 comments on commit e7ae37e

Please sign in to comment.