Skip to content

Commit

Permalink
Load files from binary / json dynamically
Browse files Browse the repository at this point in the history
  • Loading branch information
mininny committed Oct 1, 2024
1 parent 1a5a788 commit 585e8ff
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion rvgo/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func Run(ctx *cli.Context) error {
defer profile.Start(profile.NoShutdownHook, profile.ProfilePath("."), profile.CPUProfile).Stop()
}

state, err := jsonutil.LoadJSON[fast.VMState](ctx.Path(cannon.RunInputFlag.Name))
state, err := fast.LoadVMStateFromFile(ctx.Path(cannon.RunInputFlag.Name))
if err != nil {
return err
}
Expand Down
3 changes: 1 addition & 2 deletions rvgo/cmd/witness.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (

"github.com/ethereum-optimism/asterisc/rvgo/fast"
cannon "github.com/ethereum-optimism/optimism/cannon/cmd"
"github.com/ethereum-optimism/optimism/cannon/serialize"
"github.com/ethereum-optimism/optimism/op-service/ioutil"
"github.com/ethereum-optimism/optimism/op-service/jsonutil"
)
Expand All @@ -20,7 +19,7 @@ type WitnessOutput struct {
func Witness(ctx *cli.Context) error {
input := ctx.Path(cannon.WitnessInputFlag.Name)
output := ctx.Path(cannon.WitnessOutputFlag.Name)
state, err := serialize.LoadSerializedBinary[fast.VMState](input)
state, err := fast.LoadVMStateFromFile(input)
if err != nil {
return fmt.Errorf("invalid input state (%v): %w", input, err)
}
Expand Down
9 changes: 9 additions & 0 deletions rvgo/fast/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"fmt"
"io"

"github.com/ethereum-optimism/optimism/op-service/jsonutil"

"github.com/ethereum-optimism/optimism/cannon/serialize"

"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -260,3 +262,10 @@ func (s *VMState) Deserialize(in io.Reader) error {

return nil
}

func LoadVMStateFromFile(path string) (*VMState, error) {
if !serialize.IsBinaryFile(path) {
return jsonutil.LoadJSON[VMState](path)
}
return serialize.LoadSerializedBinary[VMState](path)
}

0 comments on commit 585e8ff

Please sign in to comment.