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): def make_short_url(r):
try: 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: except UnicodeDecodeError:
print(f'failed making short url due to name parse error for claim_id: {r["claimID"][::-1].hex()}') print(f'failed making short url due to name parse error for claim_id: {r["claimID"][::-1].hex()}')
return '' return 'FAILED'
class FindShortestID: class FindShortestID:

View file

@ -8,7 +8,7 @@ from docopt import docopt
from lbry import __version__ from lbry import __version__
from lbry.conf import Config, CLIConfig 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.metadata import interface
from lbry.service.full_node import FullNode from lbry.service.full_node import FullNode
from lbry.blockchain.ledger import Ledger from lbry.blockchain.ledger import Ledger
@ -165,7 +165,11 @@ def ensure_directory_exists(path: str):
async def execute_command(conf, method, params): 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): 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 .daemon import Daemon, jsonrpc_dumps_pretty
from .full_node import FullNode from .full_node import FullNode
from .light_client import LightClient from .light_client import LightClient

View file

@ -574,7 +574,7 @@ class API:
if isinstance(urls, str): if isinstance(urls, str):
urls = [urls] urls = [urls]
return await self.service.resolve( 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_purchase_receipt=include_purchase_receipt,
include_is_my_output=include_is_my_output, include_is_my_output=include_is_my_output,
include_sent_supports=include_sent_supports, include_sent_supports=include_sent_supports,

View file

@ -80,7 +80,7 @@ class Service:
await self.sync.stop() await self.sync.stop()
await self.db.close() await self.db.close()
def get_status(self): async def get_status(self):
pass pass
def get_version(self): def get_version(self):

View file

@ -147,21 +147,19 @@ class Daemon:
return web_socket return web_socket
async def on_message(self, web_socket: WebSocketManager, msg: dict): async def on_message(self, web_socket: WebSocketManager, msg: dict):
if msg['type'] == 'subscribe': if msg['method'] == 'subscribe':
streams = msg['streams'] streams = msg['streams']
if isinstance(streams, str): if isinstance(streams, str):
streams = [streams] streams = [streams]
web_socket.subscribe(streams, self.app['subscriptions']) 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: 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({ await web_socket.send_json({
'type': 'rpc', 'id': msg.get('id', ''), 'id': msg.get('id', ''),
'result': result 'result': encoded_result
}) })
@staticmethod @staticmethod

View file

@ -29,6 +29,9 @@ class FullNode(Service):
await super().stop() await super().stop()
await self.chain.close() await self.chain.close()
async def get_status(self):
return 'everything is wonderful'
async def get_block_address_filters(self): async def get_block_address_filters(self):
return { return {
hexlify(f['block_hash']).decode(): hexlify(f['block_filter']).decode() 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): async def wait(self, tx: Transaction, height=-1, timeout=1):
pass pass
async def resolve(self, accounts, urls, **kwargs): async def resolve(self, urls, **kwargs):
raise NotImplementedError return await self.db.resolve(*urls)

View file

@ -198,7 +198,7 @@ def generate_options(method, indent) -> List[str]:
flags.append(f"--{arg['name']}") flags.append(f"--{arg['name']}")
else: else:
flags.append(f"--{arg['name']}=<{arg['name']}>") 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] flags = [f.ljust(max_len) for f in flags]
options = [] options = []
for flag, arg in zip(flags, method['arguments']): for flag, arg in zip(flags, method['arguments']):

View file

@ -196,18 +196,20 @@ class TestGenerator(TestCase):
Usage: Usage:
thing delete <value1> thing delete <value1>
[--wallet_id=<wallet_id>] [--change_account_id=<change_account_id>] [--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] [--page=<page>] [--page_size=<page_size>] [--include_total]
Options: Options:
--value1=<value1> : (str) --value1=<value1> : (str)
--wallet_id=<wallet_id> : (str) restrict operation to specific wallet --wallet_id=<wallet_id> : (str) restrict operation to specific wallet
--change_account_id=<change_account_id> : (str) account to send excess change (LBC) --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 --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=<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 --include_total : (bool) calculate total number of items and
pages pages