-
Notifications
You must be signed in to change notification settings - Fork 11.7k
[graphql-alt] Load balanceChanges from simulate and execute transaction #24338
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
base: graphql-alt-package-execution-context
Are you sure you want to change the base?
[graphql-alt] Load balanceChanges from simulate and execute transaction #24338
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
| #[derive(Clone)] | ||
| /// Effects to the balance (sum of coin values per coin type) of addresses and objects. | ||
| #[derive(Clone, SimpleObject)] | ||
| pub(crate) struct BalanceChange { |
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.
For this change, I have been thinking on a few options:
- Keep
storedfield and add a new constructorfrom_grpc(&GrpcBalanceChange)to convertGrpcBalanceChangetoStoredBalanceChange. However,StoredBalanceChangeis having owner type, whereGrpcBalanceChangeis just having address. We could overcome it by just usingAddressOwnerto wrap the address (as it will be unwrapped to address anyway), but that logic can be confusing to readers as they might thinkSuiAddressis alwaysAddressOwner? - Replace "stored: StoredBalanceChange" by the native BalanceChanges from
sui-types. This works but requires extra conversion for both gpc::BalanceChange and stored::BalanceChange, making the flow more complex. - [This approach] convert the
gpc::BalanceChangeandstored::BalanceChangedirectly toSimpleObjectBalanceChange, which allows us to convert theBalanceChangedirectly to GraphQL type.
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 like this approach for this use case!
9d79779 to
20bea81
Compare
amnn
left a comment
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.
Could we expose the balance changes through the transaction effects contents, rather than through the scope?
| #[derive(Clone)] | ||
| /// Effects to the balance (sum of coin values per coin type) of addresses and objects. | ||
| #[derive(Clone, SimpleObject)] | ||
| pub(crate) struct BalanceChange { |
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 like this approach for this use case!
|
|
||
| // Load balance changes from database using DataLoader | ||
| // First try to get balance changes from execution context (scope) | ||
| if let Some(grpc_balance_changes) = self.scope.balance_changes() { |
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'm surprised to see this in the scope, as opposed to being exposed via the content, like for events -- why is that?
Description
Transactions that are output from simulation don't produce balance changes (because the usual path for returning balance changes involves looking them up in the database). This PR fixes that by loading the balance changes from the gRPC response.
Test plan
How did you test the new or updated feature?
Release notes
Check each box that your changes affect. If none of the boxes relate to your changes, release notes aren't required.
For each box you select, include information after the relevant heading that describes the impact of your changes that a user might notice and any actions they must take to implement updates.