Skip to content

Commit

Permalink
Use a 'name' field to namespace the data directory (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
ferranbt authored Sep 19, 2023
1 parent de12663 commit d2ad76b
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -1506,6 +1506,13 @@ func SetDataDir(ctx *cli.Context, cfg *node.Config) {
cfg.DataDir = filepath.Join(node.DefaultDataDir(), "sepolia")
case ctx.Bool(SuaveFlag.Name) && cfg.DataDir == node.DefaultDataDir():
cfg.DataDir = filepath.Join(node.DefaultDataDir(), "suave")
case ctx.IsSet(CustomChainFlag.Name) && cfg.DataDir == node.DefaultDataDir():
genesis, err := readJSONGenesis(ctx.String(CustomChainFlag.Name))
if err == nil {
// best effort, it will raise an error later on, we do not need to
// catch it here.
cfg.DataDir = filepath.Join(node.DefaultDataDir(), genesis.Name)
}
}
}

Expand Down Expand Up @@ -2269,6 +2276,8 @@ func MakeConsolePreloads(ctx *cli.Context) []string {
type jsonGenesis struct {
core *core.Genesis `json:"-"`

Name string `json:"name"`

Config struct {
Clique struct {
// Signers is the list of initial validators of the clique protocol
Expand All @@ -2294,6 +2303,9 @@ func readJSONGenesis(genesisPath string) (*jsonGenesis, error) {
if err := json.Unmarshal(genesisRaw, genesis); err != nil {
return nil, fmt.Errorf("invalid genesis file: %v", err)
}
if genesis.Name == "" {
return nil, fmt.Errorf("genesis.json file must have a name field")
}

genesis.core = coreGenesis
return genesis, nil
Expand Down

0 comments on commit d2ad76b

Please sign in to comment.