Repository navigation
fix(spec-tools): full support for ScType::Val in argument parsing and output formatting (#2438) - #2867
Closed
jdjioe5-cpu wants to merge 1 commit into
Closed
fix(spec-tools): full support for ScType::Val in argument parsing and output formatting (#2438)#2867jdjioe5-cpu wants to merge 1 commit into
jdjioe5-cpu wants to merge 1 commit into
Conversation
… output formatting (stellar#2438)
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.
Summary
Fixes #2438
Also addresses #691
When a Soroban contract function declares return or input parameters typed as generic
Val(represented asSC_SPEC_TYPE_VAL/ScType::Valin contract specs), calling the function or passing parameters viastellar contract invokecaused panics or parsing failures:Bool(false)or other primitives previously panicked withnot yet implemented: Bool(false,) doesn't have a matching ValorInvalidPair(..., Val)when falling through spec object dispatch.from_jsonfell back directly toserde_json::from_valuewhich fails on primitive JSON values like booleans, integers, or bare strings forScType::Val.Changes
cmd/crates/soroban-spec-tools/src/lib.rs:val_from_jsonto recursively infer and convert any JSON value (null/void, bool, numbers, addresses, strings, arrays, objects) to its correspondingScValrepresentation, while maintaining backwards compatibility with serializedScValformats.(ScType::Val, _) => val_from_json(v)?inSpec::from_json.ScType::ValinSpec::from_string.(val, ScType::Val) => to_json(val)?safeguard inSpec::sc_object_to_json.arg_value_name(Some("val")) andexample(Some("\"any_value\"")).ScVal::Bool(false)/true, all scalar variants, bare strings, numbers, and collections withScType::Val.cmd/soroban-cli/src/commands/contract/arg_parsing.rs:ScSpecTypeDef::Valinis_primitive_typeto allow natural command-line inputs.ScSpecTypeDef::Val.test_val_arg_parsingverifying argument parsing for booleans, integers, and strings.Evidence
cargo fmt --check --all: Passed (0 errors).cargo test -p soroban-spec-tools: 113/113 passed.cargo test -p soroban-cli --lib commands::contract::arg_parsing: 31/31 passed.