Skip to content

Commit

Permalink
Added: Support CLI NFT Pagination (#15342)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

* Update chia/rpc/wallet_rpc_client.py

use suggested default, `num=50`

Co-authored-by: Sebastjan Trepca <[email protected]>

* 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 <[email protected]>
  • Loading branch information
yyolk and trepca authored Aug 4, 2023
1 parent 289260c commit a33f86b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
6 changes: 4 additions & 2 deletions chia/cmds/wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
6 changes: 4 additions & 2 deletions chia/cmds/wallet_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions chia/rpc/wallet_rpc_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit a33f86b

Please sign in to comment.