make resolve command work from cli

This commit is contained in:
Lex Berezhny 2020-07-07 10:52:41 -04:00
parent f8a8a75ae9
commit 15b8891fce
9 changed files with 55 additions and 48 deletions

View file

@ -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:

View file

@ -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):

View file

@ -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

View file

@ -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,

View file

@ -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):

View file

@ -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'])
else:
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

View file

@ -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)

View file

@ -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']):

View file

@ -152,13 +152,13 @@ class TestGenerator(TestCase):
expanders = get_expanders()
self.assertEqual(
generate_options(parse_method(FakeAPI.thing_list, expanders), indent=' '), [
' --value1=<value1> : (str) the first value',
' --value2=<value2> : (int) the second value with a very very long description which',
' needs to be wrapped',
' --value3 : (bool) a bool multi-line',
' --page=<page> : (int) page to return for paginating',
' --page_size=<page_size> : (int) number of items on page for pagination',
' --include_total : (bool) calculate total number of items and pages',
' --value1=<value1> : (str) the first value',
' --value2=<value2> : (int) the second value with a very very long description which',
' needs to be wrapped',
' --value3 : (bool) a bool multi-line',
' --page=<page> : (int) page to return for paginating',
' --page_size=<page_size> : (int) number of items on page for pagination',
' --include_total : (bool) calculate total number of items and pages',
]
)
@ -181,9 +181,9 @@ class TestGenerator(TestCase):
thing create
Options:
--name=<name> : (str) the name
--value1=<value1> : (str) the first value [default: 'hi']
--value2=<value2> : (int) the second value [default: 9]
--name=<name> : (str) the name
--value1=<value1> : (str) the first value [default: 'hi']
--value2=<value2> : (int) the second value [default: 9]
Returns:
(str) thing name""")
@ -196,20 +196,22 @@ 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
--preview : (bool) do not broadcast the transaction
--blocking : (bool) wait until transaction is in mempool
--page=<page> : (int) page to return for paginating
--page_size=<page_size> : (int) number of items on page for pagination
--include_total : (bool) calculate total number of items and
pages
--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
--preview : (bool) do not broadcast the transaction
--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
--include_total : (bool) calculate total number of items and
pages
Returns:
(Wallet) deleted thing
@ -227,13 +229,13 @@ class TestGenerator(TestCase):
thing list
Options:
--value1=<value1> : (str) the first value
--value2=<value2> : (int) the second value with a very very long description
which needs to be wrapped
--value3 : (bool) a bool multi-line
--page=<page> : (int) page to return for paginating
--page_size=<page_size> : (int) number of items on page for pagination
--include_total : (bool) calculate total number of items and pages
--value1=<value1> : (str) the first value
--value2=<value2> : (int) the second value with a very very long description
which needs to be wrapped
--value3 : (bool) a bool multi-line
--page=<page> : (int) page to return for paginating
--page_size=<page_size> : (int) number of items on page for pagination
--include_total : (bool) calculate total number of items and pages
Returns:
(Paginated[Wallet]) list of wallets