forked from LBRYCommunity/lbry-sdk
provide --resolve tag for collection claim, separate from resolving its contents
bugfix and docs generation review changes
This commit is contained in:
parent
9815ddef1f
commit
183fb9f9ff
4 changed files with 46 additions and 7 deletions
|
@ -3696,7 +3696,7 @@ class Daemon(metaclass=JSONRPCServerType):
|
||||||
COLLECTION_DOC = """
|
COLLECTION_DOC = """
|
||||||
Create, update, list, resolve, and abandon collections.
|
Create, update, list, resolve, and abandon collections.
|
||||||
"""
|
"""
|
||||||
|
#| --claims = < claims >
|
||||||
@requires(WALLET_COMPONENT)
|
@requires(WALLET_COMPONENT)
|
||||||
async def jsonrpc_collection_create(
|
async def jsonrpc_collection_create(
|
||||||
self, name, bid, claims, allow_duplicate_name=False,
|
self, name, bid, claims, allow_duplicate_name=False,
|
||||||
|
@ -3993,15 +3993,17 @@ class Daemon(metaclass=JSONRPCServerType):
|
||||||
return await self.jsonrpc_stream_abandon(*args, **kwargs)
|
return await self.jsonrpc_stream_abandon(*args, **kwargs)
|
||||||
|
|
||||||
@requires(WALLET_COMPONENT)
|
@requires(WALLET_COMPONENT)
|
||||||
def jsonrpc_collection_list(self, resolve_claims=0, account_id=None, wallet_id=None, page=None, page_size=None):
|
def jsonrpc_collection_list(self, resolve_claims=0, resolve=False,
|
||||||
|
account_id=None, wallet_id=None, page=None, page_size=None):
|
||||||
"""
|
"""
|
||||||
List my collection claims.
|
List my collection claims.
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
collection_list [--resolve_claims=<resolve_claims>] [<account_id> | --account_id=<account_id>]
|
collection_list [--resolve_claims=<resolve_claims>] [--resolve] [<account_id> | --account_id=<account_id>]
|
||||||
[--wallet_id=<wallet_id>] [--page=<page>] [--page_size=<page_size>]
|
[--wallet_id=<wallet_id>] [--page=<page>] [--page_size=<page_size>]
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
|
--resolve : (bool) resolve collection claim
|
||||||
--resolve_claims=<resolve_claims> : (int) resolve every claim
|
--resolve_claims=<resolve_claims> : (int) resolve every claim
|
||||||
--account_id=<account_id> : (str) id of the account to use
|
--account_id=<account_id> : (str) id of the account to use
|
||||||
--wallet_id=<wallet_id> : (str) restrict results to specific wallet
|
--wallet_id=<wallet_id> : (str) restrict results to specific wallet
|
||||||
|
@ -4013,11 +4015,22 @@ class Daemon(metaclass=JSONRPCServerType):
|
||||||
wallet = self.wallet_manager.get_wallet_or_default(wallet_id)
|
wallet = self.wallet_manager.get_wallet_or_default(wallet_id)
|
||||||
if account_id:
|
if account_id:
|
||||||
account = wallet.get_account_or_error(account_id)
|
account = wallet.get_account_or_error(account_id)
|
||||||
collections = account.get_collections
|
collections = partial(
|
||||||
|
self.ledger.get_collections,
|
||||||
|
wallet=wallet,
|
||||||
|
accounts=[account],
|
||||||
|
resolve=resolve)
|
||||||
collection_count = account.get_collection_count
|
collection_count = account.get_collection_count
|
||||||
else:
|
else:
|
||||||
collections = partial(self.ledger.get_collections, wallet=wallet, accounts=wallet.accounts)
|
collections = partial(
|
||||||
collection_count = partial(self.ledger.get_collection_count, wallet=wallet, accounts=wallet.accounts)
|
self.ledger.get_collections,
|
||||||
|
wallet=wallet,
|
||||||
|
accounts=wallet.accounts,
|
||||||
|
resolve=resolve)
|
||||||
|
collection_count = partial(
|
||||||
|
self.ledger.get_collection_count,
|
||||||
|
wallet=wallet,
|
||||||
|
accounts=wallet.accounts)
|
||||||
return paginate_rows(collections, collection_count, page, page_size, resolve_claims=resolve_claims)
|
return paginate_rows(collections, collection_count, page, page_size, resolve_claims=resolve_claims)
|
||||||
|
|
||||||
async def jsonrpc_collection_resolve(
|
async def jsonrpc_collection_resolve(
|
||||||
|
|
|
@ -1022,8 +1022,10 @@ class Ledger(metaclass=LedgerRegistry):
|
||||||
claims.append(None)
|
claims.append(None)
|
||||||
return claims
|
return claims
|
||||||
|
|
||||||
async def get_collections(self, resolve_claims=0, **constraints):
|
async def get_collections(self, resolve_claims=0, resolve=False, **constraints):
|
||||||
collections = await self.db.get_collections(**constraints)
|
collections = await self.db.get_collections(**constraints)
|
||||||
|
if resolve:
|
||||||
|
collections = await self._resolve_for_local_results(constraints.get('accounts', []), collections)
|
||||||
if resolve_claims > 0:
|
if resolve_claims > 0:
|
||||||
for collection in collections:
|
for collection in collections:
|
||||||
collection.claims = await self.resolve_collection(collection, page_size=resolve_claims)
|
collection.claims = await self.resolve_collection(collection, page_size=resolve_claims)
|
||||||
|
|
|
@ -365,6 +365,26 @@ class Examples(CommandTestCase):
|
||||||
|
|
||||||
await self.daemon.jsonrpc_comment_abandon(reply['comment_id'])
|
await self.daemon.jsonrpc_comment_abandon(reply['comment_id'])
|
||||||
|
|
||||||
|
# collections
|
||||||
|
collection = await r(
|
||||||
|
'Create a collection of one stream',
|
||||||
|
'collection', 'create',
|
||||||
|
'--name=tom', '--bid=1.0',
|
||||||
|
f'--channel_id={channel_id}',
|
||||||
|
f'--claims={stream_id}'
|
||||||
|
)
|
||||||
|
|
||||||
|
await self.on_transaction_dict(collection)
|
||||||
|
await self.generate(1)
|
||||||
|
await self.on_transaction_dict(collection)
|
||||||
|
|
||||||
|
await r(
|
||||||
|
'List collections',
|
||||||
|
'collection', 'list',
|
||||||
|
'--resolve', '--resolve_claims=1',
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
# files
|
# files
|
||||||
|
|
||||||
file_list_result = (await r(
|
file_list_result = (await r(
|
||||||
|
|
|
@ -2030,6 +2030,10 @@ class CollectionCommands(CommandTestCase):
|
||||||
collections = await self.out(self.daemon.jsonrpc_collection_list())
|
collections = await self.out(self.daemon.jsonrpc_collection_list())
|
||||||
self.assertEquals(len(collections['items']), 2)
|
self.assertEquals(len(collections['items']), 2)
|
||||||
|
|
||||||
|
# resolve flag resolves collection claim
|
||||||
|
resolved_collections_tx = await self.out(self.daemon.jsonrpc_collection_list(resolve=True))
|
||||||
|
self.assertIn('canonical_url', resolved_collections_tx[0])
|
||||||
|
|
||||||
await self.collection_abandon(claim_id)
|
await self.collection_abandon(claim_id)
|
||||||
self.assertItemCount(await self.daemon.jsonrpc_collection_list(), 1)
|
self.assertItemCount(await self.daemon.jsonrpc_collection_list(), 1)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue