feat: simulateStateChanges GraphQL query — Phase 0 scaffolding + walking skeleton - #691
Open
JiahuiWho wants to merge 4 commits into
Open
feat: simulateStateChanges GraphQL query — Phase 0 scaffolding + walking skeleton #691JiahuiWho wants to merge 4 commits into
JiahuiWho wants to merge 4 commits into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds Phase 0 scaffolding for simulating transaction state changes through GraphQL.
Changes:
- Defines the simulation GraphQL API and result variants.
- Adds simulation service wiring, XDR validation, and conversion logic.
- Adds a native SAC transfer walking-skeleton test.
Reviewed changes
Copilot reviewed 7 out of 11 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
internal/services/transaction_simulation.go |
Adds simulation service skeleton and indexer pipeline. |
internal/services/transaction_simulation_test.go |
Tests validation and native SAC transfer processing. |
internal/serve/serve.go |
Wires the simulation service into GraphQL. |
internal/serve/graphql/schema/simulation.graphqls |
Defines simulated state-change types. |
internal/serve/graphql/schema/queries.graphqls |
Exposes the simulation query. |
internal/serve/graphql/resolvers/statechange.resolvers.go |
Regenerates resolver declarations. |
internal/serve/graphql/resolvers/simulation.go |
Converts state changes to GraphQL variants. |
internal/serve/graphql/resolvers/resolver.go |
Adds the simulation dependency. |
internal/serve/graphql/resolvers/queries.resolvers.go |
Implements query and error mapping. |
internal/serve/graphql/generated/models_gen.go |
Adds generated simulation models. |
internal/serve/graphql/generated/generated.go |
Regenerates GraphQL execution code. |
Files not reviewed (2)
- internal/serve/graphql/resolvers/queries.resolvers.go: Generated file
- internal/serve/graphql/resolvers/statechange.resolvers.go: Generated file
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+15
to
+16
| Currently accepts contract (Soroban) transactions, whose changes come from | ||
| RPC simulation; classic transactions are rejected as UNSUPPORTED_TRANSACTION. |
Comment on lines
+66
to
+69
| case errors.Is(err, services.ErrInvalidTransactionXDR): | ||
| return nil, &gqlerror.Error{ | ||
| Message: err.Error(), | ||
| Extensions: map[string]interface{}{"code": "INVALID_TRANSACTION_XDR"}, |
Comment on lines
+100
to
+103
| func (s *transactionSimulationService) stateChangesForTransaction(ctx context.Context, tx ingest.LedgerTransaction) ([]types.StateChange, error) { | ||
| buffer := indexer.NewIndexerBuffer() | ||
| if _, err := s.ledgerIndexer.ProcessLedgerTransactions(ctx, []ingest.LedgerTransaction{tx}, buffer); err != nil { | ||
| return nil, fmt.Errorf("processing transaction through indexer: %w", err) |
Comment on lines
+135
to
+139
| f, ok := raw.(float64) | ||
| if !ok || f < 0 || f > math.MaxUint32 { | ||
| return 0, false | ||
| } | ||
| return uint32(f), true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
GraphQL schema + codegen -
simulateStateChanges(transactionXdr: String!): SimulatedStateChanges!and the newBaseSimulatedStateChangeinterface.TransactionSimulationServiceskeleton + resolver wiring — decodes the envelope and branches on transaction type.Walking skeleton test — synthesizes a native-SAC transfer and asserts the pipeline emits the sender DEBIT and receiver CREDIT with correct accounts, amounts, and token ID. Also covers the error contract.
Why
Phase 0 of simulated transaction state changes: the API surface, service skeleton, and a walking skeleton proving the core assumption
Design doc: Simulated Transaction State Changes
Known limitations
N/A
Issue that this PR addresses
#618
Checklist
PR Structure
allif the changes are broad or impact many packages.Thoroughness
Release