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 ( ...@@ -4,6 +4,7 @@ import (
"encoding/json" "encoding/json"
"math/big" "math/big"
"os" "os"
"path/filepath"
"github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
...@@ -78,6 +79,14 @@ func NewDeployConfig(path string) (*DeployConfig, error) { ...@@ -78,6 +79,14 @@ func NewDeployConfig(path string) (*DeployConfig, error) {
return &config, nil 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 // StorageConfig represents the storage configuration for the L2 predeploy
// contracts. // contracts.
type StorageConfig map[string]state.StorageValues type StorageConfig map[string]state.StorageValues
......
...@@ -4,7 +4,6 @@ import ( ...@@ -4,7 +4,6 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"os" "os"
"path/filepath"
"strings" "strings"
"github.com/urfave/cli" "github.com/urfave/cli"
...@@ -66,9 +65,8 @@ var Subcommands = cli.Commands{ ...@@ -66,9 +65,8 @@ var Subcommands = cli.Commands{
return err return err
} }
deployConfigDirectory := ctx.String("deploy-config") deployConfig := ctx.String("deploy-config")
deployConfig := filepath.Join(deployConfigDirectory, network+".json") config, err := genesis.NewDeployConfigWithNetwork(network, deployConfig)
config, err := genesis.NewDeployConfig(deployConfig)
if err != nil { if err != nil {
return err return err
} }
...@@ -119,10 +117,9 @@ var Subcommands = cli.Commands{ ...@@ -119,10 +117,9 @@ var Subcommands = cli.Commands{
}, },
Action: func(ctx *cli.Context) error { Action: func(ctx *cli.Context) error {
network := ctx.String("network") network := ctx.String("network")
deployConfigDirectory := ctx.String("deploy-config") deployConfig := ctx.String("deploy-config")
deployConfig := filepath.Join(deployConfigDirectory, network+".json")
config, err := genesis.NewDeployConfig(deployConfig) config, err := genesis.NewDeployConfigWithNetwork(network, deployConfig)
if err != nil { if err != nil {
return err 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