Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial iteration of the NFT0 chia wallet nft list command #11485

Merged
merged 1 commit into from
May 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions chia/cmds/wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -564,3 +564,21 @@ def nft_transfer_cmd(
"artist_address": artist_address,
}
asyncio.run(execute_with_wallet(wallet_rpc_port, fingerprint, extra_params, transfer_nft))


@nft_cmd.command("list", short_help="List the current NFTs")
@click.option(
"-wp",
"--wallet-rpc-port",
help="Set the port where the Wallet is hosting the RPC interface. See the rpc_port under wallet in config.yaml",
type=int,
default=None,
)
@click.option("-f", "--fingerprint", help="Set the fingerprint to specify which wallet 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:
import asyncio
from .wallet_funcs import execute_with_wallet, list_nfts

extra_params = {"wallet_id": id}
asyncio.run(execute_with_wallet(wallet_rpc_port, fingerprint, extra_params, list_nfts))
27 changes: 27 additions & 0 deletions chia/cmds/wallet_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -713,3 +713,30 @@ async def transfer_nft(args: Dict, wallet_client: WalletRpcClient, fingerprint:
print(f"NFT transferred successfully with spend bundle: {spend_bundle}")
except Exception as e:
print(f"Failed to transfer NFT: {e}")


async def list_nfts(args: Dict, wallet_client: WalletRpcClient, fingerprint: int) -> None:
wallet_id = args["wallet_id"]
try:
response = await wallet_client.list_nfts(wallet_id)
nft_list = response["nft_list"]
if len(nft_list) > 0:
from chia.wallet.nft_wallet.nft_info import NFTInfo

indent: str = " "

for n in nft_list:
nft = NFTInfo.from_json_dict(n)
print()
print(f"{'Launcher coin ID:'.ljust(23)} {nft.launcher_id}")
print(f"{'Current NFT coin ID:'.ljust(23)} {nft.nft_coin_id}")
print(f"{'NFT content hash:'.ljust(23)} {nft.data_hash}")
print(f"{'Current NFT version:'.ljust(23)} {nft.version}")
print()
print("URIs:")
for uri in nft.data_uris:
print(f"{indent}{uri}")
else:
print(f"No NFTs found for wallet with id {wallet_id} on key {fingerprint}")
except Exception as e:
print(f"Failed to list NFTs for wallet with id {wallet_id} on key {fingerprint}: {e}")
5 changes: 5 additions & 0 deletions chia/rpc/wallet_rpc_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -584,3 +584,8 @@ async def transfer_nft(self, wallet_id, nft_coin_id, artist_address):
request: Dict[str, Any] = {"wallet_id": wallet_id, "nft_coin_id": nft_coin_id, "target_address": artist_address}
response = await self.fetch("nft_transfer_nft", request)
return response

async def list_nfts(self, wallet_id):
request: Dict[str, Any] = {"wallet_id": wallet_id}
response = await self.fetch("nft_get_nfts", request)
return response