Merge pull request #11922 from AmineKhaldi/nft_mint_better_hashes_handling

When minting NFTs, only include the metadata hash and the license hash when they are provided
This commit is contained in:
Amine Khaldi 2022-06-16 23:49:18 +01:00 committed by GitHub
commit fdb60bf8c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 17 additions and 21 deletions

View File

@ -513,9 +513,9 @@ def nft_wallet_create_cmd(
@click.option("-ta", "--target-address", help="Target address", type=str)
@click.option("-nh", "--hash", help="NFT content hash", type=str, required=True)
@click.option("-u", "--uris", help="Comma separated list of URIs", type=str, required=True)
@click.option("-mh", "--metadata-hash", help="NFT metadata hash", type=str, default="00")
@click.option("-mh", "--metadata-hash", help="NFT metadata hash", type=str, default="")
@click.option("-mu", "--metadata-uris", help="Comma separated list of metadata URIs", type=str)
@click.option("-lh", "--license-hash", help="NFT license hash", type=str, default="00")
@click.option("-lh", "--license-hash", help="NFT license hash", type=str, default="")
@click.option("-lu", "--license-uris", help="Comma separated list of license URIs", type=str)
@click.option("-st", "--series-total", help="NFT series total number", type=int, default=1, show_default=True)
@click.option("-sn", "--series-number", help="NFT seriese number", type=int, default=1, show_default=True)

View File

@ -1362,18 +1362,19 @@ class WalletRpcApi:
return {"success": False, "error": "Metadata URIs must be a list"}
if not isinstance(request.get("license_uris", []), list):
return {"success": False, "error": "License URIs must be a list"}
metadata = Program.to(
[
("u", request["uris"]),
("h", hexstr_to_bytes(request["hash"])),
("mu", request.get("meta_uris", [])),
("mh", hexstr_to_bytes(request.get("meta_hash", "00"))),
("lu", request.get("license_uris", [])),
("lh", hexstr_to_bytes(request.get("license_hash", "00"))),
("sn", uint64(request.get("series_number", 1))),
("st", uint64(request.get("series_total", 1))),
]
)
metadata_list = [
("u", request["uris"]),
("h", hexstr_to_bytes(request["hash"])),
("mu", request.get("meta_uris", [])),
("lu", request.get("license_uris", [])),
("sn", uint64(request.get("series_number", 1))),
("st", uint64(request.get("series_total", 1))),
]
if "meta_hash" in request and len(request["meta_hash"]) > 0:
metadata_list.append(("mh", hexstr_to_bytes(request["meta_hash"])))
if "license_hash" in request and len(request["license_hash"]) > 0:
metadata_list.append(("lh", hexstr_to_bytes(request["license_hash"])))
metadata = Program.to(metadata_list)
fee = uint64(request.get("fee", 0))
did_id = request.get("did_id", None)
if did_id is not None:

View File

@ -591,9 +591,9 @@ class WalletRpcClient(RpcClient):
target_address,
hash,
uris,
meta_hash="00",
meta_hash="",
meta_uris=[],
license_hash="00",
license_hash="",
license_uris=[],
series_total=1,
series_number=1,

View File

@ -11,7 +11,6 @@ from chia.simulator.simulator_protocol import FarmNewBlockProtocol
from chia.types.blockchain_format.program import Program
from chia.types.blockchain_format.sized_bytes import bytes32
from chia.types.peer_info import PeerInfo
from chia.util.byte_types import hexstr_to_bytes
from chia.util.ints import uint16, uint32, uint64
from chia.wallet.cat_wallet.cat_wallet import CATWallet
from chia.wallet.nft_wallet.nft_wallet import NFTWallet
@ -395,9 +394,7 @@ async def test_nft_offer_with_metadata_update(two_wallet_nodes: Any, trusted: An
("u", ["https://www.chia.net/img/branding/chia-logo.svg"]),
("h", "0xD4584AD463139FA8C0D9F68F4B59F185"),
("mu", []),
("mh", hexstr_to_bytes("00")),
("lu", []),
("lh", hexstr_to_bytes("00")),
("sn", uint64(1)),
("st", uint64(1)),
]

View File

@ -457,9 +457,7 @@ async def test_nft_wallet_rpc_update_metadata(two_wallet_nodes: Any, trusted: An
("u", ["https://www.chia.net/img/branding/chia-logo.svg"]),
("h", hexstr_to_bytes("0xD4584AD463139FA8C0D9F68F4B59F185")),
("mu", []),
("mh", hexstr_to_bytes("00")),
("lu", []),
("lh", hexstr_to_bytes("00")),
("sn", uint64(1)),
("st", uint64(1)),
]