Merge pull request #11483 from AmineKhaldi/nft0_transfer_cmd

Initial iteration of the NFT0 chia wallet nft transfer command
This commit is contained in:
Sebastjan Trepca
2022-05-11 17:54:41 +02:00
committed by GitHub
3 changed files with 46 additions and 1 deletions
+29 -1
View File
@@ -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))
+12
View File
@@ -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}")
+5
View File
@@ -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