Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serialize script return value to Cadence json #1348

Open
sisyphusSmiling opened this issue Jan 16, 2024 · 3 comments
Open

Serialize script return value to Cadence json #1348

sisyphusSmiling opened this issue Jan 16, 2024 · 3 comments
Labels
Feature A new user feature or a new package API Feedback

Comments

@sisyphusSmiling
Copy link
Contributor

sisyphusSmiling commented Jan 16, 2024

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.

@bjartek
Copy link
Collaborator

bjartek commented Jan 25, 2024

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

@bjartek
Copy link
Collaborator

bjartek commented Jan 25, 2024

I guess that returns it without the surrounding array wrapper.

@bjartek
Copy link
Collaborator

bjartek commented Jan 26, 2024

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))

@chasefleming chasefleming moved this to 🔖 Ready for Pickup in 🌊 Flow 4D Feb 8, 2024
@gregsantos gregsantos moved this from 🔖 Ready for Pickup to 🧊 Backlog in 🌊 Flow 4D Feb 20, 2024
@chasefleming chasefleming removed their assignment May 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature A new user feature or a new package API Feedback
Projects
Status: 🧊 Backlog
Development

No branches or pull requests

3 participants