Skip to content

Commit

Permalink
#270 Back port fix from cep-18 + #267 nft_kind should be optional on …
Browse files Browse the repository at this point in the history
…install + default (#280)

* #270 Back port fix from cep-18
#267 nft_kind should be optional on install + default

* clippy

* Update doc

* Revert in get_optional_named_arg_with_user_errors
  • Loading branch information
gRoussac authored Jul 8, 2024
1 parent 4c1aa3a commit d13ed09
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 17 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ The following are the required runtime arguments that must be passed to the inst
- `"collection_symbol"`: The symbol representing a given NFT collection, passed in as a `String`. This parameter is required and cannot be changed post installation.
- `"total_token_supply"`: The total number of NFTs that a specific instance of a contract will mint passed in as a `U64` value. This parameter is required.
- `"ownership_mode"`: The [`OwnershipMode`](/docs/modalities.md#ownership) modality that dictates the ownership behavior of the NFT contract. This argument is passed in as a `u8` value and is required at the time of installation.
- `"nft_kind"`: The [`NFTKind`](/docs/modalities.md#nftkind) modality that specifies the off-chain items represented by the on-chain NFT data. This argument is passed in as a `u8` value and is required at the time of installation.
- `"json_schema"`: The JSON schema for the NFT tokens that will be minted by the NFT contract passed in as a `String`. This parameter is required if the metadata kind is set to `CustomValidated(3)` and cannot be changed post installation.
- `"nft_metadata_kind"`: The base metadata schema for the NFTs to be minted by the NFT contract. This argument is passed in as a `u8` value and is required at the time of installation.
- `"identifier_mode"`: The [`NFTIdentifierMode`](/docs/modalities.md#nftidentifiermode) modality dictates the primary identifier for NFTs minted by the contract. This argument is passed in as a `u8` value and is required at the time of installation.
Expand All @@ -58,7 +57,7 @@ The following are the optional parameters that can be passed in at the time of i

- `"minting_mode"`: The [`MintingMode`](/docs/modalities.md#minting) modality that dictates the access to the `mint()` entry-point in the NFT contract. This is an optional parameter that will default to restricting access to the installer of the contract. This parameter cannot be changed once the contract has been installed.
- `"allow_minting"`: The `"allow_minting"` flag allows the installer of the contract to pause the minting of new NFTs. The `allow_minting` is a boolean toggle that allows minting when `true`. If not provided at install the toggle will default to `true`. This value can be changed by the installer by calling the `set_variables()` entrypoint.

- `"nft_kind"`: The [`NFTKind`](/docs/modalities.md#nftkind) modality that specifies the off-chain items represented by the on-chain NFT data. This argument is passed in as a `u8` value and is optional at the time of installation. If not provided at install the toggle will default to `Virtual` This parameter cannot be changed once the contract has been installed.
- `"whitelist_mode"`: The [`WhitelistMode`](/docs/modalities.md#whitelistmode) modality dictates whether the contract whitelist can be updated. This optional parameter will default to an unlocked whitelist that can be updated post installation. This parameter cannot be changed once the contract has been installed.
- `"holder_mode"`: The [`NFTHolderMode`](/docs/modalities.md#nftholdermode) modality dictates which entities can hold NFTs. This is an optional parameter and will default to a mixed mode allowing either `Accounts` or `Contracts` to hold NFTs. This parameter cannot be changed once the contract has been installed.
- `"acl_whitelist"`: The ACL whitelist is a list of accounts and/or contract/package hashes that specifies which accounts and/or contracts can call the `mint()` entrypoint to mint NFTs. This is an optional parameter which will default to an empty whitelist. This value can be changed via the `set_variables` post installation. If the whitelist mode is set to locked, a non-empty whitelist must be passed; else, installation of the contract will fail.
Expand Down
10 changes: 5 additions & 5 deletions client-js/TUTORIAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ npm install casper-cep78-js-client
## Installing a CEP-78 Contract using the JavaScript Client

The `install` method crafts a [Deploy](https://docs.casper.network/deploy-and-deploy-lifecycle/#execution-semantics-deploys) using `InstallArgs`.
As with every deploy created by the SDK, you can send it using the `.send(rpcUrl)` method providing the RPC URL that you want to use. It will return deployHash.
As with every deploy created by the SDK, you can send it using the `.send(rpcUrl)` method providing the RPC URL that you want to use. It will return deployHash.

```js

Expand Down Expand Up @@ -65,7 +65,7 @@ As with every deploy created by the SDK, you can send it using the `.send(rpcUrl
* `ownershipMode` - The `OwnershipMode` modality that dictates the ownership behavior of the NFT contract. This argument is passed in as a `u8` value and is required at the time of installation.
* `nftKind` - The `NFTKind` modality that specifies the off-chain items represented by the on-chain NFT data. This argument is passed in as a `u8` value and is required at the time of installation.
* `nftKind` - The `NFTKind` modality that specifies the off-chain items represented by the on-chain NFT data. This argument is passed in as a `u8` value and is optional at the time of installation.
* `jsonSchema` - The JSON schema for the NFT tokens that will be minted by the NFT contract passed in as a `String`. More information on `NFTMetadataKind` can be found [here](../docs/modalities.md#nftmetadatakind). This parameter may be left empty if metadata kind is set to `Raw(3)`. If the metadata kind is set to `CustomValidated(4)`, it will require a specifically formatted custom schema. This parameter **cannot be changed post installation**.
Expand Down Expand Up @@ -116,7 +116,7 @@ In this example, the [`useSessionCode`](https://github.com/casper-ecosystem/cep-
If `OwnerReverseLookupMode` is set to `NoLookup`, `useSessionCode` will be set to `false` and it will simply mint the token as it does not need to register the recipient.
## Register Recipient
## Register Recipient
As we used `ownerReverseLookupMode: OwnerReverseLookupMode.Complete` in this contract installation, we must register the recipient. To do this, we construct a `register` deploy:
Expand All @@ -132,9 +132,9 @@ As we used `ownerReverseLookupMode: OwnerReverseLookupMode.Complete` in this con
);

const registerDeployHash = await registerDeploy.send("http://localhost:11101/rpc");

```
## Transferring a Token
After minting one or more tokens, you can then use the following code to transfer the tokens between accounts:
Expand Down
9 changes: 3 additions & 6 deletions contract/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2574,12 +2574,9 @@ fn install_contract() {
// Refer to the enum `NFTKind`
// in the `src/modalities.rs` file for details.
// This value cannot be changed after installation.
let nft_kind: u8 = utils::get_named_arg_with_user_errors(
ARG_NFT_KIND,
NFTCoreError::MissingNftKind,
NFTCoreError::InvalidNftKind,
)
.unwrap_or_revert();
let nft_kind: u8 =
utils::get_optional_named_arg_with_user_errors(ARG_NFT_KIND, NFTCoreError::InvalidNftKind)
.unwrap_or(NFTKind::default() as u8);

// Represents whether Accounts or Contracts, or both can hold NFTs for
// a given contract instance. Refer to the enum `NFTHolderMode`
Expand Down
2 changes: 2 additions & 0 deletions contract/src/modalities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ impl TryFrom<u8> for MintingMode {
}
}

#[derive(PartialEq, Eq, Default, Debug)]
#[repr(u8)]
pub enum NFTKind {
/// The NFT represents a real-world physical
Expand All @@ -89,6 +90,7 @@ pub enum NFTKind {
/// The NFT is the virtual representation
/// of a physical notion, e.g a patent
/// or copyright.
#[default]
Virtual = 2,
}

Expand Down
3 changes: 2 additions & 1 deletion contract/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ pub fn get_optional_named_arg_with_user_errors<T: FromBytes>(
) -> Option<T> {
match get_named_arg_with_user_errors::<T>(name, NFTCoreError::Phantom, invalid) {
Ok(val) => Some(val),
Err(_) => None,
Err(NFTCoreError::Phantom) => None,
Err(e) => runtime::revert(e),
}
}

Expand Down
5 changes: 2 additions & 3 deletions docs/modalities.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ and only exists to specify the correlation between on-chain data and off-chain i
2. `Digital`: The NFT represents a digital item, e.g., a unique JPEG or digital art.
3. `Virtual`: The NFT is the virtual representation of a physical notion, e.g., a patent or copyright.

The `NFTKind` mode is a required installation parameter and cannot be changed once the contract has been installed.
This modality is an optional installation parameter and will default to the `Virtual` mode if not provided. However, this mode cannot be changed once the contract has been installed.
The mode is passed in as a `u8` value to `nft_kind` runtime argument.

| NFTKind | u8 |
Expand All @@ -85,8 +85,7 @@ If the `NFTHolderMode` is set to `Contracts` a `ContractHash` whitelist must be
| Contracts | 1 |
| Mixed | 2 |

This modality is an optional installation parameter and will default to the `Mixed` mode if not provided. However, this
mode cannot be changed once the contract has been installed.
This modality is an optional installation parameter and will default to the `Mixed` mode if not provided. However, this mode cannot be changed once the contract has been installed.
The mode is passed in as a `u8` value to `nft_holder_mode` runtime argument.

## WhitelistMode
Expand Down

0 comments on commit d13ed09

Please sign in to comment.