-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6425 from onflow/bastian/debug-script-command
[Util] Add command to debug a script
- Loading branch information
Showing
2 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package debug_tx | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/rs/zerolog/log" | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/onflow/flow-go/model/flow" | ||
"github.com/onflow/flow-go/utils/debug" | ||
) | ||
|
||
// use the following command to forward port 9000 from the EN to localhost:9001 | ||
// `gcloud compute ssh '--ssh-flag=-A' --no-user-output-enabled --tunnel-through-iap migrationmainnet1-execution-001 --project flow-multi-region -- -NL 9001:localhost:9000` | ||
|
||
var ( | ||
flagExecutionAddress string | ||
flagChain string | ||
flagScript string | ||
) | ||
|
||
var Cmd = &cobra.Command{ | ||
Use: "debug-script", | ||
Short: "debug a script", | ||
Run: run, | ||
} | ||
|
||
func init() { | ||
|
||
Cmd.Flags().StringVar( | ||
&flagChain, | ||
"chain", | ||
"", | ||
"Chain name", | ||
) | ||
_ = Cmd.MarkFlagRequired("chain") | ||
|
||
Cmd.Flags().StringVar(&flagExecutionAddress, "execution-address", "", "address of the execution node") | ||
_ = Cmd.MarkFlagRequired("execution-address") | ||
|
||
Cmd.Flags().StringVar(&flagScript, "script", "", "path to script") | ||
_ = Cmd.MarkFlagRequired("script") | ||
} | ||
|
||
func run(*cobra.Command, []string) { | ||
|
||
chainID := flow.ChainID(flagChain) | ||
chain := chainID.Chain() | ||
|
||
code, err := os.ReadFile(flagScript) | ||
if err != nil { | ||
log.Fatal().Err(err).Msgf("failed to read script from file %s", flagScript) | ||
} | ||
|
||
debugger := debug.NewRemoteDebugger( | ||
flagExecutionAddress, | ||
chain, | ||
log.Logger, | ||
) | ||
|
||
// TODO: add support for arguments | ||
var arguments [][]byte | ||
|
||
result, scriptErr, processErr := debugger.RunScript(code, arguments) | ||
|
||
if scriptErr != nil { | ||
log.Fatal().Err(scriptErr).Msg("transaction error") | ||
} | ||
if processErr != nil { | ||
log.Fatal().Err(processErr).Msg("process error") | ||
} | ||
log.Info().Msgf("result: %s", result) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters