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

#[ink::trait_definition] doesn't support super trait and default implementation #4

Open
xgreenx opened this issue Jun 8, 2021 · 2 comments
Assignees
Labels
usage-simplification Resolving of this issue will simplify the usage of the library

Comments

@xgreenx
Copy link
Contributor

xgreenx commented Jun 8, 2021

ink! doesn't support generics and default implementation inside of trait definition. It causes us to introduce a separate trait Erc20 on rust level with a default implementation and reuse it in the impl section. It causes the user to declare the implementation of two traits.

impl Erc20 for Erc20Struct {}
impl IErc20 for Erc20Struct {
    #[ink(message)]
    fn token_name(&self) -> Option<String> {
        Erc20::token_name(self)
    }
...
}

instead of

impl IErc20 for Erc20Struct {
    #[ink(message)]
    fn token_name(&self) -> Option<String> {
        IErc20::token_name(self)
    }
...
}
@xgreenx xgreenx added the usage-simplification Resolving of this issue will simplify the usage of the library label Jun 8, 2021
@xgreenx xgreenx self-assigned this Jun 8, 2021
@xgreenx
Copy link
Contributor Author

xgreenx commented Jun 24, 2021

We already have a feature that allows us to get trait definition by indent of the trait. So, we can add support of generics and default implementations to brush trait definition. We will save this trait definition to file and will replace brush trait definition with trait definition from the ink!. But in the case of ink! trait definition we will only use definition without generics and default implementations.

During the implementation of the trait defined via brush, we will paste the default implementation from the trait definition if the user didn't override that.

It will allow us:
Removed derive for IErc20, IOwnable and etc traits.
Will remove internal trait with according naming Erc20, Ownable and etc. It will simplify usage and will avoid two methods with the same signature(for example Erc20 and IErc20 have the same public methods).
It simplifies understanding how it works. The user only must derive storage traits, add an impl section for helper function, and add an impl section for an external trait.

@xgreenx xgreenx changed the title #[ink::trait_definition] doesn't support generics and default implementation #[ink::trait_definition] doesn't support super trait and default implementation Jun 25, 2021
@xgreenx
Copy link
Contributor Author

xgreenx commented Jun 25, 2021

It is PR with the suggested change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
usage-simplification Resolving of this issue will simplify the usage of the library
Projects
None yet
Development

No branches or pull requests

1 participant