feat: detect read-only functions and hide Submit for view calls#37
Open
OTimileyin wants to merge 1 commit into
Open
feat: detect read-only functions and hide Submit for view calls#37OTimileyin wants to merge 1 commit into
OTimileyin wants to merge 1 commit into
Conversation
|
@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. |
Collaborator
|
@OTimileyin please resolve existing conflicts |
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.
Closes #17
Title: feat: detect read-only functions and hide Submit for view calls
Summary
extractFunctionsincontract-parser.tsnow emitsisReadOnly: nullfor every function at parse time — the Soroban XDR spec (ScSpecFunctionV0) exposes noreadonly/viewattribute, so the spec path is unavailable andnullis the correct initial state.simulateCallininvocation.tsnow returns{ value, isReadimulation it readsresult.transactionData.getFootprint().readWrite().length === 0` — an empty write set means no ledger mutations → read-only.useContractexposes a newpatchFunctionReadOnly(name, isReadOnly)callback that immutably updates the matching function in metadata state.ContractExplorercallspatchFunctionReadOnlyafter every seadOnly` is lazily resolved per-function on first use.FunctionFormhides the Submit button entirely whenfn.isReadOnly === true. Simulate remains the primary action and is always visible.FunctionListrenders aviewbadge next to the function signature whenfn.isReadOnly === true.How read-only is determined
Soroban simulation returns a
SorobanDataBuilder(transactionDvery ledger key the function reads or writes. IfreadWrite()` 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,
isReadOnlyisnull. 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)
isReadOnly: nullisReadOnly: trueisReadOnly: falseisReadOnly: trueisReadOnly: falseisReadOnly: nullTest 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
invokeCalldirectly; Soroban's own fee and auth checks remain the authoritative guard.