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

Custom trait implementation #125

Open
Artemka374 opened this issue Aug 3, 2023 · 4 comments
Open

Custom trait implementation #125

Artemka374 opened this issue Aug 3, 2023 · 4 comments
Assignees
Labels
enhancement New feature or request

Comments

@Artemka374
Copy link
Contributor

In OpenBrush 4.0-beta it is possible to avoid boilerplate code with usage of implementation macro, but currently it only works with OpenBrush native traits. If some projects want to separate logics of custom trait implementation and actual contract file, there will still be a lot of boilerplate code, that should be written manually. We can resolve this issue in the following way:

  1. Create something like trait_implementation macro that will be used on TraitImpl. It will have the parameter - the actual trait naming, for which implementation is described.
  2. trait_implementation macro will generate functional macro, like trait_impl!(Contract) that will generate
impl Trait for Contract {
	#[ink(message)]
	fn message(&self) {
		TraitImpl::message(self)
	}
}
  1. This macro can be integrated in implementation macro, and it will use it on storage struct
  2. Macro does not allow overriding the implementation, but could reduce a lot amount of boilerplate code in contract implementations.
@Artemka374 Artemka374 added the enhancement New feature or request label Aug 3, 2023
@PierreOssun
Copy link
Contributor

Seems reasonable like this but how do you deal with payable functions ?

@deuszx
Copy link

deuszx commented Aug 3, 2023

Thanks for starting this. IMHO all solutions will be stubs while we wait for the proper/fix of the trait system in ink! itself. Tracking issue: use-ink/ink#1689

@Artemka374
Copy link
Contributor Author

Seems reasonable like this but how do you deal with payable functions ?

We can add the payable marker that will work inside the trait_implementation macro, so messages that are payable will be generated also as #[ink(payable)]

@Artemka374
Copy link
Contributor Author

Thanks for starting this. IMHO all solutions will be stubs while we wait for the proper/fix of the trait system in ink! itself. Tracking issue: paritytech/ink#1689

That's true, but until this issue in ink! is not fixed, we still can implement our own solution for this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants