provide --resolve tag for collection claim, separate from resolving its contents

bugfix and docs generation

review changes
This commit is contained in:
zeppi 2021-02-19 16:14:44 -05:00 committed by Lex Berezhny
parent 9815ddef1f
commit 183fb9f9ff
4 changed files with 46 additions and 7 deletions

View file

@ -3696,7 +3696,7 @@ class Daemon(metaclass=JSONRPCServerType):
COLLECTION_DOC = """
Create, update, list, resolve, and abandon collections.
"""
#| --claims = < claims >
@requires(WALLET_COMPONENT)
async def jsonrpc_collection_create(
self, name, bid, claims, allow_duplicate_name=False,
@ -3993,15 +3993,17 @@ class Daemon(metaclass=JSONRPCServerType):
return await self.jsonrpc_stream_abandon(*args, **kwargs)
@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.
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>]
Options:
--resolve : (bool) resolve collection claim
--resolve_claims=<resolve_claims> : (int) resolve every claim
--account_id=<account_id> : (str) id of the account to use
--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)
if 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
else:
collections = partial(self.ledger.get_collections, wallet=wallet, accounts=wallet.accounts)
collection_count = partial(self.ledger.get_collection_count, wallet=wallet, accounts=wallet.accounts)
collections = partial(
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)
async def jsonrpc_collection_resolve(

View file

@ -1022,8 +1022,10 @@ class Ledger(metaclass=LedgerRegistry):
claims.append(None)
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)
if resolve:
collections = await self._resolve_for_local_results(constraints.get('accounts', []), collections)
if resolve_claims > 0:
for collection in collections:
collection.claims = await self.resolve_collection(collection, page_size=resolve_claims)

View file

@ -365,6 +365,26 @@ class Examples(CommandTestCase):
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
file_list_result = (await r(

View file

@ -2030,6 +2030,10 @@ class CollectionCommands(CommandTestCase):
collections = await self.out(self.daemon.jsonrpc_collection_list())
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)
self.assertItemCount(await self.daemon.jsonrpc_collection_list(), 1)