Skip to content

Commit

Permalink
Merge pull request #6244 from onflow/bastian/improve-run-script
Browse files Browse the repository at this point in the history
[Util] Improve run script command
  • Loading branch information
turbolent authored Jul 23, 2024
2 parents 58de2f7 + c89697d commit 6ce4c85
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions cmd/util/cmd/run-script/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,17 @@ func run(*cobra.Command, []string) {
// Validate chain ID
_ = chainID.Chain()

code, err := io.ReadAll(os.Stdin)
if err != nil {
log.Fatal().Msgf("failed to read script: %s", err)
}

var payloads []*ledger.Payload
var err error

if flagPayloads != "" {
_, payloads, err = util.ReadPayloadFile(log.Logger, flagPayloads)
} else {
log.Info().Msg("Reading trie")
log.Info().Msg("reading trie")

stateCommitment := util.ParseStateCommitment(flagStateCommitment)
payloads, err = util.ReadTrie(flagState, stateCommitment)
Expand All @@ -92,12 +96,17 @@ func run(*cobra.Command, []string) {
log.Fatal().Err(err).Msg("failed to read payloads")
}

log.Info().Msgf("creating registers from payloads (%d)", len(payloads))

registersByAccount, err := registers.NewByAccountFromPayloads(payloads)
if err != nil {
log.Fatal().Err(err)
}

log.Info().Msgf("created registers (%d accounts)", registersByAccount.AccountCount())
log.Info().Msgf(
"created %d registers from payloads (%d accounts)",
registersByAccount.Count(),
registersByAccount.AccountCount(),
)

options := computation.DefaultFVMOptions(chainID, false, false)
options = append(
Expand All @@ -116,11 +125,6 @@ func run(*cobra.Command, []string) {

vm := fvm.NewVirtualMachine()

code, err := io.ReadAll(os.Stdin)
if err != nil {
log.Fatal().Msgf("failed to read script: %s", err)
}

_, res, err := vm.Run(
ctx,
fvm.Script(code),
Expand Down

0 comments on commit 6ce4c85

Please sign in to comment.