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

Reexport scale dependencies, introduce #[ink::scale_derive] #1890

Merged
merged 43 commits into from
Sep 1, 2023

Conversation

ascjones
Copy link
Collaborator

@ascjones ascjones commented Aug 25, 2023

Closes #1885.

Removes requirement for contracts to have direct dependencies on parity-scale-codec and scale-info, instead using reexports from the ink umbrella crate. This require some additional attributes e.g. #[codec(crate = ::ink::scale)] to specify the path of the reexported crate for the built in derives.

To this end I have added a convenience attribute macro to add the necessary attributes:instead of doing derive(Encode, Decode) or derive(TypeInfo), simply:

#[ink::scale_derive(Encode, Decode, TypeInfo)]

This would expand to

#[derive(::ink::scale::Encode, ::ink::scale::Decode)]
#[codec(crate = ::ink::scale)]
#[cfg_attr(
  feature = "std", 
  derive(::scale_info::TypeInfo),
  scale_info(crate = ::ink::scale_info)
)]

todo

  • update all examples, remove scale dependencies
  • document use of ink::scale_derive
  • ui tests for scale_derive macro

@ascjones ascjones changed the title Reexport scale dependencies, introduce ink::scale_derive macro Reexport scale dependencies, introduce #[ink::scale_derive] Aug 25, 2023
@ascjones ascjones marked this pull request as ready for review August 29, 2023 16:16
@SkymanOne
Copy link
Contributor

#[ink::scale_derive(encode, decode, type_info)]

Can we make derive specs to be camel case?

@ascjones
Copy link
Collaborator Author

#[ink::scale_derive(encode, decode, type_info)]

Can we make derive specs to be camel case?

We could. I had to decide between idiomatic attribute configuration snake_case and aping the special case derive which uses the CamelCase trait names.

I was in two minds and decided to go with the idiomatic attribute config style, on the basis that it is clear what is happening and no magic. Could possibly be persuaded to do use CamelCase based on it being closer to the derive syntax, itself: question is whether that is a good or a bad thing.

@codecov-commenter
Copy link

codecov-commenter commented Aug 29, 2023

Codecov Report

Merging #1890 (a395df9) into master (ff4a0b5) will decrease coverage by 0.06%.
The diff coverage is 33.33%.

@@            Coverage Diff             @@
##           master    #1890      +/-   ##
==========================================
- Coverage   52.96%   52.90%   -0.06%     
==========================================
  Files         215      220       +5     
  Lines        6786     6822      +36     
==========================================
+ Hits         3594     3609      +15     
- Misses       3192     3213      +21     
Files Changed Coverage Δ
crates/env/src/call/create_builder.rs 2.66% <ø> (ø)
...odegen/src/generator/as_dependency/call_builder.rs 0.00% <ø> (ø)
...odegen/src/generator/as_dependency/contract_ref.rs 0.00% <ø> (ø)
...rates/ink/codegen/src/generator/chain_extension.rs 0.00% <ø> (ø)
crates/ink/codegen/src/generator/dispatch.rs 0.00% <ø> (ø)
crates/ink/codegen/src/generator/event.rs 0.00% <ø> (ø)
crates/ink/codegen/src/generator/storage_item.rs 0.00% <ø> (ø)
...nk/codegen/src/generator/trait_def/call_builder.rs 0.00% <ø> (ø)
.../codegen/src/generator/trait_def/call_forwarder.rs 0.00% <ø> (ø)
crates/ink/macro/src/lib.rs 0.00% <0.00%> (ø)
... and 22 more

... and 5 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@ascjones
Copy link
Collaborator Author

#[ink::scale_derive(encode, decode, type_info)]

Can we make derive specs to be camel case?

Done.

@ascjones ascjones merged commit 5fb5477 into master Sep 1, 2023
22 checks passed
@ascjones ascjones deleted the aj/reexport-scale branch September 1, 2023 15:10
@SkymanOne SkymanOne mentioned this pull request Mar 4, 2024
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.

Re-export scale and scale-info from ink entrance crate
4 participants