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

Open
#2,191 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
rust
Domain
cli

Research direction

Start from the implementation of stellar tx edit and its XDR-JSON rendering and editor round trip; trace how contract invocation arguments are obtained and how $schema is injected and removed. Determine how contract spec parameter names can be rendered as JSONC comments without breaking parsing, then verify that edited JSONC still converts back to XDR correctly.

Written by the indexing model from the issue text.

Description

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
  ]
// ...
Dominant language
Rust
Stars
123
Forks
141
Avg merge
2d 21h
Merged PRs (30d)
17

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from stellar/stellar-cli

All issues in stellar/stellar-cli

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.