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 linecache
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
@ -434,6 +435,7 @@ class Daemon(metaclass=JSONRPCServerType):
|
||||||
)
|
)
|
||||||
|
|
||||||
def __init__(self, conf: Config, component_manager: typing.Optional[ComponentManager] = None):
|
def __init__(self, conf: Config, component_manager: typing.Optional[ComponentManager] = None):
|
||||||
|
self.use_go_hub = True
|
||||||
self.conf = conf
|
self.conf = conf
|
||||||
self.platform_info = system_info.get_platform()
|
self.platform_info = system_info.get_platform()
|
||||||
self._video_file_analyzer = VideoFileAnalyzer(conf)
|
self._video_file_analyzer = VideoFileAnalyzer(conf)
|
||||||
|
@ -2609,8 +2611,11 @@ class Daemon(metaclass=JSONRPCServerType):
|
||||||
|
|
||||||
Returns: {Paginated[Output]}
|
Returns: {Paginated[Output]}
|
||||||
"""
|
"""
|
||||||
if os.environ.get("GO_HUB") and os.environ.get("GO_HUB") == "true":
|
# if os.environ.get("GO_HUB") and os.environ.get("GO_HUB") == "true":
|
||||||
host = os.environ.get("HUB_HOST", "localhost")
|
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")
|
port = os.environ.get("HUB_PORT", "50051")
|
||||||
kwargs['new_sdk_server'] = f"{host}:{port}"
|
kwargs['new_sdk_server'] = f"{host}:{port}"
|
||||||
if kwargs.get("channel"):
|
if kwargs.get("channel"):
|
||||||
|
@ -2638,17 +2643,24 @@ class Daemon(metaclass=JSONRPCServerType):
|
||||||
page_num, page_size = abs(kwargs.pop('page', 1)), min(abs(kwargs.pop('page_size', DEFAULT_PAGE_SIZE)), 50)
|
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))
|
wallet = self.wallet_manager.get_wallet_or_default(kwargs.pop('wallet_id', None))
|
||||||
kwargs.update({'offset': page_size * (page_num - 1), 'limit': page_size})
|
kwargs.update({'offset': page_size * (page_num - 1), 'limit': page_size})
|
||||||
txos, blocked, _, total = await self.ledger.claim_search(wallet.accounts, **kwargs)
|
try:
|
||||||
result = {
|
txos, blocked, _, total = await self.ledger.claim_search(wallet.accounts, **kwargs)
|
||||||
"items": txos,
|
result = {
|
||||||
"blocked": blocked,
|
"items": txos,
|
||||||
"page": page_num,
|
"blocked": blocked,
|
||||||
"page_size": page_size
|
"page": page_num,
|
||||||
}
|
"page_size": page_size
|
||||||
if not kwargs.pop('no_totals', False):
|
}
|
||||||
result['total_pages'] = int((total + (page_size - 1)) / page_size)
|
if not kwargs.pop('no_totals', False):
|
||||||
result['total_items'] = total
|
result['total_pages'] = int((total + (page_size - 1)) / page_size)
|
||||||
return result
|
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 = """
|
CHANNEL_DOC = """
|
||||||
Create, update, abandon and list your channel claims.
|
Create, update, abandon and list your channel claims.
|
||||||
|
|
|
@ -156,6 +156,7 @@ class Network:
|
||||||
MINIMUM_REQUIRED = (0, 65, 0)
|
MINIMUM_REQUIRED = (0, 65, 0)
|
||||||
|
|
||||||
def __init__(self, ledger):
|
def __init__(self, ledger):
|
||||||
|
self.use_go_hub = True
|
||||||
self.ledger = ledger
|
self.ledger = ledger
|
||||||
self.client: Optional[ClientSession] = None
|
self.client: Optional[ClientSession] = None
|
||||||
self.server_features = None
|
self.server_features = None
|
||||||
|
@ -207,6 +208,7 @@ class Network:
|
||||||
|
|
||||||
async def start(self):
|
async def start(self):
|
||||||
if not self.running:
|
if not self.running:
|
||||||
|
self.use_go_hub = True
|
||||||
self.running = True
|
self.running = True
|
||||||
self.aiohttp_session = aiohttp.ClientSession()
|
self.aiohttp_session = aiohttp.ClientSession()
|
||||||
self.on_header.listen(self._update_remote_height)
|
self.on_header.listen(self._update_remote_height)
|
||||||
|
|
Loading…
Reference in a new issue