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

[Util] Improve run script command #6244

Merged
merged 1 commit into from
Jul 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading