77from .crypto .secp256k1 import Secp256k1Keypair
88from .did import create_did
99from .crypto .account import save_account_to_file , load_account_from_file
10+ from .utils .validate import validate_asset_address
1011
1112CONFIG_ACCOUNTS_DIR = "account"
1213
@@ -451,18 +452,20 @@ def execute_smart_contract(self, contract_address: str, smart_contract_data: str
451452 # Return the final response
452453 return tx_response
453454
454- def deploy_nft (self , artifact_file : str , metadata_file : str , nft_data : str , nft_value : float ,
455- nft_metadata_info : str = "" , nft_file_name : str = "" ):
455+ def deploy_nft (self , nft_data : str , nft_value : float , artifact_file : str = "" , metadata_file : str = "" ,
456+ nft_metadata_info : str = "" , nft_file_name : str = "" , nft_id : str = "" ):
456457 """
457458 Deploys an NFT
458459
459460 Args:
460- artifact_file (str): Path to the artifact file.
461- metadata_file (str): (To be Deprecated) Path to the metadata file.
461+ artifact_file (str, optional ): Path to the artifact file.
462+ metadata_file (str, optional ): (To be Deprecated) Path to the metadata file.
462463 nft_data (str): Arbitrary data for the NFT.
463464 nft_value (float): The value of the NFT.
464465 nft_metadata_info (str, optional): Additional metadata information for the NFT. Defaults to "".
465466 nft_file_name (str, optional): Name of the NFT file. Defaults to "".
467+ nft_id (str, optional): Pre-computed IPFS CID v0. If this is passed, then `metadata_file` and
468+ and `artifact_file` are ignored
466469
467470 Returns:
468471 Transaction response from the Rubix node.
@@ -471,12 +474,29 @@ def deploy_nft(self, artifact_file: str, metadata_file: str, nft_data: str, nft_
471474 Exception: If the NFT deployment fails.
472475 """
473476 deployer_did = self .did
477+
478+ # Either nft_id or both artifact_file and metadata_file should be passed.
479+ # Passing all of them or none of them would result in an error
480+ if nft_id != "" and artifact_file != "" and metadata_file != "" :
481+ raise AttributeError ("values for `nft_id`, `artifact_file` and `metadata_file` have been passed. " \
482+ " Either pass `nft_id` or both `artifact_file` and `metadata_file`" )
474483
475- nft_address = self .__generate_nft_address (
476- user_did = deployer_did ,
477- artifact_file = artifact_file ,
478- metadata_file = metadata_file
479- )
484+ if nft_id == "" and artifact_file == "" and metadata_file == "" :
485+ raise AttributeError ("`nft_id`, `artifact_file` and `metadata_file` are empty. " \
486+ " Either pass `nft_id` or both `artifact_file` and `metadata_file`" )
487+
488+ if nft_id == "" :
489+ nft_address = self .__generate_nft_address (
490+ user_did = deployer_did ,
491+ artifact_file = artifact_file ,
492+ metadata_file = metadata_file
493+ )
494+ else :
495+ # validate nft_id
496+ if not validate_asset_address (nft_id ):
497+ raise ValueError (f"nft_id passed is not in a valid format, value: { nft_id } " )
498+
499+ nft_address = nft_id
480500
481501 tx_body = {
482502 "did" : deployer_did ,
0 commit comments