forked from LBRYCommunity/lbry-sdk
Set default server to the networks default and use go hub by default
This commit is contained in:
parent
f59ddcc88d
commit
9b78501392
2 changed files with 27 additions and 13 deletions
|
@ -1,3 +1,4 @@
|
|||
import copy
|
||||
import linecache
|
||||
import os
|
||||
import re
|
||||
|
@ -434,6 +435,7 @@ class Daemon(metaclass=JSONRPCServerType):
|
|||
)
|
||||
|
||||
def __init__(self, conf: Config, component_manager: typing.Optional[ComponentManager] = None):
|
||||
self.use_go_hub = True
|
||||
self.conf = conf
|
||||
self.platform_info = system_info.get_platform()
|
||||
self._video_file_analyzer = VideoFileAnalyzer(conf)
|
||||
|
@ -2609,8 +2611,11 @@ class Daemon(metaclass=JSONRPCServerType):
|
|||
|
||||
Returns: {Paginated[Output]}
|
||||
"""
|
||||
if os.environ.get("GO_HUB") and os.environ.get("GO_HUB") == "true":
|
||||
host = os.environ.get("HUB_HOST", "localhost")
|
||||
# if os.environ.get("GO_HUB") and os.environ.get("GO_HUB") == "true":
|
||||
if self.ledger.network.use_go_hub:
|
||||
kwargs_old = copy.copy(kwargs)
|
||||
host = self.ledger.network.client.server[0]
|
||||
# host = os.environ.get("HUB_HOST", "localhost")
|
||||
port = os.environ.get("HUB_PORT", "50051")
|
||||
kwargs['new_sdk_server'] = f"{host}:{port}"
|
||||
if kwargs.get("channel"):
|
||||
|
@ -2638,6 +2643,7 @@ class Daemon(metaclass=JSONRPCServerType):
|
|||
page_num, page_size = abs(kwargs.pop('page', 1)), min(abs(kwargs.pop('page_size', DEFAULT_PAGE_SIZE)), 50)
|
||||
wallet = self.wallet_manager.get_wallet_or_default(kwargs.pop('wallet_id', None))
|
||||
kwargs.update({'offset': page_size * (page_num - 1), 'limit': page_size})
|
||||
try:
|
||||
txos, blocked, _, total = await self.ledger.claim_search(wallet.accounts, **kwargs)
|
||||
result = {
|
||||
"items": txos,
|
||||
|
@ -2649,6 +2655,12 @@ class Daemon(metaclass=JSONRPCServerType):
|
|||
result['total_pages'] = int((total + (page_size - 1)) / page_size)
|
||||
result['total_items'] = total
|
||||
return result
|
||||
except Exception as e:
|
||||
if self.ledger.network.use_go_hub:
|
||||
log.warning("failed, trying again without hub")
|
||||
self.ledger.network.use_go_hub = False
|
||||
return await self.jsonrpc_claim_search(**kwargs_old)
|
||||
raise e
|
||||
|
||||
CHANNEL_DOC = """
|
||||
Create, update, abandon and list your channel claims.
|
||||
|
|
|
@ -156,6 +156,7 @@ class Network:
|
|||
MINIMUM_REQUIRED = (0, 65, 0)
|
||||
|
||||
def __init__(self, ledger):
|
||||
self.use_go_hub = True
|
||||
self.ledger = ledger
|
||||
self.client: Optional[ClientSession] = None
|
||||
self.server_features = None
|
||||
|
@ -207,6 +208,7 @@ class Network:
|
|||
|
||||
async def start(self):
|
||||
if not self.running:
|
||||
self.use_go_hub = True
|
||||
self.running = True
|
||||
self.aiohttp_session = aiohttp.ClientSession()
|
||||
self.on_header.listen(self._update_remote_height)
|
||||
|
|
Loading…
Reference in a new issue