Merge pull request #11849 from AmineKhaldi/nft_set_did_cmd

Initial iteration of the chia wallet nft set_did command
This commit is contained in:
William Allen
2022-06-10 14:21:44 -05:00
committed by GitHub
3 changed files with 59 additions and 0 deletions
+41
View File
@@ -678,3 +678,44 @@ def nft_list_cmd(wallet_rpc_port: Optional[int], fingerprint: int, id: int) -> N
extra_params = {"wallet_id": id}
asyncio.run(execute_with_wallet(wallet_rpc_port, fingerprint, extra_params, list_nfts))
@nft_cmd.command("set_did", short_help="Set a DID on an NFT")
@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)
@click.option("-di", "--did-id", help="DID Id to set on the NFT", type=str, required=True)
@click.option("-ni", "--nft-coin-id", help="Id of the NFT coin to set the DID on", type=str, required=True)
@click.option(
"-m",
"--fee",
help="Set the fees per transaction, in XCH.",
type=str,
default="0",
show_default=True,
callback=validate_fee,
)
def nft_set_did_cmd(
wallet_rpc_port: Optional[int],
fingerprint: int,
id: int,
did_id: str,
nft_coin_id: str,
fee: str,
) -> None:
import asyncio
from .wallet_funcs import execute_with_wallet, set_nft_did
extra_params = {
"wallet_id": id,
"did_id": did_id,
"nft_coin_id": nft_coin_id,
"fee": fee,
}
asyncio.run(execute_with_wallet(wallet_rpc_port, fingerprint, extra_params, set_nft_did))
+13
View File
@@ -799,3 +799,16 @@ async def list_nfts(args: Dict, wallet_client: WalletRpcClient, fingerprint: int
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}")
async def set_nft_did(args: Dict, wallet_client: WalletRpcClient, fingerprint: int) -> None:
wallet_id = args["wallet_id"]
did_id = args["did_id"]
nft_coin_id = args["nft_coin_id"]
fee = args["fee"]
try:
response = await wallet_client.set_nft_did(wallet_id, did_id, nft_coin_id, fee)
spend_bundle = response["spend_bundle"]
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}")
+5
View File
@@ -650,3 +650,8 @@ class WalletRpcClient(RpcClient):
request: Dict[str, Any] = {"wallet_id": wallet_id}
response = await self.fetch("nft_get_nfts", request)
return response
async def set_nft_did(self, wallet_id, did_id, nft_coin_id, fee):
request: Dict[str, Any] = {"wallet_id": wallet_id, "did_id": did_id, "nft_coin_id": nft_coin_id, "fee": fee}
response = await self.fetch("nft_set_nft_did", request)
return response