From 7cf6784b5c81b1422d69cf29b6c59d9b2035364e Mon Sep 17 00:00:00 2001 From: Amine Khaldi Date: Wed, 11 May 2022 15:54:48 +0100 Subject: [PATCH] Initial iteration of the NFT0 chia wallet nft transfer command. --- chia/cmds/wallet.py | 30 +++++++++++++++++++++++++++++- chia/cmds/wallet_funcs.py | 12 ++++++++++++ chia/rpc/wallet_rpc_client.py | 5 +++++ 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/chia/cmds/wallet.py b/chia/cmds/wallet.py index 4932588e95..708402e246 100644 --- a/chia/cmds/wallet.py +++ b/chia/cmds/wallet.py @@ -521,7 +521,7 @@ def nft_mint_cmd( @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 add the URI to", type=str, required=True) @click.option("-u", "--uri", help="URI to add to the NFT", type=str, required=True) -def nft_transfer_cmd( +def nft_add_uri_cmd( wallet_rpc_port: Optional[int], fingerprint: int, nft_coin_id: str, @@ -536,3 +536,31 @@ def nft_transfer_cmd( "uri": uri, } asyncio.run(execute_with_wallet(wallet_rpc_port, fingerprint, extra_params, add_uri_to_nft)) + + +@nft_cmd.command("transfer", short_help="Transfer 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("-ni", "--nft-coin-id", help="Id of the NFT coin to transfer", type=str, required=True) +@click.option("-aa", "--artist-address", help="Target artist's wallet address", type=str, required=True) +def nft_transfer_cmd( + wallet_rpc_port: Optional[int], + fingerprint: int, + nft_coin_id: str, + artist_address: str, +) -> None: + import asyncio + from .wallet_funcs import execute_with_wallet, transfer_nft + + extra_params = { + "wallet_id": id, + "nft_coin_id": nft_coin_id, + "artist_address": artist_address, + } + asyncio.run(execute_with_wallet(wallet_rpc_port, fingerprint, extra_params, transfer_nft)) diff --git a/chia/cmds/wallet_funcs.py b/chia/cmds/wallet_funcs.py index 6969cb1d61..e72d53918d 100644 --- a/chia/cmds/wallet_funcs.py +++ b/chia/cmds/wallet_funcs.py @@ -701,3 +701,15 @@ async def add_uri_to_nft(args: Dict, wallet_client: WalletRpcClient, fingerprint print(f"URI added successfully with spend bundle: {spend_bundle}") except Exception as e: print(f"Failed to add URI to NFT: {e}") + + +async def transfer_nft(args: Dict, wallet_client: WalletRpcClient, fingerprint: int) -> None: + try: + wallet_id = args["wallet_id"] + nft_coin_id = args["nft_coin_id"] + artist_address = args["artist_address"] + response = await wallet_client.transfer_nft(wallet_id, nft_coin_id, artist_address) + spend_bundle = response["spend_bundle"] + print(f"NFT transferred successfully with spend bundle: {spend_bundle}") + except Exception as e: + print(f"Failed to transfer NFT: {e}") diff --git a/chia/rpc/wallet_rpc_client.py b/chia/rpc/wallet_rpc_client.py index 6e543b2a51..e4ac94a42a 100644 --- a/chia/rpc/wallet_rpc_client.py +++ b/chia/rpc/wallet_rpc_client.py @@ -579,3 +579,8 @@ class WalletRpcClient(RpcClient): request: Dict[str, Any] = {"wallet_id": wallet_id, "nft_coin_id": nft_coin_id, "uri": uri} response = await self.fetch("nft_add_uri", request) return response + + 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