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

Move storage derives to ink crate #1400

Merged
merged 14 commits into from
Sep 20, 2022
Merged

Conversation

ascjones
Copy link
Collaborator

As discussed in #1223, one problem is that the storage traits derive macros (Storable, StorableHint, StorageKey, StorageLayout) generate code which assumes the top level ink crate is in scope e.g. ::ink::storage::traits::StorageKey. Therefore if a user were to import the standalone ink_storage crate and use those derives, it would not work.

This PR solves that by moving the storage derives into the ink crate itself, ensuring it is only possible to use those derives together with the ink crate.

@ascjones ascjones requested review from a team, cmichi and HCastano as code owners September 16, 2022 13:08
@codecov-commenter
Copy link

codecov-commenter commented Sep 16, 2022

Codecov Report

Merging #1400 (e877c90) into master (3eb6eb0) will increase coverage by 0.38%.
The diff coverage is 71.42%.

❗ Current head e877c90 differs from pull request most recent head d8da53d. Consider uploading reports for the commit d8da53d to get more accurate results

@@            Coverage Diff             @@
##           master    #1400      +/-   ##
==========================================
+ Coverage   71.62%   72.01%   +0.38%     
==========================================
  Files         187      185       -2     
  Lines        5844     5813      -31     
==========================================
  Hits         4186     4186              
+ Misses       1658     1627      -31     
Impacted Files Coverage Δ
crates/ink/macro/src/lib.rs 100.00% <ø> (ø)
crates/ink/macro/src/storage/storable.rs 92.68% <ø> (ø)
crates/ink/macro/src/storage/storage_layout.rs 90.24% <ø> (ø)
crates/ink/macro/src/storage/tests/mod.rs 0.00% <ø> (ø)
...nk/tests/ui/contract/pass/storage-packed-fields.rs 12.50% <ø> (ø)
...ests/ui/storage_item/pass/argument_derive_false.rs 100.00% <ø> (ø)
...ts/ui/storage_item/pass/complex_non_packed_enum.rs 88.13% <ø> (ø)
.../ui/storage_item/pass/complex_non_packed_struct.rs 96.42% <ø> (ø)
.../tests/ui/storage_item/pass/complex_packed_enum.rs 100.00% <ø> (ø)
...ests/ui/storage_item/pass/complex_packed_struct.rs 100.00% <ø> (ø)
... and 10 more

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

@ascjones ascjones merged commit e809445 into master Sep 20, 2022
@ascjones ascjones deleted the aj/move-derives-to-ink-crate branch September 20, 2022 11:35
@ascjones ascjones mentioned this pull request Sep 22, 2022
@xiyu1984
Copy link

Hey @ascjones ,
Where is the ::ink_storage::traits::push_spread_root::<Self>(self, &root_key); in 4.0.0-alpha.3?
I have tried ::ink::storage::traits::push_spread_root::<Self>(self, &root_key); but still not found.

image

Are there any suggestions? Thanks~

@ascjones
Copy link
Collaborator Author

Hi @xiyu1984, those methods and traits have been removed as part of the storage rework: see the release notes: https://github.com/paritytech/ink/blob/master/CHANGELOG.md#storage-rework

@xiyu1984
Copy link

xiyu1984 commented Sep 29, 2022

Hi @xiyu1984, those methods and traits have been removed as part of the storage rework: see the release notes: https://github.com/paritytech/ink/blob/master/CHANGELOG.md#storage-rework

Hi @ascjones , thanks a lot. My use case is that I need a re-entry call to a smart contract. That is, Contract A calls contract B, and then contract B calls back to contract A to update a state(a member of contract A). In the last version of ink, I use push_spread_root and pull_spread_root to make sure the state in contract A is updated. The related code can be seen here. Are there any suggestions of how to implement it currently?
Thanks again~

@xgreenx
Copy link
Collaborator

xgreenx commented Sep 29, 2022

@xiyu1984 I can't compile it because I don't have a payload crate, but the fix should look like this dantenetwork/protocol-stack-for-ink#10

@xiyu1984
Copy link

xiyu1984 commented Sep 29, 2022

@xiyu1984 I can't compile it because I don't have a payload crate, but the fix should look like this dantenetwork/protocol-stack-for-ink#10

Hey @xgreenx,
Yes, it works~ Thank you very much~ I remember that I solved the re-entry problem last time with the help of you. So, thanks again!

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.

5 participants