soroban-cli icon indicating copy to clipboard operation
soroban-cli copied to clipboard

Improve `stellar tx edit` by including contract spec spec param names in JSON comments

Open leighmcculloch opened this issue 2 months ago • 0 comments
trafficstars

I think we should improve stellar tx edit command by including contract spec spec param names in JSON comments, making the output JSONC.

The stellar tx edit command today takes a tx from stdin and renders it as XDR-JSON.

It makes some modification to the XDR-JSON, inserting the $schema key so that IDEs supporting JSON LSP can offer auto completion and documentation validation. The command then removes that key after the editor closes and before processing the JSON back into XDR.

{
  "$schema": "https://stellar.org/schema/xdr-json/v23.0.0-rc.2/TransactionEnvelope.json",
  "tx": {
    "tx": {
      // ...

When viewing txs that invoke contracts, details about the invocation are visible, including the contract address and the parameters. For example:

// ...
"invoke_contract": {
  "contract_address": "CAG5LRYQ5JVEUI5TEID72EYOVX44TTUJT5BQR2J6J77FH65PCCFAJDDH",
  "function_name": "add_liquidity",
  "args": [
    { "address": "CCW67TSZV3SSS2HXMBQ5JFGCKJNXKZM7UQUWUZPUTHXSTZLEO7SJMI75" },
    { "address": "CAS3J7GYLGXMF6TDJBBYYSE3HQ6BBSMLNUQ34T6TZMYMW2EVH34XOWMA" },
    { "i128": "1000000000" },
    { "i128": "2791736460" },
    { "i128": "1000000000" },
    { "i128": "2791736460" },
    { "u64": "0" }
  ]
// ...

While this is really easy to read in JSON, the parameters only show the values, and not the parameter names, making it a little hard to reason about what the values mean, and potentially leading to mistakes if a developer edits the tx and sets a value in the wrong field.

Most IDEs support JSONC, a form of JSON that allows for comments to appear within the JSON.

The stellar tx edit command could, in much the same way that it injects the $schema, render JSONC and to inject comments after or before each parameter so that it is unambiguous to the user what each parameter is.

For example:

// ...
"invoke_contract": {
  "contract_address": "CAG5LRYQ5JVEUI5TEID72EYOVX44TTUJT5BQR2J6J77FH65PCCFAJDDH",
  "function_name": "add_liquidity",
  "args": [
    { "address": "CCW67TSZV3SSS2HXMBQ5JFGCKJNXKZM7UQUWUZPUTHXSTZLEO7SJMI75" }, // token_a
    { "address": "CAS3J7GYLGXMF6TDJBBYYSE3HQ6BBSMLNUQ34T6TZMYMW2EVH34XOWMA" }, // token_b
    { "i128": "1000000000" }, // amount_a_desired
    { "i128": "2791736460" }, // amount_b_desired
    { "i128": "1000000000" }, // amount_a_min
    { "i128": "2791736460" }, // amount_b_min
    { "u64": "0" } // deadline
  ]
// ...

leighmcculloch avatar Sep 05 '25 02:09 leighmcculloch