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