Merge pull request #11948 from AmineKhaldi/add_uri_cli_mu_lu

Introduce the ability to update metadata and license URIs in the NFT add_uri command
This commit is contained in:
Amine Khaldi
2022-06-18 21:00:47 +01:00
committed by GitHub
2 changed files with 23 additions and 3 deletions
+7 -1
View File
@@ -595,7 +595,9 @@ def nft_mint_cmd(
@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)
@click.option("-ni", "--nft-coin-id", help="Id of the NFT coin to add the URI to", type=str, required=True)
@click.option("-u", "--uri", help="URI to add to the NFT", type=str, required=True)
@click.option("-u", "--uri", help="URI to add to the NFT", type=str)
@click.option("-mu", "--metadata-uri", help="Metadata URI to add to the NFT", type=str)
@click.option("-lu", "--license-uri", help="License URI to add to the NFT", type=str)
@click.option(
"-m",
"--fee",
@@ -611,6 +613,8 @@ def nft_add_uri_cmd(
id: int,
nft_coin_id: str,
uri: str,
metadata_uri: str,
license_uri: str,
fee: str,
) -> None:
import asyncio
@@ -620,6 +624,8 @@ def nft_add_uri_cmd(
"wallet_id": id,
"nft_coin_id": nft_coin_id,
"uri": uri,
"metadata_uri": metadata_uri,
"license_uri": license_uri,
"fee": fee,
}
asyncio.run(execute_with_wallet(wallet_rpc_port, fingerprint, extra_params, add_uri_to_nft))
+16 -2
View File
@@ -745,9 +745,23 @@ async def add_uri_to_nft(args: Dict, wallet_client: WalletRpcClient, fingerprint
wallet_id = args["wallet_id"]
nft_coin_id = args["nft_coin_id"]
uri = args["uri"]
metadata_uri = args["metadata_uri"]
license_uri = args["license_uri"]
if len([x for x in (uri, metadata_uri, license_uri) if x is not None]) > 1:
raise ValueError("You must provide only one of the URI flags")
if uri is not None and len(uri) > 0:
key = "u"
uri_value = uri
elif metadata_uri is not None and len(metadata_uri) > 0:
key = "mu"
uri_value = metadata_uri
elif license_uri is not None and len(license_uri) > 0:
key = "lu"
uri_value = license_uri
else:
raise ValueError("You must provide at least one of the URI flags")
fee: int = int(Decimal(args["fee"]) * units["chia"])
key = args.get("meta_uri", "u")
response = await wallet_client.add_uri_to_nft(wallet_id, nft_coin_id, key, uri, fee)
response = await wallet_client.add_uri_to_nft(wallet_id, nft_coin_id, key, uri_value, fee)
spend_bundle = response["spend_bundle"]
print(f"URI added successfully with spend bundle: {spend_bundle}")
except Exception as e: