Skip to content

feat: simulateStateChanges GraphQL query — Phase 0 scaffolding + walking skeleton - #691

Open
JiahuiWho wants to merge 4 commits into
mainfrom
feat/618-simulate-state-changes-phase0
Open

feat: simulateStateChanges GraphQL query — Phase 0 scaffolding + walking skeleton #691
JiahuiWho wants to merge 4 commits into
mainfrom
feat/618-simulate-state-changes-phase0

Conversation

@JiahuiWho

Copy link
Copy Markdown
Contributor

What

  1. GraphQL schema + codegen - simulateStateChanges(transactionXdr: String!): SimulatedStateChanges! and the new BaseSimulatedStateChange interface.

  2. TransactionSimulationService skeleton + resolver wiring — decodes the envelope and branches on transaction type.

  3. 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

  • It is not possible to break this PR down into smaller PRs.
  • This PR does not mix refactoring changes with feature changes.
  • This PR's title starts with name of package that is most changed in the PR, or all if the changes are broad or impact many packages.

Thoroughness

  • This PR adds tests for the new functionality or fixes.
  • All updated queries have been tested (refer to this check if the data set returned by the updated query is expected to be same as the original one).

Release

  • This is not a breaking change.
  • This is ready to be tested in development.
  • The new functionality is gated with a feature flag if this is not ready for production.

@JiahuiWho
JiahuiWho marked this pull request as ready for review August 19, 2026 21:01
Copilot AI balanced review requested due to automatic review settings August 19, 2026 21:01
@JiahuiWho JiahuiWho self-assigned this Aug 19, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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
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.

2 participants