Skip to content

feat: detect read-only functions and hide Submit for view calls#37

Open
OTimileyin wants to merge 1 commit into
ShippedLabs:mainfrom
OTimileyin:feat/readonly-function-detection
Open

feat: detect read-only functions and hide Submit for view calls#37
OTimileyin wants to merge 1 commit into
ShippedLabs:mainfrom
OTimileyin:feat/readonly-function-detection

Conversation

@OTimileyin

Copy link
Copy Markdown
Contributor

Closes #17
Title: feat: detect read-only functions and hide Submit for view calls

Summary

  • extractFunctions in contract-parser.ts now emits isReadOnly: null for every function at parse time — the Soroban XDR spec (ScSpecFunctionV0) exposes no readonly/view attribute, so the spec path is unavailable and null is the correct initial state.
  • simulateCall in invocation.ts now returns { value, isReadimulation it readsresult.transactionData.getFootprint().readWrite().length === 0` — an empty write set means no ledger mutations → read-only.
  • useContract exposes a new patchFunctionReadOnly(name, isReadOnly) callback that immutably updates the matching function in metadata state.
  • ContractExplorer calls patchFunctionReadOnly after every seadOnly` is lazily resolved per-function on first use.
  • FunctionForm hides the Submit button entirely when fn.isReadOnly === true. Simulate remains the primary action and is always visible.
  • FunctionList renders a view badge next to the function signature when fn.isReadOnly === true.

How read-only is determined

Soroban simulation returns a SorobanDataBuilder (transactionDvery ledger key the function reads or writes. If readWrite()` is empty the function made no state changes and is treated as read-only. This check runs client-side after the simulation RPC call — no extra network round-trip.

Unknown-status fallback

Before any simulation has run, isReadOnly is null. The UI tralse` — both Simulate and Submit are shown. This guarantees noregression: functions that have never been simulated behave exactly as before.

Test cases (6 passing)

Suite Case Assert
function-form isReadOnly: null Simulate ✓ Submit ✓
function-form isReadOnly: true Simulate ✓ Submit absent
function-form isReadOnly: false Simulate ✓ Submit ✓
function-list isReadOnly: true "view" badge present
function-list isReadOnly: false no badge
function-list isReadOnly: null no badge

Test Suites: 2 passed, 2 total
Tests: 6 passed, 6 total

Security note

Read-only detection is informational only — it removes a confusi gate actual transaction submission at the protocol level. A user who somehow bypasses the UI can still call invokeCall directly; Soroban's own fee and auth checks remain the authoritative guard.

@vercel

vercel Bot commented Jun 21, 2026

Copy link
Copy Markdown

@OTimileyin is attempting to deploy a commit to the raymondabiola's projects Team on Vercel.

A member of the Team first needs to authorize it.

@RaymondAbiola

Copy link
Copy Markdown
Collaborator

@OTimileyin please resolve existing conflicts

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.

Add read-only function detection so view calls hide the Submit button

2 participants