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

refactor!: workspace + ports + adapters #73

Merged
merged 23 commits into from
May 8, 2024
Merged

Conversation

segfault-magnet
Copy link
Contributor

The previous organisation of everything being in one crate had the downside of all dependencies being available to you in every place. That meant you can circumvent the database, eth and fuel traits. The LSP would suggest things you probably aren't looking for (sqlx::Postgres vs storage::Postgres). You can use whatever type you like and couple the project tighter to a dependency.

The project was separated according to the following guidelines:

  • Our ports are now in a separate crate called ports.
    If you want your code to interact with any of the outside deps (the eth or fuel nodes or with the database), just add a dependency on ports with the feature flags of the ports you want. You're now dependent only on the interface and you're not pulling in ethers-rs or sqlx or fuel-core-client. You're forced to use the interface if you want to communicate with the external systems. Also the compile targets drop significantly and the autocompletion thanks you.
    • Any type that shows up in a port needs to be reexported from the ports crate. This is so you don't have to guess what crate you need if U256 shows up in a port. For types we borrow from ethers ethers-core was used so not to drag in the whole sdk just to reexport a few types.
    • A port declares its own error types. It doesn't make sense for a port to the fuel node to have the common error with the Error::Storage variant.
    • An adapter can internally use whatever errors they want, but any public facing API should use the port error. This just makes life easier for error conversions later on in main. This is easily achieved by making the adapter errors pub(crate) so you'll get an error/warning if you try to include them in any pub method.
  • Our adapters are separated each into a separate crate. fuel, eth and storage. These should only be used by the main binary. Once started every other component accesses them through the ports crate mentioned above.
  • Services have been moved to the services crate. This forces you to write services against the ports since services doesn't have a dep on any of the adapters.
  • the e2e doesn't have to recreate the adapters now and can use whatever adapter it needs, in our case fuel and eth.
  • The EthereumAdapter was split into two ports: Api and Contract. Api is used by the wallet balance tracker and contains general purpose eth node API calls. Contract represents the contract binding (much like a contract_instance in fuels-rs).
  • Internally the eth naming was replaced with L1 wherever appropriate. Any public configuration wasn't changed until we actually need to support anything other than eth.

@segfault-magnet segfault-magnet self-assigned this May 6, 2024
Copy link
Contributor

@hal3e hal3e left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Beautiful! This will make the DevX so much better! 🚀

@segfault-magnet segfault-magnet merged commit 5a93223 into master May 8, 2024
7 checks passed
@segfault-magnet segfault-magnet deleted the chore/workspaces branch May 8, 2024 16:38
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.

3 participants