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

Simple struct requires SpreadLayout trait implementation #1440

Closed
h4x3rotab opened this issue Oct 19, 2022 · 1 comment
Closed

Simple struct requires SpreadLayout trait implementation #1440

h4x3rotab opened this issue Oct 19, 2022 · 1 comment

Comments

@h4x3rotab
Copy link

h4x3rotab commented Oct 19, 2022

Suppose we just want to write a simple contract to store some H160 EVM contract address:

#[derive(Encode, Decode, Debug, PackedLayout, SpreadLayout)]
struct Config {
  evm_contract: H160,
}

#[ink(storage)]
struct MyContract {
  config: Config,
}

The compiler will complain that primitive_types::H160 doesn't implement SpreadLayout. So it cannot derive PackedLayout for struct Config.

It would be nice if any data type implements Encode + Decode can be stored in the storage by packing as a bytes blob by default. In this case, H160 is defined outside in the crate primitive_types. I cannot easily implement a trait for that, unless I create a wrapper type and write the boilerplate code.

Tested with ink v3.3.1

@HCastano
Copy link
Contributor

HCastano commented Nov 8, 2022

Hey, sorry for the late response here. As part of ink! 4.0 we've removed SpreadLayout, PackedLayout, et. al (see #1331). I'm gonna close this since you should be able to do this without any problems with ink! 4.0. If you can't feel free to re-open it.

@HCastano HCastano closed this as completed Nov 8, 2022
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

No branches or pull requests

2 participants