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):
|
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:
|
||||||
|
|
|
@ -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):
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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,
|
||||||
|
|
|
@ -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):
|
||||||
|
|
|
@ -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':
|
else:
|
||||||
component, method_name = msg['method'].split('.')
|
params = msg.get('params', {})
|
||||||
method = getattr(self.components[component], method_name)
|
method = getattr(self.api, msg['method'])
|
||||||
if asyncio.iscoroutinefunction(method):
|
result = await method(**params)
|
||||||
result = await method(**msg['args'])
|
encoded_result = jsonrpc_dumps_pretty(result, service=self.service)
|
||||||
else:
|
|
||||||
result = method(**msg['args'])
|
|
||||||
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
|
||||||
|
|
|
@ -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)
|
||||||
|
|
|
@ -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']):
|
||||||
|
|
|
@ -152,13 +152,13 @@ class TestGenerator(TestCase):
|
||||||
expanders = get_expanders()
|
expanders = get_expanders()
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
generate_options(parse_method(FakeAPI.thing_list, expanders), indent=' '), [
|
generate_options(parse_method(FakeAPI.thing_list, expanders), indent=' '), [
|
||||||
' --value1=<value1> : (str) the first value',
|
' --value1=<value1> : (str) the first value',
|
||||||
' --value2=<value2> : (int) the second value with a very very long description which',
|
' --value2=<value2> : (int) the second value with a very very long description which',
|
||||||
' needs to be wrapped',
|
' needs to be wrapped',
|
||||||
' --value3 : (bool) a bool multi-line',
|
' --value3 : (bool) a bool multi-line',
|
||||||
' --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 pages',
|
' --include_total : (bool) calculate total number of items and pages',
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -181,9 +181,9 @@ class TestGenerator(TestCase):
|
||||||
thing create
|
thing create
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
--name=<name> : (str) the name
|
--name=<name> : (str) the name
|
||||||
--value1=<value1> : (str) the first value [default: 'hi']
|
--value1=<value1> : (str) the first value [default: 'hi']
|
||||||
--value2=<value2> : (int) the second value [default: 9]
|
--value2=<value2> : (int) the second value [default: 9]
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
(str) thing name""")
|
(str) thing name""")
|
||||||
|
@ -196,20 +196,22 @@ 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
|
||||||
--preview : (bool) do not broadcast the transaction
|
transaction
|
||||||
--blocking : (bool) wait until transaction is in mempool
|
--preview : (bool) do not broadcast the transaction
|
||||||
--page=<page> : (int) page to return for paginating
|
--no_wait : (bool) do not wait for mempool confirmation
|
||||||
--page_size=<page_size> : (int) number of items on page for pagination
|
--page=<page> : (int) page to return for paginating
|
||||||
--include_total : (bool) calculate total number of items and
|
--page_size=<page_size> : (int) number of items on page for
|
||||||
pages
|
pagination
|
||||||
|
--include_total : (bool) calculate total number of items and
|
||||||
|
pages
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
(Wallet) deleted thing
|
(Wallet) deleted thing
|
||||||
|
@ -227,13 +229,13 @@ class TestGenerator(TestCase):
|
||||||
thing list
|
thing list
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
--value1=<value1> : (str) the first value
|
--value1=<value1> : (str) the first value
|
||||||
--value2=<value2> : (int) the second value with a very very long description
|
--value2=<value2> : (int) the second value with a very very long description
|
||||||
which needs to be wrapped
|
which needs to be wrapped
|
||||||
--value3 : (bool) a bool multi-line
|
--value3 : (bool) a bool multi-line
|
||||||
--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 pages
|
--include_total : (bool) calculate total number of items and pages
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
(Paginated[Wallet]) list of wallets
|
(Paginated[Wallet]) list of wallets
|
||||||
|
|
Loading…
Reference in a new issue