Skip to content

Commit

Permalink
add AssertChainID
Browse files Browse the repository at this point in the history
  • Loading branch information
mmsqe committed Oct 27, 2023
1 parent 91f7d69 commit 64213b2
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions server/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,22 @@ func openTraceWriter(traceWriterFile string) (w io.WriteCloser, err error) {
)
}

func AssertChainID(chainID, homeDir string) string {
if chainID == "" {
// fallback to genesis chain-id
reader, err := os.Open(filepath.Join(homeDir, "config", "genesis.json"))
if err != nil {
panic(err)
}
defer reader.Close()
chainID, err = genutiltypes.ParseChainIDFromGenesis(reader)
if err != nil {
panic(fmt.Errorf("failed to parse chain-id from genesis file: %w", err))
}
}
return chainID
}

// DefaultBaseappOptions returns the default baseapp options provided by the Cosmos SDK
func DefaultBaseappOptions(appOpts types.AppOptions) []func(*baseapp.BaseApp) {
var cache sdk.MultiStorePersistentCache
Expand All @@ -455,21 +471,7 @@ func DefaultBaseappOptions(appOpts types.AppOptions) []func(*baseapp.BaseApp) {
}

homeDir := cast.ToString(appOpts.Get(flags.FlagHome))
chainID := cast.ToString(appOpts.Get(flags.FlagChainID))
if chainID == "" {
// fallback to genesis chain-id
reader, err := os.Open(filepath.Join(homeDir, "config", "genesis.json"))
if err != nil {
panic(err)
}
defer reader.Close()

chainID, err = genutiltypes.ParseChainIDFromGenesis(reader)
if err != nil {
panic(fmt.Errorf("failed to parse chain-id from genesis file: %w", err))
}
}

chainID := AssertChainID(cast.ToString(appOpts.Get(flags.FlagChainID)), homeDir)
snapshotStore, err := GetSnapshotStore(appOpts)
if err != nil {
panic(err)
Expand Down

0 comments on commit 64213b2

Please sign in to comment.