Commit f159d1f3 authored by Mark Tyneway's avatar Mark Tyneway Committed by GitHub

op-chain-ops: add helper function (#3303)

Deduplicates some code for a common pattern.
Callers will usually pass a network and a path
to a deploy config directory. This comes from
the way that `hardhat-deploy-config` works.
The config directory must include a JSON file
that is named after the network.
parent 48049abc
......@@ -4,6 +4,7 @@ import (
"encoding/json"
"math/big"
"os"
"path/filepath"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/common"
......@@ -78,6 +79,14 @@ func NewDeployConfig(path string) (*DeployConfig, error) {
return &config, nil
}
// NewDeployConfigWithNetwork takes a path to a deploy config directory
// and the network name. The config file in the deploy config directory
// must match the network name and be a JSON file.
func NewDeployConfigWithNetwork(network, path string) (*DeployConfig, error) {
deployConfig := filepath.Join(path, network+".json")
return NewDeployConfig(deployConfig)
}
// StorageConfig represents the storage configuration for the L2 predeploy
// contracts.
type StorageConfig map[string]state.StorageValues
......
......@@ -4,7 +4,6 @@ import (
"encoding/json"
"fmt"
"os"
"path/filepath"
"strings"
"github.com/urfave/cli"
......@@ -66,9 +65,8 @@ var Subcommands = cli.Commands{
return err
}
deployConfigDirectory := ctx.String("deploy-config")
deployConfig := filepath.Join(deployConfigDirectory, network+".json")
config, err := genesis.NewDeployConfig(deployConfig)
deployConfig := ctx.String("deploy-config")
config, err := genesis.NewDeployConfigWithNetwork(network, deployConfig)
if err != nil {
return err
}
......@@ -119,10 +117,9 @@ var Subcommands = cli.Commands{
},
Action: func(ctx *cli.Context) error {
network := ctx.String("network")
deployConfigDirectory := ctx.String("deploy-config")
deployConfig := filepath.Join(deployConfigDirectory, network+".json")
deployConfig := ctx.String("deploy-config")
config, err := genesis.NewDeployConfig(deployConfig)
config, err := genesis.NewDeployConfigWithNetwork(network, deployConfig)
if err != nil {
return err
}
......
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