Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#151 make minter optional #152

Merged
merged 2 commits into from
Jan 19, 2024
Merged

Conversation

taitruong
Copy link
Collaborator

@taitruong taitruong commented Jan 10, 2024

PR for #151

Rather prefer having minter: Option<String>:

pub struct InstantiateMsg {
/// Name of the NFT contract
pub name: String,
/// Symbol of the NFT contract
pub symbol: String,
/// The minter is the only one who can create new NFTs.
/// This is designed for a base NFT that is controlled by an external program
/// or contract. You will likely replace this with custom logic in custom NFTs
pub minter: String,
}

In case of none, info.sender should be minter. Makes it easier for other contracts (e.g. minter) re-using this msg.

In most cases creator of contract is also minter. Rn creator (=sender) instantiates contract AND need to provides its own address in minter prop. You can see this in unit tests:

Before: duplicate, since creator is in info.sender and minter.prop

        let info = mock_info(CREATOR, &[]);
        let init_msg = InstantiateMsg {
            name: "SpaceShips".to_string(),
            symbol: "SPACE".to_string(),
            minter: CREATOR.to_string(),
            withdraw_address: None,
        };
        entry::instantiate(deps.as_mut(), mock_env(), info.clone(), init_msg).unwrap();

After: no need to provider minter prop, since creator is sender:

        let info = mock_info(CREATOR, &[]);
        let init_msg = InstantiateMsg {
            name: "SpaceShips".to_string(),
            symbol: "SPACE".to_string(),
            minter: None,
            withdraw_address: None,
        };
        entry::instantiate(deps.as_mut(), mock_env(), info.clone(), init_msg).unwrap();

Instantiation is like this then:

like before, in case caller should NOT be minter/owner (edge case):

{"name": "foo", "symbol": "bar", "minter": "other_than_caller"}

for creator (standard, 99.99% case):

{"name": "foo", "symbol": "bar"}

@shanev @JakeHartnell

@taitruong
Copy link
Collaborator Author

You can also see from adjusted tests - it looks more convenient and natural.

@@ -136,7 +136,7 @@ mod tests {
let init_msg = InstantiateMsg {
name: "SpaceShips".to_string(),
symbol: "SPACE".to_string(),
minter: CREATOR.to_string(),
minter: None,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you scroll up, in line 135, you can see CREATOR is the sender

@taitruong
Copy link
Collaborator Author

taitruong commented Jan 10, 2024

Reason, why I came to this conclusion is this here: https://github.com/public-awesome/launchpad/blob/main/contracts/collections/sg721-base/src/contract.rs#L53-L58

        // cw721 instantiation
        let info = CW721ContractInfoResponse {
            name: msg.name,
            symbol: msg.symbol,
        };
        self.parent.contract_info.save(deps.storage, &info)?;
        cw_ownable::initialize_owner(deps.storage, deps.api, Some(&msg.minter))?;

All this logic can completely be removed, by calling parent.instantiate. Also these 3 props can be replaced by cw721_base::msg::InstantiateMsg: https://github.com/public-awesome/launchpad/blob/main/packages/sg721/src/lib.rs#L118-L120

pub struct InstantiateMsg {
    pub name: String,
    pub symbol: String,
    pub minter: String,
    pub collection_info: CollectionInfo<RoyaltyInfoResponse>,
}

@jhernandezb

Copy link
Collaborator

@JakeHartnell JakeHartnell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with this, curious what others thinks, but agree it would be slightly nicer.

@taitruong
Copy link
Collaborator Author

@shanev need one more approval, then we can merge and release 0.19.0 (#150)

Copy link
Collaborator

@shanev shanev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good change :)

@shanev shanev merged commit 378ae39 into CosmWasm:main Jan 19, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants