fix some network.get_transaction calls
see #4814 (issuecomment-434392195)
This commit is contained in:
parent
f53b480f1c
commit
5b4fada2a0
@ -2427,11 +2427,12 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError):
|
||||
if ok and txid:
|
||||
txid = str(txid).strip()
|
||||
try:
|
||||
r = self.network.get_transaction(txid)
|
||||
except BaseException as e:
|
||||
self.show_message(str(e))
|
||||
raw_tx = self.network.run_from_another_thread(
|
||||
self.network.get_transaction(txid, timeout=10))
|
||||
except Exception as e:
|
||||
self.show_message(_("Error getting transaction from network") + ":\n" + str(e))
|
||||
return
|
||||
tx = transaction.Transaction(r)
|
||||
tx = transaction.Transaction(raw_tx)
|
||||
self.show_transaction(tx)
|
||||
|
||||
@protected
|
||||
|
||||
@ -68,9 +68,9 @@ class NotificationSession(RPCSession):
|
||||
else:
|
||||
raise Exception('unexpected request: {}'.format(repr(request)))
|
||||
|
||||
async def send_request(self, *args, timeout=-1, **kwargs):
|
||||
async def send_request(self, *args, timeout=None, **kwargs):
|
||||
# note: the timeout starts after the request touches the wire!
|
||||
if timeout == -1:
|
||||
if timeout is None:
|
||||
timeout = 30
|
||||
# note: the semaphore implementation guarantees no starvation
|
||||
async with self.in_flight_requests_semaphore:
|
||||
@ -108,7 +108,13 @@ class NotificationSession(RPCSession):
|
||||
|
||||
|
||||
class GracefulDisconnect(Exception): pass
|
||||
class RequestTimedOut(GracefulDisconnect): pass
|
||||
|
||||
|
||||
class RequestTimedOut(GracefulDisconnect):
|
||||
def __str__(self):
|
||||
return _("Network request timed out.")
|
||||
|
||||
|
||||
class ErrorParsingSSLCert(Exception): pass
|
||||
class ErrorGettingSSLCertFromServer(Exception): pass
|
||||
|
||||
|
||||
@ -706,7 +706,7 @@ class Network(PrintError):
|
||||
return await self.interface.session.send_request('blockchain.transaction.get_merkle', [tx_hash, tx_height])
|
||||
|
||||
@best_effort_reliable
|
||||
async def broadcast_transaction(self, tx, timeout=10):
|
||||
async def broadcast_transaction(self, tx, *, timeout=10):
|
||||
out = await self.interface.session.send_request('blockchain.transaction.broadcast', [str(tx)], timeout=timeout)
|
||||
if out != tx.txid():
|
||||
raise Exception(out)
|
||||
@ -717,8 +717,9 @@ class Network(PrintError):
|
||||
return await self.interface.request_chunk(height, tip=tip, can_return_early=can_return_early)
|
||||
|
||||
@best_effort_reliable
|
||||
async def get_transaction(self, tx_hash: str) -> str:
|
||||
return await self.interface.session.send_request('blockchain.transaction.get', [tx_hash])
|
||||
async def get_transaction(self, tx_hash: str, *, timeout=None) -> str:
|
||||
return await self.interface.session.send_request('blockchain.transaction.get', [tx_hash],
|
||||
timeout=timeout)
|
||||
|
||||
@best_effort_reliable
|
||||
async def get_history_for_scripthash(self, sh: str) -> List[dict]:
|
||||
|
||||
@ -113,16 +113,6 @@ class FileExportFailed(Exception):
|
||||
return _("Failed to export to file.") + "\n" + self.message
|
||||
|
||||
|
||||
class TimeoutException(Exception):
|
||||
def __init__(self, message=''):
|
||||
self.message = str(message)
|
||||
|
||||
def __str__(self):
|
||||
if not self.message:
|
||||
return _("Operation timed out.")
|
||||
return self.message
|
||||
|
||||
|
||||
class WalletFileException(Exception): pass
|
||||
|
||||
|
||||
|
||||
@ -43,7 +43,7 @@ from typing import TYPE_CHECKING, List, Optional, Tuple
|
||||
from .i18n import _
|
||||
from .util import (NotEnoughFunds, PrintError, UserCancelled, profiler,
|
||||
format_satoshis, format_fee_satoshis, NoDynamicFeeEstimates,
|
||||
TimeoutException, WalletFileException, BitcoinException,
|
||||
WalletFileException, BitcoinException,
|
||||
InvalidPassword, format_time, timestamp_to_datetime, Satoshis,
|
||||
Fiat, bfh, bh2u)
|
||||
from .bitcoin import (COIN, TYPE_ADDRESS, is_address, address_to_script,
|
||||
@ -60,6 +60,7 @@ from .address_synchronizer import (AddressSynchronizer, TX_HEIGHT_LOCAL,
|
||||
from .paymentrequest import (PR_PAID, PR_UNPAID, PR_UNKNOWN, PR_EXPIRED,
|
||||
InvoiceStore)
|
||||
from .contacts import Contacts
|
||||
from .interface import RequestTimedOut
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from .network import Network
|
||||
@ -768,11 +769,14 @@ class Abstract_Wallet(AddressSynchronizer):
|
||||
tx = self.transactions.get(tx_hash, None)
|
||||
if not tx and self.network:
|
||||
try:
|
||||
tx = Transaction(self.network.get_transaction(tx_hash))
|
||||
except TimeoutException as e:
|
||||
self.print_error('getting input txn from network timed out for {}'.format(tx_hash))
|
||||
raw_tx = self.network.run_from_another_thread(
|
||||
self.network.get_transaction(tx_hash, timeout=10))
|
||||
except RequestTimedOut as e:
|
||||
self.print_error(f'getting input txn from network timed out for {tx_hash}')
|
||||
if not ignore_timeout:
|
||||
raise e
|
||||
else:
|
||||
tx = Transaction(raw_tx)
|
||||
return tx
|
||||
|
||||
def add_hw_info(self, tx):
|
||||
|
||||
Loading…
Reference in New Issue
Block a user