Commit 0ea5e0b9 authored by Mark Tyneway's avatar Mark Tyneway Committed by GitHub

op-node: genesis deduplicate json write (#9323)

Deduplicate code by using a common json write function from
`op-service` instead of using one off json write functions.
This reduces the overall code in the codebase and helps to
standardize the way that we write json to disk.
parent 1c4a6e5f
......@@ -20,6 +20,7 @@ import (
"github.com/ethereum-optimism/optimism/op-bindings/hardhat"
"github.com/ethereum-optimism/optimism/op-chain-ops/genesis"
"github.com/ethereum-optimism/optimism/op-service/jsonutil"
)
var (
......@@ -126,7 +127,7 @@ var Subcommands = cli.Commands{
return err
}
return writeJSONFile(ctx.String("outfile.l1"), l1Genesis)
return jsonutil.WriteJSON(ctx.String("outfile.l1"), l1Genesis)
},
},
{
......@@ -249,28 +250,14 @@ var Subcommands = cli.Commands{
return fmt.Errorf("generated rollup config does not pass validation: %w", err)
}
if err := writeJSONFile(ctx.String("outfile.l2"), l2Genesis); err != nil {
if err := jsonutil.WriteJSON(ctx.String("outfile.l2"), l2Genesis); err != nil {
return err
}
return writeJSONFile(ctx.String("outfile.rollup"), rollupConfig)
return jsonutil.WriteJSON(ctx.String("outfile.rollup"), rollupConfig)
},
},
}
// writeJSONFile will write a JSON file to disk at the given path
// containing the JSON serialized input value.
func writeJSONFile(outfile string, input any) error {
f, err := os.OpenFile(outfile, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0o644)
if err != nil {
return err
}
defer f.Close()
enc := json.NewEncoder(f)
enc.SetIndent("", " ")
return enc.Encode(input)
}
// rpcBlock represents the JSON serialization of a block from an Ethereum RPC.
type rpcBlock struct {
Hash common.Hash `json:"hash"`
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment