Skip to content

Commit

Permalink
Namecoin: Format ASCII values
Browse files Browse the repository at this point in the history
  • Loading branch information
JeremyRand committed Oct 1, 2018
1 parent 1e32ab2 commit f430b8c
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion electrum_nmc/names.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,22 @@ def format_name_identifier_unknown_hex(identifier_bytes):
return "Non-standard hex name " + bh2u(identifier_bytes)


def format_name_value(identifier_bytes):
try:
identifier = identifier_bytes.decode("ascii")
except UnicodeDecodeError:
return format_name_value_hex(identifier_bytes)

if not identifier.isprintable():
return format_name_value_hex(identifier_bytes)

return "ASCII " + identifier


def format_name_value_hex(identifier_bytes):
return "Hex " + bh2u(identifier_bytes)


def format_name_op(name_op):
if name_op is None:
return ''
Expand All @@ -170,7 +186,7 @@ def format_name_op(name_op):
if "name" in name_op:
formatted_name = "Name = " + format_name_identifier(name_op["name"])
if "value" in name_op:
formatted_value = "Data = Hex " + bh2u(name_op["value"])
formatted_value = "Data = " + format_name_value(name_op["value"])

if name_op["op"] == OP_NAME_NEW:
return "\tPre-Registration\n\t\t" + formatted_hash
Expand Down

0 comments on commit f430b8c

Please sign in to comment.