#[ink::trait_definition] doesn't support super trait and default implementation
xgreenx opened this issue · comments
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)
}
...
}
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.
It is PR with the suggested change.