-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
feat!: fetch and cache chain info on Provider
when initialized
#1181
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good, I am in favour of bringing us closer to the Rust SDK and improving the UX. However couple comments on the approach:
- If
connect()
is now paramount to populateconsensusParameters
, we should make the constructor private and thereforeProvider
becomes instantiatable only viaconnect()
. Therefore we won't need to encourage one way or the other and it is enforced. We could introduce aProviderFactory
to handle the provision of a packaged provider but this is potentially an unnecessary level of abstraction if we are in preference of dev ex and bringing us closer to the Rust SDK. - Or we maintain the API, and call
connect()
from within the constructor (not my preference but lots of breaking changes / tutorials to think of). - Another thought is that now
consensusParameters
and the provider itself are now tightly bound. Should we be makingurl
read only, and restricting the ability to update a url as that itself should refetch the params. Or we make the url update in turn refetch. But I feel as if we are restricting those, we should just be reinstantiating aProvider
class?
A bunch of spaghetti code still, don't review yet pls :P |
Provider
when initializedProvider
when initialized
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-
I think it's worth doing a final search/replace for removing the residual hardcoded
http://127.0.0.1:4000/graphql
addresses in favor of theFUEL_NETWORK_URL
constant. -
We should not postpone the resolution of the broken tests since it can hide critical problems with the taken approach. Addressing and uncommenting those should also fix the failing checks of the next point below.
-
There are a couple of failing checks here (the last ones), probably due to the commented-out tests mentioned above:
Summary
This PR caches the
chainInfo
for a given Fuel node on theProvider
instance whenever aProvider
is initialized.Motivation
Please see #1176 for a detailed breakdown of the problem at hand, but tldr: we are currently using a lot of hardcoded values for some constants that we use when creating transactions. These hardcoded values served us well until now, but we now need to fetch them from the chain dynamically. This has been requested as a top priority by the frontend team.
Breaking Changes
Because of the nature of the changes introduced in this PR, and the fact that
Provider
is used so widely in our SDK, there are multiple breaking changes that we need to be aware of and need to communicate to our users:1. Initializing the
Provider
2.
Wallet methods
All of these methods now require a
Provider
to be passed in:3.
Account
class4.
PrivateKeyVault
5.
MnemonicVault
Same as
PrivateKeyVault
. The constructor requires aprovider
to be passed in.6.
WalletManager
The
VaultConfig
now requires aprovider
to be passed in.7.
Predicate
Other notes
To demonstrate the fact that we can now use fresh on-chain values for some of the previosuly hard-coded constants, I have refactored the usage of the
VM_TX_MEMORY
constant. This constant is used to calculate the contract call script's data offset.Closes #1176
Closes #1260