Merge pull request #11938 from AmineKhaldi/nft_get_info_cmd

Initial iteration of the chia wallet nft get_info command
This commit is contained in:
Amine Khaldi
2022-06-17 09:27:40 +01:00
committed by GitHub
2 changed files with 72 additions and 36 deletions
+24
View File
@@ -723,3 +723,27 @@ def nft_set_did_cmd(
"fee": fee,
}
asyncio.run(execute_with_wallet(wallet_rpc_port, fingerprint, extra_params, set_nft_did))
@nft_cmd.command("get_info", short_help="Get NFT information")
@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("-ni", "--nft-coin-id", help="Id of the NFT coin to get information on", type=str, required=True)
def nft_get_info_cmd(
wallet_rpc_port: Optional[int],
fingerprint: int,
nft_coin_id: str,
) -> None:
import asyncio
from .wallet_funcs import execute_with_wallet, get_nft_info
extra_params = {
"nft_coin_id": nft_coin_id,
}
asyncio.run(execute_with_wallet(wallet_rpc_port, fingerprint, extra_params, get_nft_info))
+48 -36
View File
@@ -19,6 +19,8 @@ from chia.util.config import load_config
from chia.util.default_root import DEFAULT_ROOT_PATH
from chia.util.ints import uint16, uint32, uint64
from chia.cmds.cmds_util import transaction_submitted_msg, transaction_status_msg
from chia.wallet.did_wallet.did_info import DID_HRP
from chia.wallet.nft_wallet.nft_info import NFT_HRP, NFTInfo
from chia.wallet.trade_record import TradeRecord
from chia.wallet.trading.offer import Offer
from chia.wallet.trading.trade_status import TradeStatus
@@ -765,50 +767,50 @@ async def transfer_nft(args: Dict, wallet_client: WalletRpcClient, fingerprint:
print(f"Failed to transfer NFT: {e}")
def print_nft_info(nft: NFTInfo) -> None:
indent: str = " "
owner_did = None if nft.owner_did is None else encode_puzzle_hash(nft.owner_did, DID_HRP)
print()
print(f"{'NFT identifier:'.ljust(26)} {encode_puzzle_hash(nft.launcher_id, NFT_HRP)}")
print(f"{'Launcher coin ID:'.ljust(26)} {nft.launcher_id}")
print(f"{'Launcher puzhash:'.ljust(26)} {nft.launcher_puzhash}")
print(f"{'Current NFT coin ID:'.ljust(26)} {nft.nft_coin_id}")
print(f"{'On-chain data/info:'.ljust(26)} {nft.chain_info}")
print(f"{'Owner DID:'.ljust(26)} {owner_did}")
print(f"{'Royalty percentage:'.ljust(26)} {nft.royalty_percentage}")
print(f"{'Royalty puzhash:'.ljust(26)} {nft.royalty_puzzle_hash}")
print(f"{'NFT content hash:'.ljust(26)} {nft.data_hash.hex()}")
print(f"{'Metadata hash:'.ljust(26)} {nft.metadata_hash.hex()}")
print(f"{'License hash:'.ljust(26)} {nft.license_hash.hex()}")
print(f"{'NFT series total:'.ljust(26)} {nft.series_total}")
print(f"{'Current NFT number in the series:'.ljust(26)} {nft.series_number}")
print(f"{'Metadata updater puzhash:'.ljust(26)} {nft.updater_puzhash}")
print(f"{'NFT minting block height:'.ljust(26)} {nft.mint_height}")
print(f"{'Inner puzzle supports DID:'.ljust(26)} {nft.supports_did}")
print(f"{'NFT is pending for a transaction:'.ljust(26)} {nft.pending_transaction}")
print()
print("URIs:")
for uri in nft.data_uris:
print(f"{indent}{uri}")
print()
print("Metadata URIs:")
for metadata_uri in nft.metadata_uris:
print(f"{indent}{metadata_uri}")
print()
print("License URIs:")
for license_uri in nft.license_uris:
print(f"{indent}{license_uri}")
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.did_wallet.did_info import DID_HRP
from chia.wallet.nft_wallet.nft_info import NFT_HRP, NFTInfo
indent: str = " "
for n in nft_list:
nft = NFTInfo.from_json_dict(n)
owner_did = None if nft.owner_did is None else encode_puzzle_hash(nft.owner_did, DID_HRP)
print()
print(f"{'NFT identifier:'.ljust(26)} {encode_puzzle_hash(nft.launcher_id, NFT_HRP)}")
print(f"{'Launcher coin ID:'.ljust(26)} {nft.launcher_id}")
print(f"{'Launcher puzhash:'.ljust(26)} {nft.launcher_puzhash}")
print(f"{'Current NFT coin ID:'.ljust(26)} {nft.nft_coin_id}")
print(f"{'On-chain data/info:'.ljust(26)} {nft.chain_info}")
print(f"{'Owner DID:'.ljust(26)} {owner_did}")
print(f"{'Royalty percentage:'.ljust(26)} {nft.royalty_percentage}")
print(f"{'Royalty puzhash:'.ljust(26)} {nft.royalty_puzzle_hash}")
print(f"{'NFT content hash:'.ljust(26)} {nft.data_hash.hex()}")
print(f"{'Metadata hash:'.ljust(26)} {nft.metadata_hash.hex()}")
print(f"{'License hash:'.ljust(26)} {nft.license_hash.hex()}")
print(f"{'NFT series total:'.ljust(26)} {nft.series_total}")
print(f"{'Current NFT number in the series:'.ljust(26)} {nft.series_number}")
print(f"{'Metadata updater puzhash:'.ljust(26)} {nft.updater_puzhash}")
print(f"{'NFT minting block height:'.ljust(26)} {nft.mint_height}")
print(f"{'Inner puzzle supports DID:'.ljust(26)} {nft.supports_did}")
print(f"{'NFT is pending for a transaction:'.ljust(26)} {nft.pending_transaction}")
print()
print("URIs:")
for uri in nft.data_uris:
print(f"{indent}{uri}")
print()
print("Metadata URIs:")
for metadata_uri in nft.metadata_uris:
print(f"{indent}{metadata_uri}")
print()
print("License URIs:")
for license_uri in nft.license_uris:
print(f"{indent}{license_uri}")
print_nft_info(nft)
else:
print(f"No NFTs found for wallet with id {wallet_id} on key {fingerprint}")
except Exception as e:
@@ -826,3 +828,13 @@ async def set_nft_did(args: Dict, wallet_client: WalletRpcClient, fingerprint: i
print(f"Transaction to set DID on NFT has been initiated with: {spend_bundle}")
except Exception as e:
print(f"Failed to set DID on NFT: {e}")
async def get_nft_info(args: Dict, wallet_client: WalletRpcClient, fingerprint: int) -> None:
nft_coin_id = args["nft_coin_id"]
try:
response = await wallet_client.get_nft_info(nft_coin_id)
nft_info = NFTInfo.from_json_dict(response["nft_info"])
print_nft_info(nft_info)
except Exception as e:
print(f"Failed to get NFT info: {e}")