forked from LBRYCommunity/lbry-sdk
make resolve command work from cli
This commit is contained in:
parent
f8a8a75ae9
commit
15b8891fce
9 changed files with 55 additions and 48 deletions
|
@ -16,10 +16,10 @@ FILES = [
|
|||
|
||||
def make_short_url(r):
|
||||
try:
|
||||
f'{normalize_name(r["name"].decode())}#{r["shortestID"] or r["claimID"][::-1].hex()[0]}'
|
||||
return f'{normalize_name(r["name"].decode())}#{r["shortestID"] or r["claimID"][::-1].hex()[0]}'
|
||||
except UnicodeDecodeError:
|
||||
print(f'failed making short url due to name parse error for claim_id: {r["claimID"][::-1].hex()}')
|
||||
return ''
|
||||
return 'FAILED'
|
||||
|
||||
|
||||
class FindShortestID:
|
||||
|
|
|
@ -8,7 +8,7 @@ from docopt import docopt
|
|||
|
||||
from lbry import __version__
|
||||
from lbry.conf import Config, CLIConfig
|
||||
from lbry.service import Daemon
|
||||
from lbry.service import Daemon, Client
|
||||
from lbry.service.metadata import interface
|
||||
from lbry.service.full_node import FullNode
|
||||
from lbry.blockchain.ledger import Ledger
|
||||
|
@ -165,7 +165,11 @@ def ensure_directory_exists(path: str):
|
|||
|
||||
|
||||
async def execute_command(conf, method, params):
|
||||
pass
|
||||
client = Client(f"http://{conf.api}/ws")
|
||||
await client.connect()
|
||||
resp = await client.send(method, **params)
|
||||
print(await resp.first)
|
||||
await client.close()
|
||||
|
||||
|
||||
def normalize_value(x, key=None):
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
from .api import API
|
||||
from .api import API, Client
|
||||
from .daemon import Daemon, jsonrpc_dumps_pretty
|
||||
from .full_node import FullNode
|
||||
from .light_client import LightClient
|
||||
|
|
|
@ -574,7 +574,7 @@ class API:
|
|||
if isinstance(urls, str):
|
||||
urls = [urls]
|
||||
return await self.service.resolve(
|
||||
urls, wallet=self.wallets.get_or_default(wallet_id),
|
||||
urls, wallet=None,#self.wallets.get_or_default(wallet_id),
|
||||
include_purchase_receipt=include_purchase_receipt,
|
||||
include_is_my_output=include_is_my_output,
|
||||
include_sent_supports=include_sent_supports,
|
||||
|
|
|
@ -80,7 +80,7 @@ class Service:
|
|||
await self.sync.stop()
|
||||
await self.db.close()
|
||||
|
||||
def get_status(self):
|
||||
async def get_status(self):
|
||||
pass
|
||||
|
||||
def get_version(self):
|
||||
|
|
|
@ -147,21 +147,19 @@ class Daemon:
|
|||
return web_socket
|
||||
|
||||
async def on_message(self, web_socket: WebSocketManager, msg: dict):
|
||||
if msg['type'] == 'subscribe':
|
||||
if msg['method'] == 'subscribe':
|
||||
streams = msg['streams']
|
||||
if isinstance(streams, str):
|
||||
streams = [streams]
|
||||
web_socket.subscribe(streams, self.app['subscriptions'])
|
||||
elif msg['type'] == 'rpc':
|
||||
component, method_name = msg['method'].split('.')
|
||||
method = getattr(self.components[component], method_name)
|
||||
if asyncio.iscoroutinefunction(method):
|
||||
result = await method(**msg['args'])
|
||||
else:
|
||||
result = method(**msg['args'])
|
||||
params = msg.get('params', {})
|
||||
method = getattr(self.api, msg['method'])
|
||||
result = await method(**params)
|
||||
encoded_result = jsonrpc_dumps_pretty(result, service=self.service)
|
||||
await web_socket.send_json({
|
||||
'type': 'rpc', 'id': msg.get('id', ''),
|
||||
'result': result
|
||||
'id': msg.get('id', ''),
|
||||
'result': encoded_result
|
||||
})
|
||||
|
||||
@staticmethod
|
||||
|
|
|
@ -29,6 +29,9 @@ class FullNode(Service):
|
|||
await super().stop()
|
||||
await self.chain.close()
|
||||
|
||||
async def get_status(self):
|
||||
return 'everything is wonderful'
|
||||
|
||||
async def get_block_address_filters(self):
|
||||
return {
|
||||
hexlify(f['block_hash']).decode(): hexlify(f['block_filter']).decode()
|
||||
|
@ -57,5 +60,5 @@ class FullNode(Service):
|
|||
async def wait(self, tx: Transaction, height=-1, timeout=1):
|
||||
pass
|
||||
|
||||
async def resolve(self, accounts, urls, **kwargs):
|
||||
raise NotImplementedError
|
||||
async def resolve(self, urls, **kwargs):
|
||||
return await self.db.resolve(*urls)
|
||||
|
|
|
@ -198,7 +198,7 @@ def generate_options(method, indent) -> List[str]:
|
|||
flags.append(f"--{arg['name']}")
|
||||
else:
|
||||
flags.append(f"--{arg['name']}=<{arg['name']}>")
|
||||
max_len = max(len(f) for f in flags) + 1
|
||||
max_len = max(len(f) for f in flags) + 2
|
||||
flags = [f.ljust(max_len) for f in flags]
|
||||
options = []
|
||||
for flag, arg in zip(flags, method['arguments']):
|
||||
|
|
|
@ -196,18 +196,20 @@ class TestGenerator(TestCase):
|
|||
Usage:
|
||||
thing delete <value1>
|
||||
[--wallet_id=<wallet_id>] [--change_account_id=<change_account_id>]
|
||||
[--fund_account_id=<fund_account_id>...] [--preview] [--blocking]
|
||||
[--fund_account_id=<fund_account_id>...] [--preview] [--no_wait]
|
||||
[--page=<page>] [--page_size=<page_size>] [--include_total]
|
||||
|
||||
Options:
|
||||
--value1=<value1> : (str)
|
||||
--wallet_id=<wallet_id> : (str) restrict operation to specific wallet
|
||||
--change_account_id=<change_account_id> : (str) account to send excess change (LBC)
|
||||
--fund_account_id=<fund_account_id> : (str, list) accounts to fund the transaction
|
||||
--fund_account_id=<fund_account_id> : (str, list) accounts to fund the
|
||||
transaction
|
||||
--preview : (bool) do not broadcast the transaction
|
||||
--blocking : (bool) wait until transaction is in mempool
|
||||
--no_wait : (bool) do not wait for mempool confirmation
|
||||
--page=<page> : (int) page to return for paginating
|
||||
--page_size=<page_size> : (int) number of items on page for pagination
|
||||
--page_size=<page_size> : (int) number of items on page for
|
||||
pagination
|
||||
--include_total : (bool) calculate total number of items and
|
||||
pages
|
||||
|
||||
|
|
Loading…
Reference in a new issue