Skip to content

feat(rest): expose view function evaluation endpoints#4310

Merged
vicsn merged 11 commits into
stagingfrom
copilot/feature-expose-new-api-endpoint
Jun 15, 2026
Merged

feat(rest): expose view function evaluation endpoints#4310
vicsn merged 11 commits into
stagingfrom
copilot/feature-expose-new-api-endpoint

Conversation

Copilot AI commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Adds REST endpoints to evaluate Aleo view functions against ledger state, as exposed by VM::evaluate_view_at_height in snarkVM. Both a historic (specific block height) and a latest-height variant are provided.

New endpoints

Both require the history feature.

POST /{network}/program/{id}/view/{functionName}/{height} — evaluate at a specific block height

POST /{network}/program/{id}/view/{functionName} — evaluate at the latest block height

  • Body: JSON array of string-encoded inputs
  • Response: JSON array of string-encoded outputs
# At a specific height
curl -X POST https://api.example.com/mainnet/program/vw_lifecycle.aleo/view/total_balance/1000 \
  -H 'Content-Type: application/json' \
  -d '["aleo1abc..."]'
# → ["42u64"]

# At the latest height
curl -X POST https://api.example.com/mainnet/program/vw_lifecycle.aleo/view/total_balance \
  -H 'Content-Type: application/json' \
  -d '["aleo1abc..."]'
# → ["42u64"]

Changes

  • Cargo.toml

    • Updated snarkVM rev to e4a7a945 — adds program-edition–aware view evaluation so evaluate_view_at_height resolves the program edition live at the queried height
  • node/rest/src/routes.rs

    • Add #[cfg(feature = "history")] use snarkvm::prelude::Value
    • Add ViewFunctionRoute<N> path extractor type alias
    • Add parse_view_inputs<N> helper (mirrors existing parse_historical_mapping_keys pattern)
    • Add evaluate_view handler: parses inputs, calls vm.evaluate_view_at_height in spawn_blocking, returns outputs as JSON strings
    • Add evaluate_view_latest handler: same as evaluate_view but captures latest_height() inside spawn_blocking to minimize the sampling-to-evaluation window
  • node/rest/src/lib.rs

    • Register both routes under the existing #[cfg(feature = "history")] block
  • .ci/test_devnet.sh

    • Add view compute_sum function to test_program.aleo (computes 1u32 + 2u32)
    • Add CI assertions querying both endpoints and verifying the expected output "3u32"

…lock height

Add `POST /{network}/program/{id}/view/{functionName}/{height}` endpoint,
gated behind `#[cfg(feature = "history")]`.

The request body is a JSON array of string-encoded inputs, e.g.:
  ["aleo1...", "10u64"]

The handler calls `VM::evaluate_view_at_height` and returns a JSON array
of string-encoded output values.
Copilot AI changed the title [WIP] Expose new API endpoint to read view function data feat(rest): expose view function evaluation endpoint Jun 9, 2026
Copilot finished work on behalf of vicsn June 9, 2026 18:02
Copilot AI requested a review from vicsn June 9, 2026 18:02
@vicsn

vicsn commented Jun 10, 2026

Copy link
Copy Markdown
Collaborator

@copilot update the snarkVM rev in the top-level Cargo.toml, add a new endpoint which evaluates a view at the latest height, and extend .ci/test_devnet.sh so that test_program.aleo contains a view and we query the two new view API endpoints.

Copilot AI added 2 commits June 10, 2026 10:43
…evnet test

- Update snarkVM rev from c457b6b9e to e4a7a945 (historic program edition support)
- Add POST /{network}/program/{id}/view/{function} endpoint for latest height
- Register new route in lib.rs alongside the height-specific route
- Add `view get_value` to test_program.aleo in test_devnet.sh
- Test both view endpoints (latest + specific height) in test_devnet.sh
- Move height capture inside spawn_blocking to minimize race window
- Rename test view function from get_value to compute_sum for clarity

Copilot AI commented Jun 10, 2026

Copy link
Copy Markdown
Contributor Author

@copilot update the snarkVM rev in the top-level Cargo.toml, add a new endpoint which evaluates a view at the latest height, and extend .ci/test_devnet.sh so that test_program.aleo contains a `vie...

Done in commits b56c3c7 and ab6e72e:

  • Updated snarkVM rev to e4a7a945 (adds historic program-edition resolution so evaluate_view_at_height uses the program edition that was live at the queried height)
  • Added POST /{network}/program/{id}/view/{function} — evaluates at the latest height (height is captured inside spawn_blocking to minimize the sampling-to-evaluation window)
  • Extended .ci/test_devnet.sh: added a view compute_sum to test_program.aleo that computes 1u32 + 2u32, then asserts "3u32" is returned from both the latest-height endpoint and the specific-height endpoint

Copilot AI changed the title feat(rest): expose view function evaluation endpoint feat(rest): expose view function evaluation endpoints Jun 10, 2026
Copilot finished work on behalf of vicsn June 10, 2026 10:47
Comment thread node/rest/src/routes.rs
Comment thread node/rest/src/routes.rs
Comment thread node/rest/src/routes.rs
@vicsn vicsn force-pushed the copilot/feature-expose-new-api-endpoint branch from a5b5f08 to 8ad736d Compare June 12, 2026 19:55
@vicsn vicsn marked this pull request as ready for review June 15, 2026 07:34
@vicsn vicsn requested a review from Antonio95 June 15, 2026 07:53
@vicsn vicsn requested a review from ljedrz June 15, 2026 07:53
ljedrz
ljedrz previously approved these changes Jun 15, 2026

@ljedrz ljedrz left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'm not familiar with the new snarkVM-side feature, but the snarkOS impl looks good to me.

@vicsn vicsn merged commit 16a4863 into staging Jun 15, 2026
5 of 6 checks passed
@vicsn vicsn deleted the copilot/feature-expose-new-api-endpoint branch June 15, 2026 08:32
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.

[Feature] Expose new API endpoint which can read view function data

5 participants