From a33f86bf112a9ff7f685c50fa0b065ed08ae961e Mon Sep 17 00:00:00 2001 From: Joseph Chiocchi Date: Fri, 4 Aug 2023 00:24:01 -0500 Subject: [PATCH] Added: Support CLI NFT Pagination (#15342) * first pass first exposing `--num` and `--start-index` through to `nft_get_nfts` rpc call * broke signature, fallback to defaults here broke `list_nfts` signature for 1 test, supply defaults here like `vc_get_list` does (thinking `100_000` will revert back to `50` for count/num as well, but leaving it as-is for now) * Update chia/cmds/wallet.py Co-authored-by: Sebastjan Trepca * Update chia/rpc/wallet_rpc_client.py use suggested default, `num=50` Co-authored-by: Sebastjan Trepca * update `--start-index` help message for `nft list` cmd * lost scope, fix indent on list_nft in wallet_rpc_client * fix eager formatting * missing annotations on signature * black formatting --------- Co-authored-by: Sebastjan Trepca --- chia/cmds/wallet.py | 6 ++++-- chia/cmds/wallet_funcs.py | 6 ++++-- chia/rpc/wallet_rpc_client.py | 4 ++-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/chia/cmds/wallet.py b/chia/cmds/wallet.py index 61ecab9371e6..7aa5d1b2d416 100644 --- a/chia/cmds/wallet.py +++ b/chia/cmds/wallet.py @@ -1164,10 +1164,12 @@ def nft_transfer_cmd( ) @click.option("-f", "--fingerprint", help="Set the fingerprint to specify which key to use", type=int) @click.option("-i", "--id", help="Id of the NFT wallet to use", type=int, required=True) -def nft_list_cmd(wallet_rpc_port: Optional[int], fingerprint: int, id: int) -> None: +@click.option("--num", help="Number of NFTs to return", type=int, default=50) +@click.option("--start-index", help="Which starting index to start listing NFTs from", type=int, default=0) +def nft_list_cmd(wallet_rpc_port: Optional[int], fingerprint: int, id: int, num: int, start_index: int) -> None: from .wallet_funcs import list_nfts - asyncio.run(list_nfts(wallet_rpc_port, fingerprint, id)) + asyncio.run(list_nfts(wallet_rpc_port, fingerprint, id, num, start_index)) @nft_cmd.command("set_did", help="Set a DID on an NFT") diff --git a/chia/cmds/wallet_funcs.py b/chia/cmds/wallet_funcs.py index f8ddc9c78f45..b79e1a83c827 100644 --- a/chia/cmds/wallet_funcs.py +++ b/chia/cmds/wallet_funcs.py @@ -1183,10 +1183,12 @@ def print_nft_info(nft: NFTInfo, *, config: Dict[str, Any]) -> None: print(f"{indent}{license_uri}") -async def list_nfts(wallet_rpc_port: Optional[int], fp: Optional[int], wallet_id: int) -> None: +async def list_nfts( + wallet_rpc_port: Optional[int], fp: Optional[int], wallet_id: int, num: int, start_index: int +) -> None: async with get_wallet_client(wallet_rpc_port, fp) as (wallet_client, fingerprint, config): try: - response = await wallet_client.list_nfts(wallet_id) + response = await wallet_client.list_nfts(wallet_id, num, start_index) nft_list = response["nft_list"] if len(nft_list) > 0: for n in nft_list: diff --git a/chia/rpc/wallet_rpc_client.py b/chia/rpc/wallet_rpc_client.py index 4e5cdf9d5c73..22408a44c098 100644 --- a/chia/rpc/wallet_rpc_client.py +++ b/chia/rpc/wallet_rpc_client.py @@ -1007,8 +1007,8 @@ async def count_nfts(self, wallet_id: Optional[int]): response = await self.fetch("nft_count_nfts", request) return response - async def list_nfts(self, wallet_id) -> dict[str, Any]: - request: Dict[str, Any] = {"wallet_id": wallet_id, "num": 100_000} + async def list_nfts(self, wallet_id, num: int = 50, start_index: int = 0): + request: Dict[str, Any] = {"wallet_id": wallet_id, "num": num, "start_index": start_index} response = await self.fetch("nft_get_nfts", request) return response