Skip to content

Commit

Permalink
Namecoin: Fix broadcast() usage
Browse files Browse the repository at this point in the history
Upstream Electrum changed the return value of broadcast().  Previously,
errors would be encoded in the return value.  Now errors are raised as
exceptions, and the return value is just a txid.  This commit fixes our
usage accordingly.
  • Loading branch information
JeremyRand committed Oct 23, 2018
1 parent db79581 commit 66e783f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
14 changes: 8 additions & 6 deletions electrum_nmc/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -681,9 +681,10 @@ def name_autoregister(self, identifier, value, destination=None, amount=0.0, fee
new_rand = new_result["rand"]
new_tx = new_result["tx"]["hex"]

status, msg = self.broadcast(new_tx)
if not status:
raise Exception("Error broadcasting name pre-registration: " + msg)
try:
self.broadcast(new_tx)
except Exception as e:
raise Exception("Error broadcasting name pre-registration: " + str(e))

# We add the name_new transaction to the wallet explicitly because
# otherwise, the wallet will only learn about the name_new once the
Expand Down Expand Up @@ -931,9 +932,10 @@ def updatequeuedtransactions(self):

if current_depth >= trigger_depth:
tx = queue_item["tx"]
status, msg = self.broadcast(tx)
if not status:
errors[txid] = msg
try:
self.broadcast(tx)
except Exception as e:
errors[txid] = str(e)

to_unqueue.append(txid)

Expand Down
7 changes: 4 additions & 3 deletions electrum_nmc/gui/qt/configure_name_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,11 @@ def update_and_broadcast(self, identifier, value, transfer_to):
# TODO: support non-ASCII encodings
tx = name_update(identifier.decode('ascii'), value.decode('ascii'), recipient_address)['hex']

status, msg = broadcast(tx)
if not status:
try:
broadcast(tx)
except Exception as e:
formatted_name = format_name_identifier(identifier)
self.main_window.show_error(_("Error broadcasting update for ") + formatted_name + ": " + str(msg))
self.main_window.show_error(_("Error broadcasting update for ") + formatted_name + ": " + str(e))
return

# As far as I can tell, we don't need to explicitly add the transaction
Expand Down
7 changes: 4 additions & 3 deletions electrum_nmc/gui/qt/uno_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,11 @@ def renew_selected_items(self):
# The name was recently updated, so skip it and don't renew.
continue

status, msg = broadcast(tx)
if not status:
try:
broadcast(tx)
except Exception as e:
formatted_name = format_name_identifier(identifier)
self.parent.show_error(_("Error broadcasting renewal for ") + formatted_name + ": " + str(msg))
self.parent.show_error(_("Error broadcasting renewal for ") + formatted_name + ": " + str(e))
continue

# We add the transaction to the wallet explicitly because
Expand Down

0 comments on commit 66e783f

Please sign in to comment.