Skip to content

feat(contract): support addresses, numbers, and JSON for --key storage lookups - #2852

Closed
jdjioe5-cpu wants to merge 1 commit into
stellar:mainfrom
jdjioe5-cpu:feat/issue-2041-key-invoke-variables
Closed

jdjioe5-cpu wants to merge 1 commit into
stellar:mainfrom
jdjioe5-cpu:feat/issue-2041-key-invoke-variables

Conversation

@jdjioe5-cpu

Copy link
Copy Markdown

What

Closes #2041.

Enhance --key in contract storage commands (read, restore, extend) so that it can parse more than just plain Symbol keys. --key now supports:

  1. Valid Stellar StrKey addresses (G..., C..., M...), parsed into ScVal::Address
  2. Standard XDR-JSON format representations (e.g., {"u64": 123456789})
  3. JSON primitive/structured values (numbers, booleans, arrays, and objects)
  4. Integer/boolean literals (e.g., 42, true)
  5. Full backward compatibility: fallback to Symbol primitive parsing for existing plain string symbols

Why

Previously, --key was hardcoded to only accept ScSpecTypeDef::Symbol:

soroban_spec_tools::from_string_primitive(key, &xdr::ScSpecTypeDef::Symbol)?

This forced developers looking up storage entries keyed by addresses, integers, or complex values to either write manual scripts or use the base64-encoded --key-xdr option, which was inconvenient and unintuitive.

How

  • Extracted and modularized key parsing into parse_key_arg(key_str: &str) -> Result<ScVal, Error>.
  • Added address detection using stellar_strkey::Strkey.
  • Added structured JSON conversion (json_to_scval) converting JSON numbers, booleans, arrays (ScVal::Vec), and maps (ScVal::Map).
  • Retained seamless fallback to soroban_spec_tools::from_string_primitive(..., Symbol) preserving complete backward compatibility.
  • Added comprehensive unit tests covering symbols, account addresses, contract addresses, numbers, booleans, JSON arrays, JSON objects, and XDR-JSON.

@github-project-automation github-project-automation Bot moved this to Backlog (Not Ready) in DevX Oct 23, 2026
@github-project-automation github-project-automation Bot moved this from Backlog (Not Ready) to Done in DevX Oct 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Make --key work like invoke variables

2 participants