stellar / rs-stellar-xdr

Rust lib for Stellar XDR.
Apache License 2.0
20 stars 27 forks source link

Add support for decoding variable length arrays to cli #366

Open leighmcculloch opened 6 months ago

leighmcculloch commented 6 months ago

What

Add support for decoding variable length arrays to the CLI.

Why

Stellar-core returns a variable length array of diagnostic events from it's submission endpoint. It'd be convenient to be able to decode it on the command line with the CLI.

A symmetrical encode op would be ideal to add, but the effort to add it is significantly higher than simply plopping this additional decode format in, so I'm trading off symmetrical feature support for getting something that's a win today and deferring something that to my knowledge we haven't identified a need for yet.

Example

$ curl -vG 'http://localhost:11826/tx' --data-urlencode "blob=AAAAAg..." | jq
{
  "diagnostic_events": "AAAAAQAAAAAAAAAAAAAAAAAAAAIAAAAAAAAAAgAAAA8AAAAFZXJyb3IAAAAAAAACAAAAAwAAAAUAAAAQAAAAAQAAAAMAAAAOAAAAU3RyYW5zYWN0aW9uIGBzb3JvYmFuRGF0YS5yZXNvdXJjZUZlZWAgaXMgbG93ZXIgdGhhbiB0aGUgYWN0dWFsIFNvcm9iYW4gcmVzb3VyY2UgZmVlAAAAAAUAAAAAAFom2gAAAAUAAAAAAo+hhQ==",
  "error": "AAAAAABaJz7////vAAAAAA==",
  "status": "ERROR"
}
$ echo -n 'AAAAAQAAAAAAAAAAAAAAAAAAAAIAAAAAAAAAAgAAAA8AAAAFZXJyb3IAAAAAAAACAAAAAwAAAAUAAAAQAAAAAQAAAAMAAAAOAAAAU3RyYW5zYWN0aW9uIGBzb3JvYmFuRGF0YS5yZXNvdXJjZUZlZWAgaXMgbG93ZXIgdGhhbiB0aGUgYWN0dWFsIFNvcm9iYW4gcmVzb3VyY2UgZmVlAAAAAAUAAAAAAFom2gAAAAUAAAAAAo+hhQ==' \
    | stellar-xdr d --type DiagnosticEvent --input var-array-base64 | jq
{
  "in_successful_contract_call": false,
  "event": {
    "ext": "v0",
    "contract_id": null,
    "type_": "diagnostic",
    "body": {
      "v0": {
        "topics": [
          {
            "symbol": "error"
          },
          {
            "error": {
              "storage": "exceeded_limit"
            }
          }
        ],
        "data": {
          "vec": [
            {
              "string": "transaction `sorobanData.resourceFee` is lower than the actual Soroban resource fee"
            },
            {
              "u64": 5908186
            },
            {
              "u64": 42967429
            }
          ]
        }
      }
    }
  }
}

Close https://github.com/stellar/rs-stellar-xdr/issues/323

leighmcculloch commented 3 months ago

The main immediate problem being solve by this PR was solved with https://github.com/stellar/stellar-xdr/pull/187, but it's still a useful feature that I'll finish and merge.