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

Feature/minting lazy #45

Merged
merged 9 commits into from
Feb 16, 2023
Merged

Feature/minting lazy #45

merged 9 commits into from
Feb 16, 2023

Conversation

boyswan
Copy link
Contributor

@boyswan boyswan commented Feb 12, 2023

This decouples the core and lazy minting functionality, and instead provides 2 traits Minting & MintingLazy to allow the user to choose their desired implementation.

I propose some small changes to the trait methods to allow consistency between core/lazy and provide a clearer api.

Minting (Ownable, Non-payable)

pub trait Minting {
    fn mint(&mut self, to: AccountId) -> Result<Id>;
    fn mint_many(&mut self, to: AccountId, mint_amount: u64) -> Result<(Id, Id)>;
    fn assign_metadata(&mut self, token_id: Id, metadata: String) -> Result<()>;
    fn max_supply(&self) -> u64;
    fn token_uri(&self, token_id: u64) -> Result<String>;
} 

MintingLazy (Payable)

pub trait MintingLazy {
    fn mint(&mut self) -> Result<()>;
    fn mint_many(&mut self, mint_amount: u64) -> Result<()>;
    fn price(&self) -> Balance;
    fn max_supply(&self) -> u64;
    fn token_uri(&self, token_id: u64) -> Result<String>;
} 

Other than minting methods, the only differences between the implementations are Minting having assing_metadata as this is not a needed for lazy, and price is only available in MintingLazy.

Other updates include:

  • Return Id and (Id, Id) (id range) for the Minting implementation for use cross-contract logic.
  • Decouple assign_metadata from minting logic. This provides greater flexibility. Current implementation only caters for single-mint-with-metadata.
  • Moving common minting behaviour to underlying internal trait.
  • Create equippable-lazy example, which is used in the JS tests.
  • Remove unwraps in token_uri

I have also moved the minting tests into the minting crate, and split them between core & lazy.

Copy link

@steven2308 steven2308 left a comment

Choose a reason for hiding this comment

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

This is a great change!
I just left a couple minor doubts to to my lack of knowledge on ink!.

self.get_attribute(collection_id, String::from("baseUri"))
.and_then(|uri| PreludeString::from_utf8(uri).ok())
.map(|uri| uri + &token_id.to_string() + &PreludeString::from(".json"))
};

Choose a reason for hiding this comment

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

This seems very opinionated. Can implementers override it in case they want a different logic?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So I left the existing logic intact but just refactored away some potentially unsafe code. Maybe @Maar-io can answer this better than me!

Copy link
Contributor

Choose a reason for hiding this comment

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

Any of the default fn can be overridden. Just check how Evens are handled.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do we think the from_attribute part of the logic is clear enough? It confused me a little as it could be completely different from the metadata the user has assigned to a token, which is what the user is expecting to return.

Would it not be clearer to return None if their metadata has not been set, and then it's up to the user to handle this with custom logic (such as what's in from_attribute)?

Copy link
Contributor

Choose a reason for hiding this comment

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

we do not need to use attributes at all. They come from metadata trait but if it is confusing, better to remove it and use contract's storage

crates/minting/src/internal.rs Outdated Show resolved Hide resolved
@Maar-io
Copy link
Contributor

Maar-io commented Feb 16, 2023

Would it make sense to move rmrk_example_equippable::tests: into equippable crate?

Copy link
Contributor

@Maar-io Maar-io left a comment

Choose a reason for hiding this comment

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

LGTM

I'll move it to ink 4.0 soon and take a deeper look

@boyswan
Copy link
Contributor Author

boyswan commented Feb 16, 2023

Would it make sense to move rmrk_example_equippable::tests: into equippable crate?

Yeah definitely, will make a separate PR for it though and keep this one to minting

@boyswan boyswan merged commit 6f8043e into main Feb 16, 2023
@boyswan boyswan deleted the feature/minting-lazy branch February 16, 2023 17:34
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

3 participants