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

Serialize script return value to Cadence json

Open sisyphusSmiling opened this issue 2 years ago • 3 comments

Issue To Be Solved

It would be really great if script return values could be serialized into Cadence json and saved locally.

Suggest A Solution

A flag added to flow scripts ... like --serialize-to <FILENAME.json>. Say I have a script like:

access(all) fun main(): UInt64 {
  return getCurrentBlock().height
}

That I run with the command:

flow scripts execute ./scripts/get_current_block_height.cdc --serialize-to block-height.json

Where block-height.json looks like

[
  {
    "type": "UInt64",
    "value": "70027781"
  }
]

This would allow me to script the following:

#!/bin/bash

flow scripts execute ./scripts/get_current_block_height.cdc --serialize-to block-height.json
flow transactions execute ./transactions/set_minimum_block_height.cdc --args-json "$(cat block-height.json)"

Where the script result is used as args for the subsequent transaction execution.

Context

Not a blocker, just an idea.

sisyphusSmiling avatar Jan 16 '24 23:01 sisyphusSmiling

does -o json > file.json do what you want?

bjartek avatar Jan 25 '24 23:01 bjartek

I guess that returns it without the surrounding array wrapper.

bjartek avatar Jan 25 '24 23:01 bjartek

This is not cli, but this little snippet of overflow does the same

  var height uint64
  o.Script("get_current_block").MarshalAs(&height)
  o.Tx("set_minimum_block_height", overflow.WithSigner("foo"), overflow.WithArg("height", height))

bjartek avatar Jan 26 '24 00:01 bjartek