Skip to content
Merged
Show file tree
Hide file tree
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
47 changes: 1 addition & 46 deletions op-deployer/pkg/deployer/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ package deployer

import (
"fmt"
"log"
"os"
"path"

"github.com/ethereum-optimism/optimism/op-deployer/pkg/deployer/artifacts"

Expand All @@ -31,40 +28,6 @@ const (
ContractNameFlagName = "contract-name"
)

type DeploymentTarget string

const (
DeploymentTargetLive DeploymentTarget = "live"
DeploymentTargetGenesis DeploymentTarget = "genesis"
DeploymentTargetCalldata DeploymentTarget = "calldata"
DeploymentTargetNoop DeploymentTarget = "noop"
)

func NewDeploymentTarget(s string) (DeploymentTarget, error) {
switch s {
case string(DeploymentTargetLive):
return DeploymentTargetLive, nil
case string(DeploymentTargetGenesis):
return DeploymentTargetGenesis, nil
case string(DeploymentTargetCalldata):
return DeploymentTargetCalldata, nil
case string(DeploymentTargetNoop):
return DeploymentTargetNoop, nil
default:
return "", fmt.Errorf("invalid deployment target: %s", s)
}
}

func GetDefaultCacheDir() string {
homeDir, err := os.UserHomeDir()
if err != nil {
fallbackDir := ".op-deployer/cache"
log.Printf("error getting user home directory: %v, using fallback directory: %s\n", err, fallbackDir)
return fallbackDir
}
return path.Join(homeDir, ".op-deployer/cache")
}

var (
L1RPCURLFlag = &cli.StringFlag{
Name: L1RPCURLFlagName,
Expand All @@ -85,7 +48,7 @@ var (
Usage: "Cache directory. " +
"If set, the deployer will attempt to cache downloaded artifacts in the specified directory.",
EnvVars: PrefixEnvVar("CACHE_DIR"),
Value: GetDefaultCacheDir(),
Value: EnsureDefaultCacheDir(),
}
L1ChainIDFlag = &cli.Uint64Flag{
Name: L1ChainIDFlagName,
Expand Down Expand Up @@ -187,11 +150,3 @@ var VerifyFlags = []cli.Flag{
func PrefixEnvVar(name string) []string {
return op_service.PrefixEnvVar(EnvVarPrefix, name)
}

func cwd() string {
dir, err := os.Getwd()
if err != nil {
return ""
}
return dir
}
58 changes: 58 additions & 0 deletions op-deployer/pkg/deployer/utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package deployer

import (
"fmt"
"log"
"os"
"path"
)

type DeploymentTarget string

const (
DeploymentTargetLive DeploymentTarget = "live"
DeploymentTargetGenesis DeploymentTarget = "genesis"
DeploymentTargetCalldata DeploymentTarget = "calldata"
DeploymentTargetNoop DeploymentTarget = "noop"
)

func NewDeploymentTarget(s string) (DeploymentTarget, error) {
switch s {
case string(DeploymentTargetLive):
return DeploymentTargetLive, nil
case string(DeploymentTargetGenesis):
return DeploymentTargetGenesis, nil
case string(DeploymentTargetCalldata):
return DeploymentTargetCalldata, nil
case string(DeploymentTargetNoop):
return DeploymentTargetNoop, nil
default:
return "", fmt.Errorf("invalid deployment target: %s", s)
}
}

func cwd() string {
dir, err := os.Getwd()
if err != nil {
return ""
}
return dir
}

func EnsureDefaultCacheDir() string {
var cacheDir string

homeDir, err := os.UserHomeDir()
if err != nil {
cacheDir = ".op-deployer/cache"
log.Printf("error getting user home directory: %v, using fallback directory: %s\n", err, cacheDir)
} else {
cacheDir = path.Join(homeDir, ".op-deployer/cache")
}

if err := os.MkdirAll(cacheDir, 0755); err != nil {
panic(fmt.Sprintf("failed to create cache directory %s: %v", cacheDir, err))
}

return cacheDir
}
12 changes: 12 additions & 0 deletions op-deployer/pkg/deployer/utils_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package deployer

import (
"testing"

"github.com/stretchr/testify/require"
)

func TestEnsureDefaultCacheDir(t *testing.T) {
cacheDir := EnsureDefaultCacheDir()
require.NotNil(t, cacheDir)
}
2 changes: 1 addition & 1 deletion op-deployer/pkg/deployer/verify/verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func VerifyCLI(cliCtx *cli.Context) error {
if err != nil {
return fmt.Errorf("failed to parse l1 contracts release locator: %w", err)
}
artifactsFS, err := artifacts.Download(ctx, locator, nil, deployer.GetDefaultCacheDir())
artifactsFS, err := artifacts.Download(ctx, locator, nil, deployer.EnsureDefaultCacheDir())
if err != nil {
return fmt.Errorf("failed to get artifacts: %w", err)
}
Expand Down