mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-09-01 17:55:20 +00:00
network: change broadcast_transaction api
raise exceptions instead of weird return values closes #4433
This commit is contained in:
parent
c7833b8bc0
commit
87b05e1c9e
5 changed files with 27 additions and 27 deletions
|
@ -887,9 +887,14 @@ class ElectrumWindow(App):
|
||||||
Clock.schedule_once(lambda dt: on_success(tx))
|
Clock.schedule_once(lambda dt: on_success(tx))
|
||||||
|
|
||||||
def _broadcast_thread(self, tx, on_complete):
|
def _broadcast_thread(self, tx, on_complete):
|
||||||
ok, txid = self.network.run_from_another_thread(
|
|
||||||
self.network.broadcast_transaction(tx))
|
try:
|
||||||
Clock.schedule_once(lambda dt: on_complete(ok, txid))
|
self.network.run_from_another_thread(self.network.broadcast_transaction(tx))
|
||||||
|
except Exception as e:
|
||||||
|
ok, msg = False, repr(e)
|
||||||
|
else:
|
||||||
|
ok, msg = True, tx.txid()
|
||||||
|
Clock.schedule_once(lambda dt: on_complete(ok, msg))
|
||||||
|
|
||||||
def broadcast(self, tx, pr=None):
|
def broadcast(self, tx, pr=None):
|
||||||
def on_complete(ok, msg):
|
def on_complete(ok, msg):
|
||||||
|
|
|
@ -1639,8 +1639,12 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError):
|
||||||
if pr and pr.has_expired():
|
if pr and pr.has_expired():
|
||||||
self.payment_request = None
|
self.payment_request = None
|
||||||
return False, _("Payment request has expired")
|
return False, _("Payment request has expired")
|
||||||
status, msg = self.network.run_from_another_thread(
|
try:
|
||||||
self.network.broadcast_transaction(tx))
|
self.network.run_from_another_thread(self.network.broadcast_transaction(tx))
|
||||||
|
except Exception as e:
|
||||||
|
status, msg = False, repr(e)
|
||||||
|
else:
|
||||||
|
status, msg = True, tx.txid()
|
||||||
if pr and status is True:
|
if pr and status is True:
|
||||||
self.invoices.set_paid(pr, tx.txid())
|
self.invoices.set_paid(pr, tx.txid())
|
||||||
self.invoices.save()
|
self.invoices.save()
|
||||||
|
|
|
@ -203,15 +203,14 @@ class ElectrumGui:
|
||||||
self.wallet.labels[tx.txid()] = self.str_description
|
self.wallet.labels[tx.txid()] = self.str_description
|
||||||
|
|
||||||
print(_("Please wait..."))
|
print(_("Please wait..."))
|
||||||
status, msg = self.network.run_from_another_thread(
|
try:
|
||||||
self.network.broadcast_transaction(tx))
|
self.network.run_from_another_thread(self.network.broadcast_transaction(tx))
|
||||||
|
except Exception as e:
|
||||||
if status:
|
print(repr(e))
|
||||||
|
else:
|
||||||
print(_('Payment sent.'))
|
print(_('Payment sent.'))
|
||||||
#self.do_clear()
|
#self.do_clear()
|
||||||
#self.update_contacts_tab()
|
#self.update_contacts_tab()
|
||||||
else:
|
|
||||||
print(_('Error'))
|
|
||||||
|
|
||||||
def network_dialog(self):
|
def network_dialog(self):
|
||||||
print("use 'electrum setconfig server/proxy' to change your network settings")
|
print("use 'electrum setconfig server/proxy' to change your network settings")
|
||||||
|
|
|
@ -367,16 +367,14 @@ class ElectrumGui:
|
||||||
self.wallet.labels[tx.txid()] = self.str_description
|
self.wallet.labels[tx.txid()] = self.str_description
|
||||||
|
|
||||||
self.show_message(_("Please wait..."), getchar=False)
|
self.show_message(_("Please wait..."), getchar=False)
|
||||||
status, msg = self.network.run_from_another_thread(
|
try:
|
||||||
self.network.broadcast_transaction(tx))
|
self.network.run_from_another_thread(self.network.broadcast_transaction(tx))
|
||||||
|
except Exception as e:
|
||||||
if status:
|
self.show_message(repr(e))
|
||||||
|
else:
|
||||||
self.show_message(_('Payment sent.'))
|
self.show_message(_('Payment sent.'))
|
||||||
self.do_clear()
|
self.do_clear()
|
||||||
#self.update_contacts_tab()
|
#self.update_contacts_tab()
|
||||||
else:
|
|
||||||
self.show_message(_('Error'))
|
|
||||||
|
|
||||||
|
|
||||||
def show_message(self, message, getchar = True):
|
def show_message(self, message, getchar = True):
|
||||||
w = self.w
|
w = self.w
|
||||||
|
|
|
@ -676,16 +676,10 @@ class Network(PrintError):
|
||||||
|
|
||||||
@best_effort_reliable
|
@best_effort_reliable
|
||||||
async def broadcast_transaction(self, tx, timeout=10):
|
async def broadcast_transaction(self, tx, timeout=10):
|
||||||
try:
|
out = await self.interface.session.send_request('blockchain.transaction.broadcast', [str(tx)], timeout=timeout)
|
||||||
out = await self.interface.session.send_request('blockchain.transaction.broadcast', [str(tx)], timeout=timeout)
|
|
||||||
except RequestTimedOut as e:
|
|
||||||
return False, "error: operation timed out"
|
|
||||||
except Exception as e:
|
|
||||||
return False, "error: " + str(e)
|
|
||||||
|
|
||||||
if out != tx.txid():
|
if out != tx.txid():
|
||||||
return False, "error: " + out
|
raise Exception(out)
|
||||||
return True, out
|
return out # txid
|
||||||
|
|
||||||
@best_effort_reliable
|
@best_effort_reliable
|
||||||
async def request_chunk(self, height, tip=None, *, can_return_early=False):
|
async def request_chunk(self, height, tip=None, *, can_return_early=False):
|
||||||
|
|
Loading…
Add table
Reference in a new issue