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

TopLevelStorage dependency injection #120

Open
wants to merge 4 commits into
base: stylus
Choose a base branch
from

Conversation

qalisander
Copy link

@qalisander qalisander commented Apr 24, 2024

Description

High Level

Low Level

  • TopLevelStorage got two additional functions to retrieve inner laying type of contract by generic param <S>.
image
  • A new trait StorageLevel exposes two similar functions that just returns optional reference to the type <S>.
image
  • StorageLevel implemented by every type that can exist in contract storage same as StorageType. Simple storage types implementation returns just None since we're not expecting them to store inherited contract.
  • Contracts implement StorageLevel within solidity_storage macro. Implementation checks that type of self is T if so reference will be returned (unsafe reference cast). Since every storage type implements StorageLevel trait then we can call same functions in every field recursively.
  • We can remove BorrowMut constraint from the router trait and use our newly created functions to retrieve references to inner contracts. This example with inheritance of three is working now.
  • #[borrow] attributes will generate Borrow and BorrowMut bindings still but basically there is no need in them.

Compatibility

  • generically typed contracts should have generics restricted by 'static lifetime. (example)

Checklist

  • I have documented these changes where necessary.
  • I have read the DCO and ensured that these changes comply.
  • I assign this work under its open source licensing.

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.

Unable to declare non #[entrypoint] struct with #[borrow] and generics
1 participant